install-freedombone.sh 81KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788
  1. #!/bin/bash
  2. # Freedombone install script intended for use with Debian Jessie
  3. #
  4. # Note on dynamic dns
  5. # ===================
  6. #
  7. # I'm not particularly trying to promote freedns.afraid.org
  8. # as a service, it just happens to be a dynamic DNS system which
  9. # provides free (as in beer) accounts, and I'm trying to make the
  10. # process of setting up a working server as trivial as possible.
  11. # Other dynamic DNS systems are available, and if you're using
  12. # something different then comment out the section within
  13. # argument_checks and the call to dynamic_dns_freedns.
  14. #
  15. # Prerequisites
  16. # =============
  17. #
  18. # cd ~/
  19. # wget http://freedombone.uk.to/debian-jessie-console-armhf-2014-08-13.tar.xz
  20. #
  21. # Verify it.
  22. #
  23. # sha256sum debian-jessie-console-armhf-2014-08-13.tar.xz
  24. # fc225cfb3c2dfad92cccafa97e92c3cd3db9d94f4771af8da364ef59609f43de
  25. #
  26. # Uncompress it.
  27. #
  28. # tar xJf debian-jessie-console-armhf-2014-08-13.tar.xz
  29. # cd debian-jessie-console-armhf-2014-08-13
  30. #
  31. # sudo apt-get install u-boot-tools dosfstools git-core kpartx wget parted
  32. # sudo ./setup_sdcard.sh --mmc /dev/sdX --dtb beaglebone
  33. #
  34. # When finished eject the micrtoSD then reinsert it
  35. #
  36. # sudo cp /media/$USER/BOOT/bbb-uEnv.txt /media/$USER/BOOT/uEnv.txt
  37. # sync
  38. #
  39. # Eject microSD, insert into BBB, attach USB cable between BBB and laptop.
  40. # On Ubuntu wait until you see the "connected" message.
  41. #
  42. # ssh-keygen -f "/home/$USER/.ssh/known_hosts" -R 192.168.7.2
  43. # ssh debian@192.168.7.2 (password "temppwd")
  44. # su (password "root")
  45. # passwd
  46. # adduser $MY_USERNAME
  47. # sed -i '/iface eth0 inet dhcp/a\iface eth0 inet static' /etc/network/interfaces
  48. # sed -i '/iface eth0 inet static/a\ dns-nameservers 213.73.91.35 85.214.20.141' /etc/network/interfaces
  49. # sed -i "/iface eth0 inet static/a\ gateway $MY_ROUTER_IP" /etc/network/interfaces
  50. # sed -i '/iface eth0 inet static/a\ netmask 255.255.255.0' /etc/network/interfaces
  51. # sed -i "/iface eth0 inet static/a\ address $MY_BBB_STATIC_IP" /etc/network/interfaces
  52. # sed -i '/iface usb0 inet static/,/ gateway 192.168.7.1/ s/^/#/' /etc/network/interfaces
  53. # shutdown now
  54. #
  55. # Connect BBB to router
  56. #
  57. # scp install-freedombone.sh $MY_USERNAME@$MY_BBB_STATIC_IP:/home/$MY_USERNAME
  58. # ssh $MY_USERNAME@$MY_BBB_STATIC_IP
  59. # su
  60. # ./install-freedombone.sh [DOMAIN_NAME] [MY_USERNAME]
  61. DOMAIN_NAME=$1
  62. MY_USERNAME=$2
  63. FREEDNS_SUBDOMAIN_CODE=$3
  64. SYSTEM_TYPE=$4
  65. SSH_PORT=2222
  66. KERNEL_VERSION="v3.15.10-bone7"
  67. USE_HWRNG="yes"
  68. INSTALLED_WITHIN_DOCKER="no"
  69. # If you want to run an encrypted mailing list specify its name here.
  70. # There should be no spaces in the name
  71. PRIVATE_MAILING_LIST=
  72. # Domain name or freedns subdomain for Owncloud installation
  73. OWNCLOUD_DOMAIN_NAME=
  74. # Freedns dynamic dns code for owncloud
  75. OWNCLOUD_FREEDNS_SUBDOMAIN_CODE=
  76. OWNCLOUD_ARCHIVE="owncloud-7.0.2.tar.bz2"
  77. OWNCLOUD_DOWNLOAD="https://download.owncloud.org/community/$OWNCLOUD_ARCHIVE"
  78. OWNCLOUD_HASH="ea07124a1b9632aa5227240d655e4d84967fb6dd49e4a16d3207d6179d031a3a"
  79. GPG_KEYSERVER="hkp://keys.gnupg.net"
  80. # optionally you can provide your exported GPG key pair here
  81. # Note that the private key file will be deleted after use
  82. # If these are unspecified then a new GPG key will be created
  83. MY_GPG_PUBLIC_KEY=
  84. MY_GPG_PRIVATE_KEY=
  85. # If you have existing mail within a Maildir
  86. # you can specify the directory here and the files
  87. # will be imported
  88. IMPORT_MAILDIR=
  89. # The Debian package repository to use.
  90. DEBIAN_REPO="ftp.de.debian.org"
  91. DEBIAN_VERSION="jessie"
  92. # Directory where source code is downloaded and compiled
  93. INSTALL_DIR=$HOME/build
  94. # device name for an attached usb drive
  95. USB_DRIVE=/dev/sda1
  96. # memory limit for php in MB
  97. MAX_PHP_MEMORY="32"
  98. export DEBIAN_FRONTEND=noninteractive
  99. # File which keeps track of what has already been installed
  100. COMPLETION_FILE=$HOME/freedombone-completed.txt
  101. if [ ! -f $COMPLETION_FILE ]; then
  102. touch $COMPLETION_FILE
  103. fi
  104. function show_help {
  105. echo ''
  106. echo './install-freedombone.sh [domain] [username] [subdomain code] [system type]'
  107. echo ''
  108. echo 'domain'
  109. echo '------'
  110. echo 'This is your domain name or freedns subdomain.'
  111. echo ''
  112. echo 'username'
  113. echo '--------'
  114. echo ''
  115. echo 'This will be your username on the system. It should be all'
  116. echo 'lower case and contain no spaces'
  117. echo ''
  118. echo 'subdomain code'
  119. echo '--------------'
  120. echo 'This is the freedns dynamic DNS code for your subdomain.'
  121. echo "To find it from https://freedns.afraid.org select 'Dynamic DNS',"
  122. echo "then 'quick cron example' and copy the code located between "
  123. echo "'?' and '=='."
  124. echo ''
  125. echo 'system type'
  126. echo '-----------'
  127. echo 'This can either be blank if you wish to install the full system,'
  128. echo 'or for more specialised variants you can specify "mailbox", "cloud",'
  129. echo '"chat", "social" or "writer"'
  130. echo ''
  131. }
  132. function argument_checks {
  133. if [ ! -d /home/$MY_USERNAME ]; then
  134. echo "There is no user '$MY_USERNAME' on the system. Use 'adduser $MY_USERNAME' to create the user."
  135. exit 1
  136. fi
  137. if [ ! $DOMAIN_NAME ]; then
  138. show_help
  139. exit 2
  140. fi
  141. if [ ! $MY_USERNAME ]; then
  142. show_help
  143. exit 3
  144. fi
  145. if [ ! $FREEDNS_SUBDOMAIN_CODE ]; then
  146. show_help
  147. exit 4
  148. fi
  149. }
  150. function change_login_message {
  151. if grep -Fxq "change_login_message" $COMPLETION_FILE; then
  152. return
  153. fi
  154. echo '' > /etc/motd
  155. echo ".---. . . " >> /etc/motd
  156. echo "| | | " >> /etc/motd
  157. echo "|--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-. " >> /etc/motd
  158. echo "| | (.-' (.-' ( | ( )| | | | )( )| | (.-' " >> /etc/motd
  159. echo "' ' --' --' -' - -' ' ' -' -' -' ' - --'" >> /etc/motd
  160. if [[ $SYSTEM_TYPE == "cloud" ]]; then
  161. echo ' .--.. . ' >> /etc/motd
  162. echo ' : | | ' >> /etc/motd
  163. echo ' | | .-. . . .-.| ' >> /etc/motd
  164. echo ' : |( )| |( | ' >> /etc/motd
  165. echo " --' - -' -- - -' -" >> /etc/motd
  166. fi
  167. if [[ $SYSTEM_TYPE == "chat" ]]; then
  168. echo ' .--.. . ' >> /etc/motd
  169. echo ' : | _|_ ' >> /etc/motd
  170. echo ' | |--. .-. | ' >> /etc/motd
  171. echo ' : | |( ) | ' >> /etc/motd
  172. echo " --'' - -' - -' " >> /etc/motd
  173. fi
  174. if [[ $SYSTEM_TYPE == "social" ]]; then
  175. echo ' .-. . ' >> /etc/motd
  176. echo ' ( ) o | ' >> /etc/motd
  177. echo ' -. .-. .-. . .-. | ' >> /etc/motd
  178. echo ' ( )( )( | ( ) | ' >> /etc/motd
  179. echo " -' -' -'-' - -' - - " >> /etc/motd
  180. fi
  181. if [[ $SYSTEM_TYPE == "email" || $SYSTEM_TYPE == "mailbox" ]]; then
  182. echo ' . . . . ' >> /etc/motd
  183. echo ' |\ /| o | | ' >> /etc/motd
  184. echo ' | \/ | .-. . | |.-. .-.-. ,- ' >> /etc/motd
  185. echo ' | |( ) | | | )( ) : ' >> /etc/motd
  186. echo ' ' ' -' --' - -' -' -'-' - ' >> /etc/motd
  187. fi
  188. echo '' >> /etc/motd
  189. echo ' Freedom in the Cloud' >> /etc/motd
  190. echo '' >> /etc/motd
  191. echo 'change_login_message' >> $COMPLETION_FILE
  192. }
  193. function search_for_attached_usb_drive {
  194. # If a USB drive is attached then search for email,
  195. # gpg, ssh keys and emacs configuration
  196. if grep -Fxq "search_for_attached_usb_drive" $COMPLETION_FILE; then
  197. return
  198. fi
  199. if [ -b $USB_DRIVE ]; then
  200. if [ ! -d /media/usb ]; then
  201. echo 'Mounting USB drive'
  202. mkdir /media/usb
  203. mount $USB_DRIVE /media/usb
  204. fi
  205. if ! [[ $SYSTEM_TYPE == "writer" || $SYSTEM_TYPE == "cloud" || $SYSTEM_TYPE == "chat" || $SYSTEM_TYPE == "social" ]]; then
  206. if [ -d /media/usb/Maildir ]; then
  207. echo 'Maildir found on USB drive'
  208. IMPORT_MAILDIR=/media/usb/Maildir
  209. fi
  210. if [ -d /media/usb/.gnupg ]; then
  211. echo 'Importing GPG keyring'
  212. cp -r /media/usb/.gnupg /home/$MY_USERNAME
  213. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.gnupg
  214. if [ -f /home/$MY_USERNAME/.gnupg/secring.gpg ]; then
  215. shred -zu /media/usb/.gnupg/secring.gpg
  216. shred -zu /media/usb/.gnupg/random_seed
  217. shred -zu /media/usb/.gnupg/trustdb.gpg
  218. rm -rf /media/usb/.gnupg
  219. else
  220. echo 'GPG files did not copy'
  221. exit 7
  222. fi
  223. fi
  224. if [ -f /media/usb/private_key.gpg ]; then
  225. echo 'GPG private key found on USB drive'
  226. MY_GPG_PRIVATE_KEY=/media/usb/private_key.gpg
  227. fi
  228. if [ -f /media/usb/public_key.gpg ]; then
  229. echo 'GPG public key found on USB drive'
  230. MY_GPG_PUBLIC_KEY=/media/usb/public_key.gpg
  231. fi
  232. fi
  233. if [ -d /media/usb/.ssh ]; then
  234. echo 'Importing ssh keys'
  235. cp -r /media/usb/.ssh /home/$MY_USERNAME
  236. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.ssh
  237. # for security delete the ssh keys from the usb drive
  238. if [ -f /home/$MY_USERNAME/.ssh/id_rsa ]; then
  239. shred -zu /media/usb/.ssh/id_rsa
  240. shred -zu /media/usb/.ssh/id_rsa.pub
  241. shred -zu /media/usb/.ssh/known_hosts
  242. rm -rf /media/usb/.ssh
  243. else
  244. echo 'ssh files did not copy'
  245. exit 8
  246. fi
  247. fi
  248. if [ -f /media/usb/.emacs ]; then
  249. echo 'Importing .emacs file'
  250. cp -f /media/usb/.emacs /home/$MY_USERNAME/.emacs
  251. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.emacs
  252. fi
  253. if [ -d /media/usb/.emacs.d ]; then
  254. echo 'Importing .emacs.d directory'
  255. cp -r /media/usb/.emacs.d /home/$MY_USERNAME
  256. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.emacs.d
  257. fi
  258. if [ -d /media/usb/personal ]; then
  259. echo 'Importing personal directory'
  260. cp -r /media/usb/personal /home/$MY_USERNAME
  261. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/personal
  262. fi
  263. else
  264. if [ -d /media/usb ]; then
  265. umount /media/usb
  266. rm -rf /media/usb
  267. fi
  268. echo 'No USB drive attached'
  269. fi
  270. echo 'search_for_attached_usb_drive' >> $COMPLETION_FILE
  271. }
  272. function remove_proprietary_repos {
  273. if grep -Fxq "remove_proprietary_repos" $COMPLETION_FILE; then
  274. return
  275. fi
  276. sed -i 's/ non-free//g' /etc/apt/sources.list
  277. echo 'remove_proprietary_repos' >> $COMPLETION_FILE
  278. }
  279. function change_debian_repos {
  280. if grep -Fxq "change_debian_repos" $COMPLETION_FILE; then
  281. return
  282. fi
  283. rm -rf /var/lib/apt/lists/*
  284. apt-get clean
  285. sed -i "s/ftp.us.debian.org/$DEBIAN_REPO/g" /etc/apt/sources.list
  286. # ensure that there is a security repo
  287. if ! grep -q "security" /etc/apt/sources.list; then
  288. if grep -q "jessie" /etc/apt/sources.list; then
  289. echo "deb http://security.debian.org/ jessie/updates main contrib" >> /etc/apt/sources.list
  290. echo "#deb-src http://security.debian.org/ jessie/updates main contrib" >> /etc/apt/sources.list
  291. else
  292. if grep -q "wheezy" /etc/apt/sources.list; then
  293. echo "deb http://security.debian.org/ wheezy/updates main contrib" >> /etc/apt/sources.list
  294. echo "#deb-src http://security.debian.org/ wheezy/updates main contrib" >> /etc/apt/sources.list
  295. fi
  296. fi
  297. fi
  298. apt-get update
  299. apt-get -y --force-yes install apt-transport-https
  300. echo 'change_debian_repos' >> $COMPLETION_FILE
  301. }
  302. function initial_setup {
  303. if grep -Fxq "initial_setup" $COMPLETION_FILE; then
  304. return
  305. fi
  306. apt-get -y remove --purge apache*
  307. apt-get -y dist-upgrade
  308. apt-get -y install ca-certificates emacs24
  309. echo 'initial_setup' >> $COMPLETION_FILE
  310. }
  311. function install_editor {
  312. if grep -Fxq "install_editor" $COMPLETION_FILE; then
  313. return
  314. fi
  315. update-alternatives --set editor /usr/bin/emacs24
  316. echo 'install_editor' >> $COMPLETION_FILE
  317. }
  318. function enable_backports {
  319. if grep -Fxq "enable_backports" $COMPLETION_FILE; then
  320. return
  321. fi
  322. if ! grep -Fxq "deb http://$DEBIAN_REPO/debian jessie-backports main" /etc/apt/sources.list; then
  323. echo "deb http://$DEBIAN_REPO/debian jessie-backports main" >> /etc/apt/sources.list
  324. fi
  325. echo 'enable_backports' >> $COMPLETION_FILE
  326. }
  327. function update_the_kernel {
  328. if grep -Fxq "update_the_kernel" $COMPLETION_FILE; then
  329. return
  330. fi
  331. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  332. return
  333. fi
  334. cd /opt/scripts/tools
  335. ./update_kernel.sh --kernel $KERNEL_VERSION
  336. echo 'update_the_kernel' >> $COMPLETION_FILE
  337. }
  338. function enable_zram {
  339. if grep -Fxq "enable_zram" $COMPLETION_FILE; then
  340. return
  341. fi
  342. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  343. return
  344. fi
  345. if ! grep -q "options zram num_devices=1" /etc/modprobe.d/zram.conf; then
  346. echo 'options zram num_devices=1' >> /etc/modprobe.d/zram.conf
  347. fi
  348. echo '#!/bin/bash' > /etc/init.d/zram
  349. echo '### BEGIN INIT INFO' >> /etc/init.d/zram
  350. echo '# Provides: zram' >> /etc/init.d/zram
  351. echo '# Required-Start:' >> /etc/init.d/zram
  352. echo '# Required-Stop:' >> /etc/init.d/zram
  353. echo '# Default-Start: 2 3 4 5' >> /etc/init.d/zram
  354. echo '# Default-Stop: 0 1 6' >> /etc/init.d/zram
  355. echo '# Short-Description: Increased Performance In Linux With zRam (Virtual Swap Compressed in RAM)' >> /etc/init.d/zram
  356. echo '# Description: Adapted from systemd scripts at https://github.com/mystilleef/FedoraZram' >> /etc/init.d/zram
  357. echo '### END INIT INFO' >> /etc/init.d/zram
  358. echo 'start() {' >> /etc/init.d/zram
  359. echo ' # get the number of CPUs' >> /etc/init.d/zram
  360. echo ' num_cpus=$(grep -c processor /proc/cpuinfo)' >> /etc/init.d/zram
  361. echo ' # if something goes wrong, assume we have 1' >> /etc/init.d/zram
  362. echo ' [ "$num_cpus" != 0 ] || num_cpus=1' >> /etc/init.d/zram
  363. echo ' # set decremented number of CPUs' >> /etc/init.d/zram
  364. echo ' decr_num_cpus=$((num_cpus - 1))' >> /etc/init.d/zram
  365. echo ' # get the amount of memory in the machine' >> /etc/init.d/zram
  366. echo ' mem_total_kb=$(grep MemTotal /proc/meminfo | grep -E --only-matching "[[:digit:]]+")' >> /etc/init.d/zram
  367. echo ' mem_total=$((mem_total_kb * 1024))' >> /etc/init.d/zram
  368. echo ' # load dependency modules' >> /etc/init.d/zram
  369. echo ' modprobe zram num_devices=$num_cpus' >> /etc/init.d/zram
  370. echo ' # initialize the devices' >> /etc/init.d/zram
  371. echo ' for i in $(seq 0 $decr_num_cpus); do' >> /etc/init.d/zram
  372. echo ' echo $((mem_total / num_cpus)) > /sys/block/zram$i/disksize' >> /etc/init.d/zram
  373. echo ' done' >> /etc/init.d/zram
  374. echo ' # Creating swap filesystems' >> /etc/init.d/zram
  375. echo ' for i in $(seq 0 $decr_num_cpus); do' >> /etc/init.d/zram
  376. echo ' mkswap /dev/zram$i' >> /etc/init.d/zram
  377. echo ' done' >> /etc/init.d/zram
  378. echo ' # Switch the swaps on' >> /etc/init.d/zram
  379. echo ' for i in $(seq 0 $decr_num_cpus); do' >> /etc/init.d/zram
  380. echo ' swapon -p 100 /dev/zram$i' >> /etc/init.d/zram
  381. echo ' done' >> /etc/init.d/zram
  382. echo '}' >> /etc/init.d/zram
  383. echo 'stop() {' >> /etc/init.d/zram
  384. echo ' # get the number of CPUs' >> /etc/init.d/zram
  385. echo ' num_cpus=$(grep -c processor /proc/cpuinfo)' >> /etc/init.d/zram
  386. echo ' # set decremented number of CPUs' >> /etc/init.d/zram
  387. echo ' decr_num_cpus=$((num_cpus - 1))' >> /etc/init.d/zram
  388. echo ' # Switching off swap' >> /etc/init.d/zram
  389. echo ' for i in $(seq 0 $decr_num_cpus); do' >> /etc/init.d/zram
  390. echo ' if [ "$(grep /dev/zram$i /proc/swaps)" != "" ]; then' >> /etc/init.d/zram
  391. echo ' swapoff /dev/zram$i' >> /etc/init.d/zram
  392. echo ' sleep 1' >> /etc/init.d/zram
  393. echo ' fi' >> /etc/init.d/zram
  394. echo ' done' >> /etc/init.d/zram
  395. echo ' sleep 1' >> /etc/init.d/zram
  396. echo ' rmmod zram' >> /etc/init.d/zram
  397. echo '}' >> /etc/init.d/zram
  398. echo 'case "$1" in' >> /etc/init.d/zram
  399. echo ' start)' >> /etc/init.d/zram
  400. echo ' start' >> /etc/init.d/zram
  401. echo ' ;;' >> /etc/init.d/zram
  402. echo ' stop)' >> /etc/init.d/zram
  403. echo ' stop' >> /etc/init.d/zram
  404. echo ' ;;' >> /etc/init.d/zram
  405. echo ' restart)' >> /etc/init.d/zram
  406. echo ' stop' >> /etc/init.d/zram
  407. echo ' sleep 3' >> /etc/init.d/zram
  408. echo ' start' >> /etc/init.d/zram
  409. echo ' ;;' >> /etc/init.d/zram
  410. echo ' *)' >> /etc/init.d/zram
  411. echo ' echo "Usage: $0 {start|stop|restart}"' >> /etc/init.d/zram
  412. echo ' RETVAL=1' >> /etc/init.d/zram
  413. echo 'esac' >> /etc/init.d/zram
  414. echo 'exit $RETVAL' >> /etc/init.d/zram
  415. chmod +x /etc/init.d/zram
  416. update-rc.d zram defaults
  417. echo 'enable_zram' >> $COMPLETION_FILE
  418. }
  419. function random_number_generator {
  420. if grep -Fxq "random_number_generator" $COMPLETION_FILE; then
  421. return
  422. fi
  423. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  424. # it is assumed that docker uses the random number
  425. # generator of the host system
  426. return
  427. fi
  428. if [[ $USE_HWRNG == "yes" ]]; then
  429. apt-get -y --force-yes install rng-tools
  430. sed -i 's|#HRNGDEVICE=/dev/hwrng|HRNGDEVICE=/dev/hwrng|g' /etc/default/rng-tools
  431. else
  432. apt-get -y --force-yes install haveged
  433. fi
  434. echo 'random_number_generator' >> $COMPLETION_FILE
  435. }
  436. function configure_ssh {
  437. if grep -Fxq "configure_ssh" $COMPLETION_FILE; then
  438. return
  439. fi
  440. sed -i "s/Port 22/Port $SSH_PORT/g" /etc/ssh/sshd_config
  441. sed -i 's/PermitRootLogin without-password/PermitRootLogin no/g' /etc/ssh/sshd_config
  442. sed -i 's/X11Forwarding yes/X11Forwarding no/g' /etc/ssh/sshd_config
  443. sed -i 's/ServerKeyBits 1024/ServerKeyBits 4096/g' /etc/ssh/sshd_config
  444. sed -i 's/TCPKeepAlive yes/TCPKeepAlive no/g' /etc/ssh/sshd_config
  445. sed -i 's|HostKey /etc/ssh/ssh_host_dsa_key|#HostKey /etc/ssh/ssh_host_dsa_key|g' /etc/ssh/sshd_config
  446. sed -i 's|HostKey /etc/ssh/ssh_host_ecdsa_key|#HostKey /etc/ssh/ssh_host_ecdsa_key|g' /etc/ssh/sshd_config
  447. echo 'ClientAliveInterval 60' >> /etc/ssh/sshd_config
  448. echo 'ClientAliveCountMax 3' >> /etc/ssh/sshd_config
  449. echo 'Ciphers aes256-ctr,aes128-ctr' >> /etc/ssh/sshd_config
  450. echo 'MACs hmac-sha2-512,hmac-sha2-256,hmac-ripemd160
  451. KexAlgorithms diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1' >> /etc/ssh/sshd_config
  452. apt-get -y --force-yes install fail2ban
  453. echo 'configure_ssh' >> $COMPLETION_FILE
  454. # Don't reboot if installing within docker
  455. # random numbers will come from the host system
  456. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  457. return
  458. fi
  459. echo ''
  460. echo ''
  461. echo ' *** Rebooting to initialise ssh settings and random number generator ***'
  462. echo ''
  463. echo " *** Reconnect via ssh on port $SSH_PORT, then run this script again ***"
  464. echo ''
  465. reboot
  466. }
  467. function regenerate_ssh_keys {
  468. if grep -Fxq "regenerate_ssh_keys" $COMPLETION_FILE; then
  469. return
  470. fi
  471. rm -f /etc/ssh/ssh_host_*
  472. dpkg-reconfigure openssh-server
  473. service ssh restart
  474. echo 'regenerate_ssh_keys' >> $COMPLETION_FILE
  475. }
  476. function configure_dns {
  477. if grep -Fxq "configure_dns" $COMPLETION_FILE; then
  478. return
  479. fi
  480. echo 'domain localdomain' > /etc/resolv.conf
  481. echo 'search localdomain' >> /etc/resolv.conf
  482. echo 'nameserver 213.73.91.35' >> /etc/resolv.conf
  483. echo 'nameserver 85.214.20.141' >> /etc/resolv.conf
  484. echo 'configure_dns' >> $COMPLETION_FILE
  485. }
  486. function set_your_domain_name {
  487. if grep -Fxq "set_your_domain_name" $COMPLETION_FILE; then
  488. return
  489. fi
  490. echo "$DOMAIN_NAME" > /etc/hostname
  491. hostname $DOMAIN_NAME
  492. sed -i "s/127.0.1.1 arm/127.0.1.1 $DOMAIN_NAME/g" /etc/hosts
  493. echo "127.0.1.1 $DOMAIN_NAME" >> /etc/hosts
  494. echo 'set_your_domain_name' >> $COMPLETION_FILE
  495. }
  496. function time_synchronisation {
  497. if grep -Fxq "time_synchronisation" $COMPLETION_FILE; then
  498. return
  499. fi
  500. apt-get -y --force-yes install tlsdate
  501. apt-get -y remove ntpdate
  502. echo '#!/bin/bash' > /usr/bin/updatedate
  503. echo 'TIMESOURCE=google.com' >> /usr/bin/updatedate
  504. echo 'TIMESOURCE2=www.ptb.de' >> /usr/bin/updatedate
  505. echo 'LOGFILE=/var/log/tlsdate.log' >> /usr/bin/updatedate
  506. echo 'TIMEOUT=5' >> /usr/bin/updatedate
  507. echo "EMAIL=$MY_USERNAME@$DOMAIN_NAME" >> /usr/bin/updatedate
  508. echo '# File which contains the previous date as a number' >> /usr/bin/updatedate
  509. echo 'BEFORE_DATE_FILE=/var/log/tlsdateprevious.txt' >> /usr/bin/updatedate
  510. echo '# File which contains the previous date as a string' >> /usr/bin/updatedate
  511. echo 'BEFORE_FULLDATE_FILE=/var/log/tlsdate.txt' >> /usr/bin/updatedate
  512. echo 'DATE_BEFORE=$(date)' >> /usr/bin/updatedate
  513. echo 'BEFORE=$(date -d "$Y-$M-$D" "+%s")' >> /usr/bin/updatedate
  514. echo 'BACKWARDS_BETWEEN=0' >> /usr/bin/updatedate
  515. echo '# If the date was previously set' >> /usr/bin/updatedate
  516. echo 'if [[ -f "$BEFORE_DATE_FILE" ]]; then' >> /usr/bin/updatedate
  517. echo ' BEFORE_FILE=$(cat $BEFORE_DATE_FILE)' >> /usr/bin/updatedate
  518. echo ' BEFORE_FULLDATE=$(cat $BEFORE_FULLDATE_FILE)' >> /usr/bin/updatedate
  519. echo ' # is the date going backwards?' >> /usr/bin/updatedate
  520. echo ' if (( BEFORE_FILE > BEFORE )); then' >> /usr/bin/updatedate
  521. echo ' echo -n "Date went backwards between tlsdate updates. " >> $LOGFILE' >> /usr/bin/updatedate
  522. echo ' echo -n "$BEFORE_FILE > $BEFORE, " >> $LOGFILE' >> /usr/bin/updatedate
  523. echo ' echo "$BEFORE_FULLDATE > $DATE_BEFORE" >> $LOGFILE' >> /usr/bin/updatedate
  524. echo ' # Send a warning email' > /usr/bin/updatedate
  525. echo ' echo $(tail $LOGFILE -n 2) | mail -s "tlsdate anomaly" $EMAIL' >> /usr/bin/updatedate
  526. echo ' # Try another time source' >> /usr/bin/updatedate
  527. echo ' TIMESOURCE=$TIMESOURCE2' >> /usr/bin/updatedate
  528. echo ' # try running without any parameters' >> /usr/bin/updatedate
  529. echo ' tlsdate >> $LOGFILE' >> /usr/bin/updatedate
  530. echo ' BACKWARDS_BETWEEN=1' >> /usr/bin/updatedate
  531. echo ' fi' >> /usr/bin/updatedate
  532. echo 'fi' >> /usr/bin/updatedate
  533. echo '# Set the date' >> /usr/bin/updatedate
  534. echo '/usr/bin/timeout $TIMEOUT tlsdate -l -t -H $TIMESOURCE -p 443 >> $LOGFILE' >> /usr/bin/updatedate
  535. echo 'DATE_AFTER=$(date)' >> /usr/bin/updatedate
  536. echo 'AFTER=$(date -d "$Y-$M-$D" '+%s')' >> /usr/bin/updatedate
  537. echo '# After setting the date did it go backwards?' >> /usr/bin/updatedate
  538. echo 'if (( AFTER < BEFORE )); then' >> /usr/bin/updatedate
  539. echo ' echo "Incorrect date: $DATE_BEFORE -> $DATE_AFTER" >> $LOGFILE' >> /usr/bin/updatedate
  540. echo ' # Send a warning email' >> /usr/bin/updatedate
  541. echo ' echo $(tail $LOGFILE -n 2) | mail -s "tlsdate anomaly" $EMAIL' >> /usr/bin/updatedate
  542. echo ' # Try resetting the date from another time source' >> /usr/bin/updatedate
  543. echo ' /usr/bin/timeout $TIMEOUT tlsdate -l -t -H $TIMESOURCE2 -p 443 >> $LOGFILE' >> /usr/bin/updatedate
  544. echo ' DATE_AFTER=$(date)' >> /usr/bin/updatedate
  545. echo ' AFTER=$(date -d "$Y-$M-$D" "+%s")' >> /usr/bin/updatedate
  546. echo 'else' >> /usr/bin/updatedate
  547. echo ' echo -n $TIMESOURCE >> $LOGFILE' >> /usr/bin/updatedate
  548. echo ' if [[ -f "$BEFORE_DATE_FILE" ]]; then' >> /usr/bin/updatedate
  549. echo ' echo -n " " >> $LOGFILE' >> /usr/bin/updatedate
  550. echo ' echo -n $BEFORE_FILE >> $LOGFILE' >> /usr/bin/updatedate
  551. echo ' fi' >> /usr/bin/updatedate
  552. echo ' echo -n " " >> $LOGFILE' >> /usr/bin/updatedate
  553. echo ' echo -n $BEFORE >> $LOGFILE' >> /usr/bin/updatedate
  554. echo ' echo -n " " >> $LOGFILE' >> /usr/bin/updatedate
  555. echo ' echo -n $AFTER >> $LOGFILE' >> /usr/bin/updatedate
  556. echo ' echo -n " " >> $LOGFILE' >> /usr/bin/updatedate
  557. echo ' echo $DATE_AFTER >> $LOGFILE' >> /usr/bin/updatedate
  558. echo 'fi' >> /usr/bin/updatedate
  559. echo '# Log the last date' >> /usr/bin/updatedate
  560. echo 'if [ BACKWARDS_BETWEEN == 0 ]; then' >> /usr/bin/updatedate
  561. echo ' echo "$AFTER" > $BEFORE_DATE_FILE' >> /usr/bin/updatedate
  562. echo ' echo "$DATE_AFTER" > $BEFORE_FULLDATE_FILE' >> /usr/bin/updatedate
  563. echo ' exit 0' >> /usr/bin/updatedate
  564. echo 'else' >> /usr/bin/updatedate
  565. echo ' exit 1' >> /usr/bin/updatedate
  566. echo 'fi' >> /usr/bin/updatedate
  567. chmod +x /usr/bin/updatedate
  568. echo '*/15 * * * * root /usr/bin/updatedate' >> /etc/crontab
  569. service cron restart
  570. echo '#!/bin/bash' > /etc/init.d/tlsdate
  571. echo '# /etc/init.d/tlsdate' >> /etc/init.d/tlsdate
  572. echo '### BEGIN INIT INFO' >> /etc/init.d/tlsdate
  573. echo '# Provides: tlsdate' >> /etc/init.d/tlsdate
  574. echo '# Required-Start: $remote_fs $syslog' >> /etc/init.d/tlsdate
  575. echo '# Required-Stop: $remote_fs $syslog' >> /etc/init.d/tlsdate
  576. echo '# Default-Start: 2 3 4 5' >> /etc/init.d/tlsdate
  577. echo '# Default-Stop: 0 1 6' >> /etc/init.d/tlsdate
  578. echo '# Short-Description: Initially calls tlsdate with the timewarp option' >> /etc/init.d/tlsdate
  579. echo '# Description: Initially calls tlsdate with the timewarp option' >> /etc/init.d/tlsdate
  580. echo '### END INIT INFO' >> /etc/init.d/tlsdate
  581. echo '# Author: Bob Mottram <bob@robotics.uk.to>' >> /etc/init.d/tlsdate
  582. echo 'PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin"' >> /etc/init.d/tlsdate
  583. echo 'LOGFILE="/var/log/tlsdate.log"' >> /etc/init.d/tlsdate
  584. echo 'TLSDATECOMMAND="tlsdate --timewarp -l -H www.ptb.de -p 443 >> $LOGFILE"' >> /etc/init.d/tlsdate
  585. echo '#Start-Stop here' >> /etc/init.d/tlsdate
  586. echo 'case "$1" in' >> /etc/init.d/tlsdate
  587. echo ' start)' >> /etc/init.d/tlsdate
  588. echo ' echo "tlsdate started"' >> /etc/init.d/tlsdate
  589. echo ' $TLSDATECOMMAND' >> /etc/init.d/tlsdate
  590. echo ' ;;' >> /etc/init.d/tlsdate
  591. echo ' stop)' >> /etc/init.d/tlsdate
  592. echo ' echo "tlsdate stopped"' >> /etc/init.d/tlsdate
  593. echo ' ;;' >> /etc/init.d/tlsdate
  594. echo ' restart)' >> /etc/init.d/tlsdate
  595. echo ' echo "tlsdate restarted"' >> /etc/init.d/tlsdate
  596. echo ' $TLSDATECOMMAND' >> /etc/init.d/tlsdate
  597. echo ' ;;' >> /etc/init.d/tlsdate
  598. echo ' *)' >> /etc/init.d/tlsdate
  599. echo ' echo "Usage: $0 {start|stop|restart}"' >> /etc/init.d/tlsdate
  600. echo ' exit 1' >> /etc/init.d/tlsdate
  601. echo ' ;;' >> /etc/init.d/tlsdate
  602. echo 'esac' >> /etc/init.d/tlsdate
  603. echo 'exit 0' >> /etc/init.d/tlsdate
  604. chmod +x /etc/init.d/tlsdate
  605. update-rc.d tlsdate defaults
  606. echo 'time_synchronisation' >> $COMPLETION_FILE
  607. }
  608. function configure_firewall {
  609. if grep -Fxq "configure_firewall" $COMPLETION_FILE; then
  610. return
  611. fi
  612. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  613. # docker does its own firewalling
  614. return
  615. fi
  616. iptables -P INPUT ACCEPT
  617. ip6tables -P INPUT ACCEPT
  618. iptables -F
  619. ip6tables -F
  620. iptables -X
  621. ip6tables -X
  622. iptables -P INPUT DROP
  623. ip6tables -P INPUT DROP
  624. iptables -A INPUT -i lo -j ACCEPT
  625. iptables -A INPUT -i eth0 -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
  626. echo 'configure_firewall' >> $COMPLETION_FILE
  627. }
  628. function save_firewall_settings {
  629. iptables-save > /etc/firewall.conf
  630. ip6tables-save > /etc/firewall6.conf
  631. printf '#!/bin/sh\n' > /etc/network/if-up.d/iptables
  632. printf 'iptables-restore < /etc/firewall.conf\n' >> /etc/network/if-up.d/iptables
  633. printf 'ip6tables-restore < /etc/firewall6.conf\n' >> /etc/network/if-up.d/iptables
  634. chmod +x /etc/network/if-up.d/iptables
  635. }
  636. function configure_firewall_for_dns {
  637. if grep -Fxq "configure_firewall_for_dns" $COMPLETION_FILE; then
  638. return
  639. fi
  640. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  641. # docker does its own firewalling
  642. return
  643. fi
  644. iptables -A INPUT -i eth0 -p udp -m udp --dport 1024:65535 --sport 53 -j ACCEPT
  645. save_firewall_settings
  646. echo 'configure_firewall_for_dns' >> $COMPLETION_FILE
  647. }
  648. function configure_firewall_for_xmpp {
  649. if [ ! -d /etc/prosody ]; then
  650. return
  651. fi
  652. if grep -Fxq "configure_firewall_for_xmpp" $COMPLETION_FILE; then
  653. return
  654. fi
  655. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  656. # docker does its own firewalling
  657. return
  658. fi
  659. iptables -A INPUT -i eth0 -p tcp --dport 5222:5223 -j ACCEPT
  660. iptables -A INPUT -i eth0 -p tcp --dport 5269 -j ACCEPT
  661. iptables -A INPUT -i eth0 -p tcp --dport 5280:5281 -j ACCEPT
  662. save_firewall_settings
  663. echo 'configure_firewall_for_xmpp' >> $COMPLETION_FILE
  664. }
  665. function configure_firewall_for_ftp {
  666. if grep -Fxq "configure_firewall_for_ftp" $COMPLETION_FILE; then
  667. return
  668. fi
  669. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  670. # docker does its own firewalling
  671. return
  672. fi
  673. iptables -I INPUT -i eth0 -p tcp --dport 1024:65535 --sport 20:21 -j ACCEPT
  674. save_firewall_settings
  675. echo 'configure_firewall_for_ftp' >> $COMPLETION_FILE
  676. }
  677. function configure_firewall_for_web_access {
  678. if grep -Fxq "configure_firewall_for_web_access" $COMPLETION_FILE; then
  679. return
  680. fi
  681. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  682. # docker does its own firewalling
  683. return
  684. fi
  685. iptables -A INPUT -i eth0 -p tcp --dport 32768:61000 --sport 80 -j ACCEPT
  686. iptables -A INPUT -i eth0 -p tcp --dport 32768:61000 --sport 443 -j ACCEPT
  687. save_firewall_settings
  688. echo 'configure_firewall_for_web_access' >> $COMPLETION_FILE
  689. }
  690. function configure_firewall_for_web_server {
  691. if grep -Fxq "configure_firewall_for_web_server" $COMPLETION_FILE; then
  692. return
  693. fi
  694. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  695. # docker does its own firewalling
  696. return
  697. fi
  698. iptables -A INPUT -i eth0 -p tcp --dport 80 -j ACCEPT
  699. iptables -A INPUT -i eth0 -p tcp --dport 443 -j ACCEPT
  700. save_firewall_settings
  701. echo 'configure_firewall_for_web_server' >> $COMPLETION_FILE
  702. }
  703. function configure_firewall_for_ssh {
  704. if grep -Fxq "configure_firewall_for_ssh" $COMPLETION_FILE; then
  705. return
  706. fi
  707. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  708. # docker does its own firewalling
  709. return
  710. fi
  711. iptables -A INPUT -i eth0 -p tcp --dport 22 -j ACCEPT
  712. iptables -A INPUT -i eth0 -p tcp --dport $SSH_PORT -j ACCEPT
  713. save_firewall_settings
  714. echo 'configure_firewall_for_ssh' >> $COMPLETION_FILE
  715. }
  716. function configure_firewall_for_git {
  717. if grep -Fxq "configure_firewall_for_git" $COMPLETION_FILE; then
  718. return
  719. fi
  720. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  721. # docker does its own firewalling
  722. return
  723. fi
  724. iptables -A INPUT -i eth0 -p tcp --dport 9418 -j ACCEPT
  725. save_firewall_settings
  726. echo 'configure_firewall_for_git' >> $COMPLETION_FILE
  727. }
  728. function configure_firewall_for_email {
  729. if [[ $SYSTEM_TYPE == "writer" || $SYSTEM_TYPE == "cloud" || $SYSTEM_TYPE == "chat" || $SYSTEM_TYPE == "social" ]]; then
  730. return
  731. fi
  732. if grep -Fxq "configure_firewall_for_email" $COMPLETION_FILE; then
  733. return
  734. fi
  735. if [[ $INSTALLED_WITHIN_DOCKER == "yes" ]]; then
  736. # docker does its own firewalling
  737. return
  738. fi
  739. iptables -A INPUT -i eth0 -p tcp --dport 25 -j ACCEPT
  740. iptables -A INPUT -i eth0 -p tcp --dport 587 -j ACCEPT
  741. iptables -A INPUT -i eth0 -p tcp --dport 465 -j ACCEPT
  742. iptables -A INPUT -i eth0 -p tcp --dport 993 -j ACCEPT
  743. save_firewall_settings
  744. echo 'configure_firewall_for_email' >> $COMPLETION_FILE
  745. }
  746. function configure_internet_protocol {
  747. if grep -Fxq "configure_internet_protocol" $COMPLETION_FILE; then
  748. return
  749. fi
  750. sed -i "s/#net.ipv4.tcp_syncookies=1/net.ipv4.tcp_syncookies=1/g" /etc/sysctl.conf
  751. sed -i "s/#net.ipv4.conf.all.accept_redirects = 0/net.ipv4.conf.all.accept_redirects = 0/g" /etc/sysctl.conf
  752. sed -i "s/#net.ipv6.conf.all.accept_redirects = 0/net.ipv6.conf.all.accept_redirects = 0/g" /etc/sysctl.conf
  753. sed -i "s/#net.ipv4.conf.all.send_redirects = 0/net.ipv4.conf.all.send_redirects = 0/g" /etc/sysctl.conf
  754. sed -i "s/#net.ipv4.conf.all.accept_source_route = 0/net.ipv4.conf.all.accept_source_route = 0/g" /etc/sysctl.conf
  755. sed -i "s/#net.ipv6.conf.all.accept_source_route = 0/net.ipv6.conf.all.accept_source_route = 0/g" /etc/sysctl.conf
  756. sed -i "s/#net.ipv4.conf.default.rp_filter=1/net.ipv4.conf.default.rp_filter=1/g" /etc/sysctl.conf
  757. sed -i "s/#net.ipv4.conf.all.rp_filter=1/net.ipv4.conf.all.rp_filter=1/g" /etc/sysctl.conf
  758. sed -i "s/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=0/g" /etc/sysctl.conf
  759. sed -i "s/#net.ipv6.conf.all.forwarding=1/net.ipv6.conf.all.forwarding=0/g" /etc/sysctl.conf
  760. echo '# ignore pings' >> /etc/sysctl.conf
  761. echo 'net.ipv4.icmp_echo_ignore_all = 1' >> /etc/sysctl.conf
  762. echo 'net.ipv6.icmp_echo_ignore_all = 1' >> /etc/sysctl.conf
  763. echo '# disable ipv6' >> /etc/sysctl.conf
  764. echo 'net.ipv6.conf.all.disable_ipv6 = 1' >> /etc/sysctl.conf
  765. echo 'net.ipv4.tcp_synack_retries = 2' >> /etc/sysctl.conf
  766. echo 'net.ipv4.tcp_syn_retries = 1' >> /etc/sysctl.conf
  767. echo '# keepalive' >> /etc/sysctl.conf
  768. echo 'net.ipv4.tcp_keepalive_probes = 9' >> /etc/sysctl.conf
  769. echo 'net.ipv4.tcp_keepalive_intvl = 75' >> /etc/sysctl.conf
  770. echo 'net.ipv4.tcp_keepalive_time = 7200' >> /etc/sysctl.conf
  771. echo 'configure_internet_protocol' >> $COMPLETION_FILE
  772. }
  773. function script_to_make_self_signed_certificates {
  774. if grep -Fxq "script_to_make_self_signed_certificates" $COMPLETION_FILE; then
  775. return
  776. fi
  777. echo '#!/bin/bash' > /usr/bin/makecert
  778. echo 'HOSTNAME=$1' >> /usr/bin/makecert
  779. echo 'COUNTRY_CODE="US"' >> /usr/bin/makecert
  780. echo 'AREA="Free Speech Zone"' >> /usr/bin/makecert
  781. echo 'LOCATION="Freedomville"' >> /usr/bin/makecert
  782. echo 'ORGANISATION="Freedombone"' >> /usr/bin/makecert
  783. echo 'UNIT="Freedombone Unit"' >> /usr/bin/makecert
  784. echo 'if ! which openssl > /dev/null ;then' >> /usr/bin/makecert
  785. echo ' echo "$0: openssl is not installed, exiting" 1>&2' >> /usr/bin/makecert
  786. echo ' exit 1' >> /usr/bin/makecert
  787. echo 'fi' >> /usr/bin/makecert
  788. echo 'openssl req -x509 -nodes -days 3650 -sha256 -subj "/O=$ORGANISATION/OU=$UNIT/C=$COUNTRY_CODE/ST=$AREA/L=$LOCATION/CN=$HOSTNAME" -newkey rsa:4096 -keyout /etc/ssl/private/$HOSTNAME.key -out /etc/ssl/certs/$HOSTNAME.crt' >> /usr/bin/makecert
  789. echo 'openssl dhparam -check -text -5 1024 -out /etc/ssl/certs/$HOSTNAME.dhparam' >> /usr/bin/makecert
  790. echo 'chmod 400 /etc/ssl/private/$HOSTNAME.key' >> /usr/bin/makecert
  791. echo 'chmod 640 /etc/ssl/certs/$HOSTNAME.crt' >> /usr/bin/makecert
  792. echo 'chmod 640 /etc/ssl/certs/$HOSTNAME.dhparam' >> /usr/bin/makecert
  793. echo 'if [ -f /etc/init.d/nginx ]; then' >> /usr/bin/makecert
  794. echo ' /etc/init.d/nginx reload' >> /usr/bin/makecert
  795. echo 'fi' >> /usr/bin/makecert
  796. echo '# add the public certificate to a separate directory' >> /usr/bin/makecert
  797. echo '# so that we can redistribute it easily' >> /usr/bin/makecert
  798. echo 'if [ ! -d /etc/ssl/mycerts ]; then' >> /usr/bin/makecert
  799. echo ' mkdir /etc/ssl/mycerts' >> /usr/bin/makecert
  800. echo 'fi' >> /usr/bin/makecert
  801. echo 'cp /etc/ssl/certs/$HOSTNAME.crt /etc/ssl/mycerts' >> /usr/bin/makecert
  802. echo '# Create a bundle of your certificates' >> /usr/bin/makecert
  803. echo 'cat /etc/ssl/mycerts/*.crt > /etc/ssl/freedombone-bundle.crt' >> /usr/bin/makecert
  804. echo 'tar -czvf /etc/ssl/freedombone-certs.tar.gz /etc/ssl/mycerts/*.crt' >> /usr/bin/makecert
  805. chmod +x /usr/bin/makecert
  806. echo 'script_to_make_self_signed_certificates' >> $COMPLETION_FILE
  807. }
  808. function configure_email {
  809. if [[ $SYSTEM_TYPE == "writer" || $SYSTEM_TYPE == "cloud" || $SYSTEM_TYPE == "chat" || $SYSTEM_TYPE == "social" ]]; then
  810. return
  811. fi
  812. if grep -Fxq "configure_email" $COMPLETION_FILE; then
  813. return
  814. fi
  815. apt-get -y remove postfix
  816. apt-get -y --force-yes install exim4 sasl2-bin swaks libnet-ssleay-perl procmail
  817. echo 'dc_eximconfig_configtype="internet"' > /etc/exim4/update-exim4.conf.conf
  818. echo "dc_other_hostnames='$DOMAIN_NAME'" >> /etc/exim4/update-exim4.conf.conf
  819. echo "dc_local_interfaces=''" >> /etc/exim4/update-exim4.conf.conf
  820. echo "dc_readhost=''" >> /etc/exim4/update-exim4.conf.conf
  821. echo "dc_relay_domains=''" >> /etc/exim4/update-exim4.conf.conf
  822. echo "dc_minimaldns='false'" >> /etc/exim4/update-exim4.conf.conf
  823. echo "dc_relay_nets='192.168.1.0/24'" >> /etc/exim4/update-exim4.conf.conf
  824. echo "dc_smarthost=''" >> /etc/exim4/update-exim4.conf.conf
  825. echo "CFILEMODE='644'" >> /etc/exim4/update-exim4.conf.conf
  826. echo "dc_use_split_config='false'" >> /etc/exim4/update-exim4.conf.conf
  827. echo "dc_hide_mailname=''" >> /etc/exim4/update-exim4.conf.conf
  828. echo "dc_mailname_in_oh='true'" >> /etc/exim4/update-exim4.conf.conf
  829. echo "dc_localdelivery='maildir_home'" >> /etc/exim4/update-exim4.conf.conf
  830. update-exim4.conf
  831. sed -i "s/START=no/START=yes/g" /etc/default/saslauthd
  832. /etc/init.d/saslauthd start
  833. # make a tls certificate for email
  834. makecert exim
  835. mv /etc/ssl/private/exim.key /etc/exim4
  836. mv /etc/ssl/certs/exim.crt /etc/exim4
  837. mv /etc/ssl/certs/exim.dhparam /etc/exim4
  838. chown root:Debian-exim /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
  839. chmod 640 /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
  840. sed -i '/login_saslauthd_server/,/.endif/ s/# *//' /etc/exim4/exim4.conf.template
  841. sed -i "/.ifdef MAIN_HARDCODE_PRIMARY_HOSTNAME/i\MAIN_HARDCODE_PRIMARY_HOSTNAME = $DOMAIN_NAME\nMAIN_TLS_ENABLE = true" /etc/exim4/exim4.conf.template
  842. sed -i "s|SMTPLISTENEROPTIONS=''|SMTPLISTENEROPTIONS='-oX 465:25:587 -oP /var/run/exim4/exim.pid'|g" /etc/default/exim4
  843. if ! grep -q "tls_on_connect_ports=465" /etc/exim4/exim4.conf.template; then
  844. sed -i '/SSL configuration for exim/i\tls_on_connect_ports=465' /etc/exim4/exim4.conf.template
  845. fi
  846. adduser $MY_USERNAME sasl
  847. addgroup Debian-exim sasl
  848. /etc/init.d/exim4 restart
  849. if [ ! -d /etc/skel/Maildir ]; then
  850. mkdir -m 700 /etc/skel/Maildir
  851. mkdir -m 700 /etc/skel/Maildir/Sent
  852. mkdir -m 700 /etc/skel/Maildir/Sent/tmp
  853. mkdir -m 700 /etc/skel/Maildir/Sent/cur
  854. mkdir -m 700 /etc/skel/Maildir/Sent/new
  855. mkdir -m 700 /etc/skel/Maildir/.learn-spam
  856. mkdir -m 700 /etc/skel/Maildir/.learn-spam/cur
  857. mkdir -m 700 /etc/skel/Maildir/.learn-spam/new
  858. mkdir -m 700 /etc/skel/Maildir/.learn-spam/tmp
  859. mkdir -m 700 /etc/skel/Maildir/.learn-ham
  860. mkdir -m 700 /etc/skel/Maildir/.learn-ham/cur
  861. mkdir -m 700 /etc/skel/Maildir/.learn-ham/new
  862. mkdir -m 700 /etc/skel/Maildir/.learn-ham/tmp
  863. ln -s /etc/skel/Maildir/.learn-spam /etc/skel/Maildir/spam
  864. ln -s /etc/skel/Maildir/.learn-ham /etc/skel/Maildir/ham
  865. fi
  866. if [ ! -d /home/$MY_USERNAME/Maildir ]; then
  867. mkdir -m 700 /home/$MY_USERNAME/Maildir
  868. mkdir -m 700 /home/$MY_USERNAME/Maildir/cur
  869. mkdir -m 700 /home/$MY_USERNAME/Maildir/tmp
  870. mkdir -m 700 /home/$MY_USERNAME/Maildir/new
  871. mkdir -m 700 /home/$MY_USERNAME/Maildir/Sent
  872. mkdir -m 700 /home/$MY_USERNAME/Maildir/Sent/cur
  873. mkdir -m 700 /home/$MY_USERNAME/Maildir/Sent/tmp
  874. mkdir -m 700 /home/$MY_USERNAME/Maildir/Sent/new
  875. mkdir -m 700 /home/$MY_USERNAME/Maildir/.learn-spam
  876. mkdir -m 700 /home/$MY_USERNAME/Maildir/.learn-spam/cur
  877. mkdir -m 700 /home/$MY_USERNAME/Maildir/.learn-spam/new
  878. mkdir -m 700 /home/$MY_USERNAME/Maildir/.learn-spam/tmp
  879. mkdir -m 700 /home/$MY_USERNAME/Maildir/.learn-ham
  880. mkdir -m 700 /home/$MY_USERNAME/Maildir/.learn-ham/cur
  881. mkdir -m 700 /home/$MY_USERNAME/Maildir/.learn-ham/new
  882. mkdir -m 700 /home/$MY_USERNAME/Maildir/.learn-ham/tmp
  883. ln -s /home/$MY_USERNAME/Maildir/.learn-spam /home/$MY_USERNAME/Maildir/spam
  884. ln -s /home/$MY_USERNAME/Maildir/.learn-ham /home/$MY_USERNAME/Maildir/ham
  885. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Maildir
  886. fi
  887. echo 'configure_email' >> $COMPLETION_FILE
  888. }
  889. function spam_filtering {
  890. # NOTE: spamassassin installation currently doesn't work, sa-compile fails with a make error 23/09/2014
  891. if [[ $SYSTEM_TYPE == "writer" || $SYSTEM_TYPE == "cloud" || $SYSTEM_TYPE == "chat" || $SYSTEM_TYPE == "social" ]]; then
  892. return
  893. fi
  894. if grep -Fxq "spam_filtering" $COMPLETION_FILE; then
  895. return
  896. fi
  897. apt-get -y --force-yes install exim4-daemon-heavy
  898. apt-get -y --force-yes install spamassassin
  899. sa-update -v
  900. sed -i 's/ENABLED=0/ENABLED=1/g' /etc/default/spamassassin
  901. sed -i 's/# spamd_address = 127.0.0.1 783/spamd_address = 127.0.0.1 783/g' /etc/exim4/exim4.conf.template
  902. # This configuration is based on https://wiki.debian.org/DebianSpamAssassin
  903. sed -i 's/local_parts = postmaster/local_parts = postmaster:abuse/g' /etc/exim4/conf.d/acl/30_exim4-config_check_rcpt
  904. sed -i '/domains = +local_domains : +relay_to_domains/a\ set acl_m0 = rfcnames' /etc/exim4/conf.d/acl/30_exim4-config_check_rcpt
  905. sed -i 's/accept/accept condition = ${if eq{$acl_m0}{rfcnames} {1}{0}}/g' /etc/exim4/conf.d/acl/40_exim4-config_check_data
  906. echo 'warn message = X-Spam-Score: $spam_score ($spam_bar)' >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
  907. echo ' spam = nobody:true' >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
  908. echo 'warn message = X-Spam-Flag: YES' >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
  909. echo ' spam = nobody' >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
  910. echo 'warn message = X-Spam-Report: $spam_report' >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
  911. echo ' spam = nobody' >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
  912. echo '# reject spam at high scores (> 12)' >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
  913. echo 'deny message = This message scored $spam_score spam points.' >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
  914. echo ' spam = nobody:true' >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
  915. echo ' condition = ${if >{$spam_score_int}{120}{1}{0}}' >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
  916. # procmail configuration
  917. echo 'MAILDIR=$HOME/Maildir' > /home/$MY_USERNAME/.procmailrc
  918. echo 'DEFAULT=$MAILDIR/' >> /home/$MY_USERNAME/.procmailrc
  919. echo 'LOGFILE=$HOME/log/procmail.log' >> /home/$MY_USERNAME/.procmailrc
  920. echo 'LOGABSTRACT=all' >> /home/$MY_USERNAME/.procmailrc
  921. echo '# get spamassassin to check emails' >> /home/$MY_USERNAME/.procmailrc
  922. echo ':0fw: .spamassassin.lock' >> /home/$MY_USERNAME/.procmailrc
  923. echo ' * < 256000' >> /home/$MY_USERNAME/.procmailrc
  924. echo '| spamc' >> /home/$MY_USERNAME/.procmailrc
  925. echo '# strong spam are discarded' >> /home/$MY_USERNAME/.procmailrc
  926. echo ':0' >> /home/$MY_USERNAME/.procmailrc
  927. echo ' * ^X-Spam-Level: \*\*\*\*\*\*' >> /home/$MY_USERNAME/.procmailrc
  928. echo '/dev/null' >> /home/$MY_USERNAME/.procmailrc
  929. echo '# weak spam are kept just in case - clear this out every now and then' >> /home/$MY_USERNAME/.procmailrc
  930. echo ':0' >> /home/$MY_USERNAME/.procmailrc
  931. echo ' * ^X-Spam-Level: \*\*\*\*\*' >> /home/$MY_USERNAME/.procmailrc
  932. echo '.0-spam/' >> /home/$MY_USERNAME/.procmailrc
  933. echo '# otherwise, marginal spam goes here for revision' >> /home/$MY_USERNAME/.procmailrc
  934. echo ':0' >> /home/$MY_USERNAME/.procmailrc
  935. echo ' * ^X-Spam-Level: \*\*' >> /home/$MY_USERNAME/.procmailrc
  936. echo '.spam/' >> /home/$MY_USERNAME/.procmailrc
  937. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.procmailrc
  938. # filtering scripts
  939. echo '#!/bin/bash' > /usr/bin/filterspam
  940. echo 'USERNAME=$1' >> /usr/bin/filterspam
  941. echo 'MAILDIR=/home/$USERNAME/Maildir/.learn-spam' >> /usr/bin/filterspam
  942. echo 'if [ ! -d "$MAILDIR" ]; then' >> /usr/bin/filterspam
  943. echo ' exit' >> /usr/bin/filterspam
  944. echo 'fi' >> /usr/bin/filterspam
  945. echo 'for f in `ls $MAILDIR/cur`' >> /usr/bin/filterspam
  946. echo 'do' >> /usr/bin/filterspam
  947. echo ' spamc -L spam < "$MAILDIR/cur/$f" > /dev/null' >> /usr/bin/filterspam
  948. echo ' rm "$MAILDIR/cur/$f"' >> /usr/bin/filterspam
  949. echo 'done' >> /usr/bin/filterspam
  950. echo 'for f in `ls $MAILDIR/new`' >> /usr/bin/filterspam
  951. echo 'do' >> /usr/bin/filterspam
  952. echo ' spamc -L spam < "$MAILDIR/new/$f" > /dev/null' >> /usr/bin/filterspam
  953. echo ' rm "$MAILDIR/new/$f"' >> /usr/bin/filterspam
  954. echo 'done' >> /usr/bin/filterspam
  955. echo '#!/bin/bash' > /usr/bin/filterham
  956. echo 'USERNAME=$1' >> /usr/bin/filterham
  957. echo 'MAILDIR=/home/$USERNAME/Maildir/.learn-ham' >> /usr/bin/filterham
  958. echo 'if [ ! -d "$MAILDIR" ]; then' >> /usr/bin/filterham
  959. echo ' exit' >> /usr/bin/filterham
  960. echo 'fi' >> /usr/bin/filterham
  961. echo 'for f in `ls $MAILDIR/cur`' >> /usr/bin/filterham
  962. echo 'do' >> /usr/bin/filterham
  963. echo ' spamc -L ham < "$MAILDIR/cur/$f" > /dev/null' >> /usr/bin/filterham
  964. echo ' rm "$MAILDIR/cur/$f"' >> /usr/bin/filterham
  965. echo 'done' >> /usr/bin/filterham
  966. echo 'for f in `ls $MAILDIR/new`' >> /usr/bin/filterham
  967. echo 'do' >> /usr/bin/filterham
  968. echo ' spamc -L ham < "$MAILDIR/new/$f" > /dev/null' >> /usr/bin/filterham
  969. echo ' rm "$MAILDIR/new/$f"' >> /usr/bin/filterham
  970. echo 'done' >> /usr/bin/filterham
  971. if ! grep -q "filterspam" /etc/crontab; then
  972. echo "*/3 * * * * root /usr/bin/timeout 120 /usr/bin/filterspam $MY_USERNAME" >> /etc/crontab
  973. fi
  974. if ! grep -q "filterham" /etc/crontab; then
  975. echo "*/3 * * * * root /usr/bin/timeout 120 /usr/bin/filterham $MY_USERNAME" >> /etc/crontab
  976. fi
  977. chmod 655 /usr/bin/filterspam /usr/bin/filterham
  978. sed -i 's/# use_bayes 1/use_bayes 1/g' /etc/mail/spamassassin/local.cf
  979. sed -i 's/# bayes_auto_learn 1/bayes_auto_learn 1/g' /etc/mail/spamassassin/local.cf
  980. service spamassassin restart
  981. service exim4 restart
  982. service cron restart
  983. echo 'spam_filtering' >> $COMPLETION_FILE
  984. }
  985. function configure_imap {
  986. if [[ $SYSTEM_TYPE == "writer" || $SYSTEM_TYPE == "cloud" || $SYSTEM_TYPE == "chat" || $SYSTEM_TYPE == "social" ]]; then
  987. return
  988. fi
  989. if grep -Fxq "configure_imap" $COMPLETION_FILE; then
  990. return
  991. fi
  992. apt-get -y --force-yes install dovecot-common dovecot-imapd
  993. makecert dovecot
  994. chown root:dovecot /etc/ssl/certs/dovecot.crt
  995. chown root:dovecot /etc/ssl/private/dovecot.key
  996. chown root:dovecot /etc/ssl/private/dovecot.dhparams
  997. sed -i 's|#ssl = yes|ssl = yes|g' /etc/dovecot/conf.d/10-ssl.conf
  998. sed -i 's|ssl_cert = </etc/dovecot/dovecot.pem|ssl_cert = </etc/ssl/certs/dovecot.crt|g' /etc/dovecot/conf.d/10-ssl.conf
  999. sed -i 's|ssl_key = </etc/dovecot/private/dovecot.pem|/etc/ssl/private/dovecot.key|g' /etc/dovecot/conf.d/10-ssl.conf
  1000. sed -i 's|#ssl_dh_parameters_length = 1024|ssl_dh_parameters_length = 1024|g' /etc/dovecot/conf.d/10-ssl.conf
  1001. sed -i 's/#ssl_prefer_server_ciphers = no/ssl_prefer_server_ciphers = yes/g' /etc/dovecot/conf.d/10-ssl.conf
  1002. echo "ssl_cipher_list = 'EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH:+CAMELLIA256:+AES256:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!ECDSA:CAMELLIA256-SHA:AES256-SHA:CAMELLIA128-SHA:AES128-SHA'" >> /etc/dovecot/conf.d/10-ssl.conf
  1003. sed -i 's/#listen = *, ::/listen = */g' /etc/dovecot/dovecot.conf
  1004. sed -i 's/#disable_plaintext_auth = yes/disable_plaintext_auth = no/g' /etc/dovecot/conf.d/10-auth.conf
  1005. sed -i 's/auth_mechanisms = plain/auth_mechanisms = plain login/g' /etc/dovecot/conf.d/10-auth.conf
  1006. sed -i 's|# mail_location = maildir:~/Maildir| mail_location = maildir:~/Maildir:LAYOUT=fs|g' /etc/dovecot/conf.d/10-mail.conf
  1007. echo 'configure_imap' >> $COMPLETION_FILE
  1008. }
  1009. function configure_gpg {
  1010. if [[ $SYSTEM_TYPE == "writer" || $SYSTEM_TYPE == "cloud" || $SYSTEM_TYPE == "chat" || $SYSTEM_TYPE == "social" ]]; then
  1011. return
  1012. fi
  1013. if grep -Fxq "configure_gpg" $COMPLETION_FILE; then
  1014. return
  1015. fi
  1016. apt-get -y --force-yes install gnupg
  1017. if [ ! -d /home/$MY_USERNAME/.gnupg ]; then
  1018. mkdir /home/$MY_USERNAME/.gnupg
  1019. echo 'keyserver hkp://keys.gnupg.net' >> /home/$MY_USERNAME/.gnupg/gpg.conf
  1020. echo 'keyserver-options auto-key-retrieve' >> /home/$MY_USERNAME/.gnupg/gpg.conf
  1021. fi
  1022. sed -i "s|keyserver hkp://keys.gnupg.net|keyserver $GPG_KEYSERVER|g" /home/$MY_USERNAME/.gnupg/gpg.conf
  1023. if ! grep -q "# default preferences" /home/$MY_USERNAME/.gnupg/gpg.conf; then
  1024. echo '' >> /home/$MY_USERNAME/.gnupg/gpg.conf
  1025. echo '# default preferences' >> /home/$MY_USERNAME/.gnupg/gpg.conf
  1026. echo 'personal-digest-preferences SHA256' >> /home/$MY_USERNAME/.gnupg/gpg.conf
  1027. echo 'cert-digest-algo SHA256' >> /home/$MY_USERNAME/.gnupg/gpg.conf
  1028. echo 'default-preference-list SHA512 SHA384 SHA256 SHA224 AES256 AES192 AES CAST5 ZLIB BZIP2 ZIP Uncompressed' >> /home/$MY_USERNAME/.gnupg/gpg.conf
  1029. fi
  1030. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.gnupg
  1031. if [[ $MY_GPG_PUBLIC_KEY && $MY_GPG_PRIVATE_KEY ]]; then
  1032. # use your existing GPG keys which were exported
  1033. if [ ! -f $MY_GPG_PUBLIC_KEY ]; then
  1034. echo "GPG public key file $MY_GPG_PUBLIC_KEY was not found"
  1035. exit 5
  1036. fi
  1037. if [ ! -f $MY_GPG_PRIVATE_KEY ]; then
  1038. echo "GPG private key file $MY_GPG_PRIVATE_KEY was not found"
  1039. exit 6
  1040. fi
  1041. su -c "gpg --import $MY_GPG_PUBLIC_KEY" - $MY_USERNAME
  1042. su -c "gpg --allow-secret-key-import --import $MY_GPG_PRIVATE_KEY" - $MY_USERNAME
  1043. # for security ensure that the private key file doesn't linger around
  1044. shred -zu $MY_GPG_PRIVATE_KEY
  1045. else
  1046. # Generate a GPG key
  1047. echo 'Key-Type: 1' > /home/$MY_USERNAME/gpg-genkey.conf
  1048. echo 'Key-Length: 4096' >> /home/$MY_USERNAME/gpg-genkey.conf
  1049. echo 'Subkey-Type: 1' >> /home/$MY_USERNAME/gpg-genkey.conf
  1050. echo 'Subkey-Length: 4096' >> /home/$MY_USERNAME/gpg-genkey.conf
  1051. echo "Name-Real: $MY_USERNAME@$DOMAIN_NAME" >> /home/$MY_USERNAME/gpg-genkey.conf
  1052. echo "Name-Email: $MY_USERNAME@$DOMAIN_NAME" >> /home/$MY_USERNAME/gpg-genkey.conf
  1053. echo 'Expire-Date: 0' >> /home/$MY_USERNAME/gpg-genkey.conf
  1054. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/gpg-genkey.conf
  1055. su -c "gpg --batch --gen-key /home/$MY_USERNAME/gpg-genkey.conf" - $MY_USERNAME
  1056. shred -zu /home/$MY_USERNAME/gpg-genkey.conf
  1057. MY_GPG_PUBLIC_KEY_ID=$(su -c "gpg --list-keys $DOMAIN_NAME | grep 'pub ' | awk -F ' ' '{print $2}' | awk -F '/' '{print $2}'" - $MY_USERNAME)
  1058. MY_GPG_PUBLIC_KEY=/tmp/public_key.gpg
  1059. su -c "gpg --output $MY_GPG_PUBLIC_KEY --armor --export $MY_GPG_PUBLIC_KEY_ID" - $MY_USERNAME
  1060. fi
  1061. echo 'configure_gpg' >> $COMPLETION_FILE
  1062. }
  1063. function email_client {
  1064. if [[ $SYSTEM_TYPE == "writer" || $SYSTEM_TYPE == "cloud" || $SYSTEM_TYPE == "chat" || $SYSTEM_TYPE == "social" ]]; then
  1065. return
  1066. fi
  1067. if grep -Fxq "email_client" $COMPLETION_FILE; then
  1068. return
  1069. fi
  1070. apt-get -y --force-yes install mutt-patched lynx abook
  1071. if [ ! -d /home/$MY_USERNAME/.mutt ]; then
  1072. mkdir /home/$MY_USERNAME/.mutt
  1073. fi
  1074. echo "text/html; lynx -dump -width=78 -nolist %s | sed ‘s/^ //’; copiousoutput; needsterminal; nametemplate=%s.html" > /home/$MY_USERNAME/.mutt/mailcap
  1075. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.mutt
  1076. echo 'set mbox_type=Maildir' >> /etc/Muttrc
  1077. echo 'set folder="~/Maildir"' >> /etc/Muttrc
  1078. echo 'set mask="!^\\.[^.]"' >> /etc/Muttrc
  1079. echo 'set mbox="~/Maildir"' >> /etc/Muttrc
  1080. echo 'set record="+Sent"' >> /etc/Muttrc
  1081. echo 'set postponed="+Drafts"' >> /etc/Muttrc
  1082. echo 'set trash="+Trash"' >> /etc/Muttrc
  1083. echo 'set spoolfile="~/Maildir"' >> /etc/Muttrc
  1084. echo 'auto_view text/x-vcard text/html text/enriched' >> /etc/Muttrc
  1085. echo 'set editor="emacs"' >> /etc/Muttrc
  1086. echo 'set header_cache="+.cache"' >> /etc/Muttrc
  1087. echo '' >> /etc/Muttrc
  1088. echo 'macro index S "<tag-prefix><save-message>=.learn-spam<enter>" "move to learn-spam"' >> /etc/Muttrc
  1089. echo 'macro pager S "<save-message>=.learn-spam<enter>" "move to learn-spam"' >> /etc/Muttrc
  1090. echo 'macro index H "<tag-prefix><copy-message>=.learn-ham<enter>" "copy to learn-ham"' >> /etc/Muttrc
  1091. echo 'macro pager H "<copy-message>=.learn-ham<enter>" "copy to learn-ham"' >> /etc/Muttrc
  1092. echo '' >> /etc/Muttrc
  1093. echo '# set up the sidebar' >> /etc/Muttrc
  1094. echo 'set sidebar_width=12' >> /etc/Muttrc
  1095. echo 'set sidebar_visible=yes' >> /etc/Muttrc
  1096. echo "set sidebar_delim='|'" >> /etc/Muttrc
  1097. echo 'set sidebar_sort=yes' >> /etc/Muttrc
  1098. echo '' >> /etc/Muttrc
  1099. echo 'set rfc2047_parameters' >> /etc/Muttrc
  1100. echo '' >> /etc/Muttrc
  1101. echo '# Show inbox and sent items' >> /etc/Muttrc
  1102. echo 'mailboxes = =Sent' >> /etc/Muttrc
  1103. echo '' >> /etc/Muttrc
  1104. echo '# Alter these colours as needed for maximum bling' >> /etc/Muttrc
  1105. echo 'color sidebar_new yellow default' >> /etc/Muttrc
  1106. echo 'color normal white default' >> /etc/Muttrc
  1107. echo 'color hdrdefault brightcyan default' >> /etc/Muttrc
  1108. echo 'color signature green default' >> /etc/Muttrc
  1109. echo 'color attachment brightyellow default' >> /etc/Muttrc
  1110. echo 'color quoted green default' >> /etc/Muttrc
  1111. echo 'color quoted1 white default' >> /etc/Muttrc
  1112. echo 'color tilde blue default' >> /etc/Muttrc
  1113. echo '' >> /etc/Muttrc
  1114. echo '# ctrl-n, ctrl-p to select next, prev folder' >> /etc/Muttrc
  1115. echo '# ctrl-o to open selected folder' >> /etc/Muttrc
  1116. echo 'bind index \Cp sidebar-prev' >> /etc/Muttrc
  1117. echo 'bind index \Cn sidebar-next' >> /etc/Muttrc
  1118. echo 'bind index \Co sidebar-open' >> /etc/Muttrc
  1119. echo 'bind pager \Cp sidebar-prev' >> /etc/Muttrc
  1120. echo 'bind pager \Cn sidebar-next' >> /etc/Muttrc
  1121. echo 'bind pager \Co sidebar-open' >> /etc/Muttrc
  1122. echo '' >> /etc/Muttrc
  1123. echo '# ctrl-b toggles sidebar visibility' >> /etc/Muttrc
  1124. echo "macro index,pager \Cb '<enter-command>toggle sidebar_visible<enter><redraw-screen>' 'toggle sidebar'" >> /etc/Muttrc
  1125. echo '' >> /etc/Muttrc
  1126. echo '# esc-m Mark new messages as read' >> /etc/Muttrc
  1127. echo 'macro index <esc>m "T~N<enter>;WNT~O<enter>;WO\CT~T<enter>" "mark all messages read"' >> /etc/Muttrc
  1128. echo '' >> /etc/Muttrc
  1129. echo '# Collapsing threads' >> /etc/Muttrc
  1130. echo 'macro index [ "<collapse-thread>" "collapse/uncollapse thread"' >> /etc/Muttrc
  1131. echo 'macro index ] "<collapse-all>" "collapse/uncollapse all threads"' >> /etc/Muttrc
  1132. echo '' >> /etc/Muttrc
  1133. echo '# threads containing new messages' >> /etc/Muttrc
  1134. echo 'uncolor index "~(~N)"' >> /etc/Muttrc
  1135. echo 'color index brightblue default "~(~N)"' >> /etc/Muttrc
  1136. echo '' >> /etc/Muttrc
  1137. echo '# new messages themselves' >> /etc/Muttrc
  1138. echo 'uncolor index "~N"' >> /etc/Muttrc
  1139. echo 'color index brightyellow default "~N"' >> /etc/Muttrc
  1140. echo '' >> /etc/Muttrc
  1141. echo '# GPG/PGP integration' >> /etc/Muttrc
  1142. echo '# this set the number of seconds to keep in memory the passphrase used to encrypt/sign' >> /etc/Muttrc
  1143. echo 'set pgp_timeout=60' >> /etc/Muttrc
  1144. echo '' >> /etc/Muttrc
  1145. echo '# automatically sign and encrypt with PGP/MIME' >> /etc/Muttrc
  1146. echo 'set pgp_autosign # autosign all outgoing mails' >> /etc/Muttrc
  1147. echo 'set pgp_autoencrypt # Try to encrypt automatically' >> /etc/Muttrc
  1148. echo 'set pgp_replyencrypt # autocrypt replies to crypted' >> /etc/Muttrc
  1149. echo 'set pgp_replysign # autosign replies to signed' >> /etc/Muttrc
  1150. echo 'set pgp_auto_decode=yes # decode attachments' >> /etc/Muttrc
  1151. echo 'set fcc_clear # Keep cleartext copy of sent encrypted mail' >> /etc/Muttrc
  1152. echo 'unset smime_is_default' >> /etc/Muttrc
  1153. echo '' >> /etc/Muttrc
  1154. echo 'set alias_file=~/.mutt-alias' >> /etc/Muttrc
  1155. echo 'source ~/.mutt-alias' >> /etc/Muttrc
  1156. echo 'set query_command= "abook --mutt-query \"%s\""' >> /etc/Muttrc
  1157. echo 'macro index,pager A "<pipe-message>abook --add-email-quiet<return>" "add the sender address to abook"' >> /etc/Muttrc
  1158. cp -f /etc/Muttrc /home/$MY_USERNAME/.muttrc
  1159. touch /home/$MY_USERNAME/.mutt-alias
  1160. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.muttrc
  1161. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.mutt-alias
  1162. echo 'email_client' >> $COMPLETION_FILE
  1163. }
  1164. function folders_for_mailing_lists {
  1165. if [[ $SYSTEM_TYPE == "writer" || $SYSTEM_TYPE == "cloud" || $SYSTEM_TYPE == "chat" || $SYSTEM_TYPE == "social" ]]; then
  1166. return
  1167. fi
  1168. if grep -Fxq "folders_for_mailing_lists" $COMPLETION_FILE; then
  1169. return
  1170. fi
  1171. echo '#!/bin/bash' > /usr/bin/mailinglistrule
  1172. echo 'MYUSERNAME=$1' >> /usr/bin/mailinglistrule
  1173. echo 'MAILINGLIST=$2' >> /usr/bin/mailinglistrule
  1174. echo 'SUBJECTTAG=$3' >> /usr/bin/mailinglistrule
  1175. echo 'MUTTRC=/home/$MYUSERNAME/.muttrc' >> /usr/bin/mailinglistrule
  1176. echo 'PM=/home/$MYUSERNAME/.procmailrc' >> /usr/bin/mailinglistrule
  1177. echo 'LISTDIR=/home/$MYUSERNAME/Maildir/$MAILINGLIST' >> /usr/bin/mailinglistrule
  1178. echo 'if ! [[ $MYUSERNAME && $MAILINGLIST && $SUBJECTTAG ]]; then' >> /usr/bin/mailinglistrule
  1179. echo ' echo "mailinglistsrule [user name] [mailing list name] [subject tag]"' >> /usr/bin/mailinglistrule
  1180. echo ' exit 1' >> /usr/bin/mailinglistrule
  1181. echo 'fi' >> /usr/bin/mailinglistrule
  1182. echo 'if [ ! -d "$LISTDIR" ]; then' >> /usr/bin/mailinglistrule
  1183. echo ' mkdir -m 700 $LISTDIR' >> /usr/bin/mailinglistrule
  1184. echo ' mkdir -m 700 $LISTDIR/tmp' >> /usr/bin/mailinglistrule
  1185. echo ' mkdir -m 700 $LISTDIR/new' >> /usr/bin/mailinglistrule
  1186. echo ' mkdir -m 700 $LISTDIR/cur' >> /usr/bin/mailinglistrule
  1187. echo 'fi' >> /usr/bin/mailinglistrule
  1188. echo 'chown -R $MYUSERNAME:$MYUSERNAME $LISTDIR' >> /usr/bin/mailinglistrule
  1189. echo 'echo "" >> $PM' >> /usr/bin/mailinglistrule
  1190. echo 'echo ":0" >> $PM' >> /usr/bin/mailinglistrule
  1191. echo 'echo " * ^Subject:.*()\[$SUBJECTTAG\]" >> $PM' >> /usr/bin/mailinglistrule
  1192. echo 'echo "$LISTDIR/new" >> $PM' >> /usr/bin/mailinglistrule
  1193. echo 'chown $MYUSERNAME:$MYUSERNAME $PM' >> /usr/bin/mailinglistrule
  1194. echo 'if [ ! -f "$MUTTRC" ]; then' >> /usr/bin/mailinglistrule
  1195. echo ' cp /etc/Muttrc $MUTTRC' >> /usr/bin/mailinglistrule
  1196. echo ' chown $MYUSERNAME:$MYUSERNAME $MUTTRC' >> /usr/bin/mailinglistrule
  1197. echo 'fi' >> /usr/bin/mailinglistrule
  1198. echo 'PROCMAILLOG=/home/$MYUSERNAME/log' >> /usr/bin/mailinglistrule
  1199. echo 'if [ ! -d $PROCMAILLOG ]; then' >> /usr/bin/mailinglistrule
  1200. echo ' mkdir $PROCMAILLOG' >> /usr/bin/mailinglistrule
  1201. echo ' chown -R $MYUSERNAME:$MYUSERNAME $PROCMAILLOG' >> /usr/bin/mailinglistrule
  1202. echo 'fi' >> /usr/bin/mailinglistrule
  1203. echo 'MUTT_MAILBOXES=$(grep "mailboxes =" $MUTTRC)' >> /usr/bin/mailinglistrule
  1204. echo 'if [[ $MUTT_MAILBOXES != *$MAILINGLIST* ]]; then' >> /usr/bin/mailinglistrule
  1205. echo ' sed -i "s|$MUTT_MAILBOXES|$MUTT_MAILBOXES =$MAILINGLIST|g" $MUTTRC' >> /usr/bin/mailinglistrule
  1206. echo ' chown $MYUSERNAME:$MYUSERNAME $MUTTRC' >> /usr/bin/mailinglistrule
  1207. echo 'fi' >> /usr/bin/mailinglistrule
  1208. chmod +x /usr/bin/mailinglistrule
  1209. echo 'folders_for_mailing_lists' >> $COMPLETION_FILE
  1210. }
  1211. function folders_for_email_addresses {
  1212. if [[ $SYSTEM_TYPE == "writer" || $SYSTEM_TYPE == "cloud" || $SYSTEM_TYPE == "chat" || $SYSTEM_TYPE == "social" ]]; then
  1213. return
  1214. fi
  1215. if grep -Fxq "folders_for_email_addresses" $COMPLETION_FILE; then
  1216. return
  1217. fi
  1218. echo '#!/bin/bash' > /usr/bin/emailrule
  1219. echo 'MYUSERNAME=$1' >> /usr/bin/emailrule
  1220. echo 'EMAILADDRESS=$2' >> /usr/bin/emailrule
  1221. echo 'MAILINGLIST=$3' >> /usr/bin/emailrule
  1222. echo 'MUTTRC=/home/$MYUSERNAME/.muttrc' >> /usr/bin/emailrule
  1223. echo 'PM=/home/$MYUSERNAME/.procmailrc' >> /usr/bin/emailrule
  1224. echo 'LISTDIR=/home/$MYUSERNAME/Maildir/$MAILINGLIST' >> /usr/bin/emailrule
  1225. echo 'if ! [[ $MYUSERNAME && $EMAILADDRESS && $MAILINGLIST ]]; then' >> /usr/bin/emailrule
  1226. echo ' echo "emailrule [user name] [email address] [mailing list name]"' >> /usr/bin/emailrule
  1227. echo ' exit 1' >> /usr/bin/emailrule
  1228. echo 'fi' >> /usr/bin/emailrule
  1229. echo 'if [ ! -d "$LISTDIR" ]; then' >> /usr/bin/emailrule
  1230. echo ' mkdir -m 700 $LISTDIR' >> /usr/bin/emailrule
  1231. echo ' mkdir -m 700 $LISTDIR/tmp' >> /usr/bin/emailrule
  1232. echo ' mkdir -m 700 $LISTDIR/new' >> /usr/bin/emailrule
  1233. echo ' mkdir -m 700 $LISTDIR/cur' >> /usr/bin/emailrule
  1234. echo 'fi' >> /usr/bin/emailrule
  1235. echo 'chown -R $MYUSERNAME:$MYUSERNAME $LISTDIR' >> /usr/bin/emailrule
  1236. echo 'echo "" >> $PM' >> /usr/bin/emailrule
  1237. echo 'echo ":0" >> $PM' >> /usr/bin/emailrule
  1238. echo 'echo " * ^From: $EMAILADDRESS" >> $PM' >> /usr/bin/emailrule
  1239. echo 'echo "$LISTDIR/new" >> $PM' >> /usr/bin/emailrule
  1240. echo 'chown $MYUSERNAME:$MYUSERNAME $PM' >> /usr/bin/emailrule
  1241. echo 'if [ ! -f "$MUTTRC" ]; then' >> /usr/bin/emailrule
  1242. echo ' cp /etc/Muttrc $MUTTRC' >> /usr/bin/emailrule
  1243. echo ' chown $MYUSERNAME:$MYUSERNAME $MUTTRC' >> /usr/bin/emailrule
  1244. echo 'fi' >> /usr/bin/emailrule
  1245. echo 'PROCMAILLOG=/home/$MYUSERNAME/log' >> /usr/bin/emailrule
  1246. echo 'if [ ! -d $PROCMAILLOG ]; then' >> /usr/bin/emailrule
  1247. echo ' mkdir $PROCMAILLOG' >> /usr/bin/emailrule
  1248. echo ' chown -R $MYUSERNAME:$MYUSERNAME $PROCMAILLOG' >> /usr/bin/emailrule
  1249. echo 'fi' >> /usr/bin/emailrule
  1250. echo 'MUTT_MAILBOXES=$(grep "mailboxes =" $MUTTRC)' >> /usr/bin/emailrule
  1251. echo 'if [[ $MUTT_MAILBOXES != *$MAILINGLIST* ]]; then' >> /usr/bin/emailrule
  1252. echo ' sed -i "s|$MUTT_MAILBOXES|$MUTT_MAILBOXES =$MAILINGLIST|g" $MUTTRC' >> /usr/bin/emailrule
  1253. echo ' chown $MYUSERNAME:$MYUSERNAME $MUTTRC' >> /usr/bin/emailrule
  1254. echo 'fi' >> /usr/bin/emailrule
  1255. chmod +x /usr/bin/emailrule
  1256. echo 'folders_for_email_addresses' >> $COMPLETION_FILE
  1257. }
  1258. function dynamic_dns_freedns {
  1259. if grep -Fxq "dynamic_dns_freedns" $COMPLETION_FILE; then
  1260. return
  1261. fi
  1262. echo '#!/bin/bash' > /usr/bin/dynamicdns
  1263. echo '# subdomain name 1' >> /usr/bin/dynamicdns
  1264. echo "wget -O - https://freedns.afraid.org/dynamic/update.php?$FREEDNS_SUBDOMAIN_CODE== >> /dev/null 2>&1" >> /usr/bin/dynamicdns
  1265. echo '# add any other subdomains below' >> /usr/bin/dynamicdns
  1266. chmod 600 /usr/bin/dynamicdns
  1267. chmod +x /usr/bin/dynamicdns
  1268. if ! grep -q "dynamicdns" /etc/crontab; then
  1269. sed -i '/# m h dom mon dow user command/a\*/5 * * * * root /usr/bin/timeout 240 /usr/bin/dynamicdns' /etc/crontab
  1270. fi
  1271. service cron restart
  1272. echo 'dynamic_dns_freedns' >> $COMPLETION_FILE
  1273. }
  1274. function create_private_mailing_list {
  1275. if [[ $SYSTEM_TYPE == "writer" || $SYSTEM_TYPE == "cloud" || $SYSTEM_TYPE == "chat" || $SYSTEM_TYPE == "social" ]]; then
  1276. return
  1277. fi
  1278. # This installation doesn't work, results in ruby errors
  1279. # There is currently no schleuder package for Debian jessie
  1280. if grep -Fxq "create_private_mailing_list" $COMPLETION_FILE; then
  1281. return
  1282. fi
  1283. if [ ! $PRIVATE_MAILING_LIST ]; then
  1284. return
  1285. fi
  1286. if [ $PRIVATE_MAILING_LIST == $MY_USERNAME ]; then
  1287. echo 'The name of the private mailing list should not be the'
  1288. echo 'same as your username'
  1289. exit 10
  1290. fi
  1291. if [ ! $MY_GPG_PUBLIC_KEY ]; then
  1292. echo 'To create a private mailing list you need to specify a file'
  1293. echo 'containing your exported GPG key within MY_GPG_PUBLIC_KEY at'
  1294. echo 'the top of the script'
  1295. exit 11
  1296. fi
  1297. apt-get -y --force-yes install ruby ruby-dev ruby-gpgme libgpgme11-dev libmagic-dev
  1298. gem install schleuder
  1299. schleuder-fix-gem-dependencies
  1300. schleuder-init-setup --gem
  1301. # NOTE: this is version number sensitive and so might need changing
  1302. ln -s /var/lib/gems/2.1.0/gems/schleuder-2.2.4 /var/lib/schleuder
  1303. sed -i 's/#smtp_port: 25/smtp_port: 465/g' /etc/schleuder/schleuder.conf
  1304. sed -i 's/#superadminaddr: root@localhost/superadminaddr: root@localhost' /etc/schleuder/schleuder.conf
  1305. schleuder-newlist $PRIVATE_MAILING_LIST@$DOMAIN_NAME -realname "$PRIVATE_MAILING_LIST" -adminaddress $MY_USERNAME@$DOMAIN_NAME -initmember $MY_USERNAME@$DOMAIN_NAME -initmemberkey $MY_GPG_PUBLIC_KEY -nointeractive
  1306. emailrule $MY_USERNAME $PRIVATE_MAILING_LIST@$DOMAIN_NAME $PRIVATE_MAILING_LIST
  1307. echo 'schleuder:' > /etc/exim4/conf.d/router/550_exim4-config_schleuder
  1308. echo ' debug_print = "R: schleuder for $local_part@$domain"' >> /etc/exim4/conf.d/router/550_exim4-config_schleuder
  1309. echo ' driver = accept' >> /etc/exim4/conf.d/router/550_exim4-config_schleuder
  1310. echo ' local_part_suffix_optional' >> /etc/exim4/conf.d/router/550_exim4-config_schleuder
  1311. echo ' local_part_suffix = +* : -bounce : -sendkey' >> /etc/exim4/conf.d/router/550_exim4-config_schleuder
  1312. echo ' domains = +local_domains' >> /etc/exim4/conf.d/router/550_exim4-config_schleuder
  1313. echo ' user = schleuder' >> /etc/exim4/conf.d/router/550_exim4-config_schleuder
  1314. echo ' group = schleuder' >> /etc/exim4/conf.d/router/550_exim4-config_schleuder
  1315. echo ' require_files = schleuder:+/var/lib/schleuder/$domain/${local_part}' >> /etc/exim4/conf.d/router/550_exim4-config_schleuder
  1316. echo ' transport = schleuder_transport' >> /etc/exim4/conf.d/router/550_exim4-config_schleuder
  1317. echo 'schleuder_transport:' > /etc/exim4/conf.d/transport/30_exim4-config_schleuder
  1318. echo ' debug_print = "T: schleuder_transport for $local_part@$domain"' >> /etc/exim4/conf.d/transport/30_exim4-config_schleuder
  1319. echo ' driver = pipe' >> /etc/exim4/conf.d/transport/30_exim4-config_schleuder
  1320. echo ' home_directory = "/var/lib/schleuder/$domain/$local_part"' >> /etc/exim4/conf.d/transport/30_exim4-config_schleuder
  1321. echo ' command = "/usr/bin/schleuder $local_part@$domain"' >> /etc/exim4/conf.d/transport/30_exim4-config_schleuder
  1322. chown -R schleuder:schleuder /var/lib/schleuder
  1323. update-exim4.conf.template -r
  1324. update-exim4.conf
  1325. service exim4 restart
  1326. useradd -d /var/schleuderlists -s /bin/false schleuder
  1327. adduser Debian-exim schleuder
  1328. usermod -a -G mail schleuder
  1329. #exim -d -bt $PRIVATE_MAILING_LIST@$DOMAIN_NAME
  1330. echo 'create_private_mailing_list' >> $COMPLETION_FILE
  1331. }
  1332. function import_email {
  1333. if [[ $SYSTEM_TYPE == "writer" || $SYSTEM_TYPE == "cloud" || $SYSTEM_TYPE == "chat" || $SYSTEM_TYPE == "social" ]]; then
  1334. return
  1335. fi
  1336. EMAIL_COMPLETE_MSG=' *** Freedombone mailbox installation is complete ***'
  1337. if grep -Fxq "import_email" $COMPLETION_FILE; then
  1338. if [[ $SYSTEM_TYPE == "email" || $SYSTEM_TYPE == "mailbox" ]]; then
  1339. echo $EMAIL_COMPLETE_MSG
  1340. if [ -d /media/usb ]; then
  1341. umount /media/usb
  1342. rm -rf /media/usb
  1343. echo ' You can now remove the USB drive'
  1344. fi
  1345. exit 0
  1346. fi
  1347. return
  1348. fi
  1349. if [ $IMPORT_MAILDIR ]; then
  1350. if [ -d $IMPORT_MAILDIR ]; then
  1351. echo 'Transfering email files'
  1352. cp -r $IMPORT_MAILDIR /home/$MY_USERNAME
  1353. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Maildir
  1354. else
  1355. echo "Email import directory $IMPORT_MAILDIR not found"
  1356. exit 9
  1357. fi
  1358. fi
  1359. echo 'import_email' >> $COMPLETION_FILE
  1360. if [[ $SYSTEM_TYPE == "email" || $SYSTEM_TYPE == "mailbox" ]]; then
  1361. apt-get -y --force-yes autoremove
  1362. # unmount any attached usb drive
  1363. echo ''
  1364. echo $EMAIL_COMPLETE_MSG
  1365. echo ''
  1366. if [ -d /media/usb ]; then
  1367. umount /media/usb
  1368. rm -rf /media/usb
  1369. echo ' You can now remove the USB drive'
  1370. fi
  1371. exit 0
  1372. fi
  1373. }
  1374. function install_web_server {
  1375. if [[ $SYSTEM_TYPE == "chat" ]]; then
  1376. return
  1377. fi
  1378. if grep -Fxq "install_web_server" $COMPLETION_FILE; then
  1379. return
  1380. fi
  1381. # remove apache
  1382. apt-get -y remove --purge apache2
  1383. if [ -d /etc/apache2 ]; then
  1384. rm -rf /etc/apache2
  1385. fi
  1386. # install nginx
  1387. apt-get -y --force-yes install nginx php5-fpm git
  1388. # install a script to easily enable and disable nginx virtual hosts
  1389. if [ ! -d $INSTALL_DIR ]; then
  1390. mkdir $INSTALL_DIR
  1391. fi
  1392. cd $INSTALL_DIR
  1393. git clone https://github.com/perusio/nginx_ensite
  1394. cd $INSTALL_DIR/nginx_ensite
  1395. cp nginx_* /usr/sbin
  1396. nginx_dissite default
  1397. echo 'install_web_server' >> $COMPLETION_FILE
  1398. }
  1399. function install_owncloud {
  1400. if [[ $SYSTEM_TYPE == "writer" || $SYSTEM_TYPE == "email" || $SYSTEM_TYPE == "mailbox" || $SYSTEM_TYPE == "chat" || $SYSTEM_TYPE == "social" ]]; then
  1401. return
  1402. fi
  1403. OWNCLOUD_COMPLETION_MSG1=" *** Freedombone $SYSTEM_TYPE is now installed ***"
  1404. OWNCLOUD_COMPLETION_MSG2="Open $OWNCLOUD_DOMAIN_NAME in a web browser to complete the setup"
  1405. if grep -Fxq "install_owncloud" $COMPLETION_FILE; then
  1406. if [[ $SYSTEM_TYPE == "cloud" ]]; then
  1407. # unmount any attached usb drive
  1408. if [ -d /media/usb ]; then
  1409. umount /media/usb
  1410. rm -rf /media/usb
  1411. fi
  1412. echo ''
  1413. echo $OWNCLOUD_COMPLETION_MSG1
  1414. echo $OWNCLOUD_COMPLETION_MSG2
  1415. exit 0
  1416. fi
  1417. return
  1418. fi
  1419. # if this is exclusively a cloud setup
  1420. if [[ $SYSTEM_TYPE == "cloud" ]]; then
  1421. OWNCLOUD_DOMAIN_NAME=$DOMAIN_NAME
  1422. OWNCLOUD_FREEDNS_SUBDOMAIN_CODE=$FREEDNS_SUBDOMAIN_CODE
  1423. fi
  1424. if [ ! $OWNCLOUD_DOMAIN_NAME ]; then
  1425. return
  1426. fi
  1427. if ! [[ $SYSTEM_TYPE == "cloud" ]]; then
  1428. if [ ! $SYSTEM_TYPE ]; then
  1429. return
  1430. fi
  1431. fi
  1432. apt-get -y --force-yes install php5 php5-gd php-xml-parser php5-intl wget
  1433. apt-get -y --force-yes install php5-sqlite php5-mysql smbclient curl libcurl3 php5-curl bzip2
  1434. if [ ! -d /var/www/$OWNCLOUD_DOMAIN_NAME ]; then
  1435. mkdir /var/www/$OWNCLOUD_DOMAIN_NAME
  1436. mkdir /var/www/$OWNCLOUD_DOMAIN_NAME/htdocs
  1437. fi
  1438. echo 'server {' > /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1439. echo ' listen 80;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1440. echo " server_name $OWNCLOUD_DOMAIN_NAME;" >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1441. echo ' rewrite ^ https://$server_name$request_uri? permanent;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1442. echo '}' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1443. echo 'server {' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1444. echo ' listen 443 ssl;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1445. echo " root /var/www/$OWNCLOUD_DOMAIN_NAME/htdocs;" >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1446. echo " server_name $OWNCLOUD_DOMAIN_NAME;" >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1447. echo ' ssl on;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1448. echo " ssl_certificate /etc/ssl/certs/$OWNCLOUD_DOMAIN_NAME.crt;" >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1449. echo " ssl_certificate_key /etc/ssl/private/$OWNCLOUD_DOMAIN_NAME.key;" >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1450. echo " ssl_dhparam /etc/ssl/certs/$OWNCLOUD_DOMAIN_NAME.dhparam;" >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1451. echo ' ssl_session_timeout 5m;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1452. echo ' ssl_prefer_server_ciphers on;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1453. echo ' ssl_protocols TLSv1 TLSv1.1 TLSv1.2; # not possible to do exclusive' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1454. echo " ssl_ciphers 'EDH+CAMELLIA:EDH+aRSA:EECDH+aRSA+AESGCM:EECDH+aRSA+SHA384:EECDH+aRSA+SHA256:EECDH:+CAMELLIA256:+AES256:+CAMELLIA128:+AES128:+SSLv3:!aNULL:!eNULL:!LOW:!3DES:!MD5:!EXP:!PSK:!DSS:!RC4:!SEED:!ECDSA:CAMELLIA256-SHA:AES256-SHA:CAMELLIA128-SHA:AES128-SHA';" >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1455. echo ' add_header X-Frame-Options DENY;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1456. echo ' add_header X-Content-Type-Options nosniff;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1457. echo ' add_header Strict-Transport-Security max-age=15768000;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1458. echo ' # if you want to be able to access the site via HTTP' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1459. echo ' # then replace the above with the following:' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1460. echo ' # add_header Strict-Transport-Security "max-age=0;";' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1461. echo " # make sure webfinger and other well known services aren't blocked" >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1462. echo ' # by denying dot files and rewrite request to the front controller' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1463. echo ' location ^~ /.well-known/ {' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1464. echo ' allow all;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1465. echo ' rewrite ^/(.*) /index.php?q=$uri&$args last;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1466. echo ' }' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1467. echo ' client_max_body_size 10G; # set max upload size' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1468. echo ' client_body_buffer_size 128k;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1469. echo ' fastcgi_buffers 64 4K;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1470. echo ' rewrite ^/caldav(.*)$ /remote.php/caldav$1 redirect;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1471. echo ' rewrite ^/carddav(.*)$ /remote.php/carddav$1 redirect;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1472. echo ' rewrite ^/webdav(.*)$ /remote.php/webdav$1 redirect;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1473. echo ' index index.php;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1474. echo ' error_page 403 /core/templates/403.php;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1475. echo ' error_page 404 /core/templates/404.php;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1476. echo ' location = /robots.txt {' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1477. echo ' allow all;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1478. echo ' log_not_found off;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1479. echo ' access_log off;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1480. echo ' }' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1481. echo ' location ~ ^/(data|config|\.ht|db_structure\.xml|README) {' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1482. echo ' deny all;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1483. echo ' }' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1484. echo ' location / {' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1485. echo ' # The following 2 rules are only needed with webfinger' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1486. echo ' rewrite ^/.well-known/host-meta /public.php?service=host-meta last;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1487. echo ' rewrite ^/.well-known/host-meta.json /public.php?service=host-meta-json last;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1488. echo ' rewrite ^/.well-known/carddav /remote.php/carddav/ redirect;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1489. echo ' rewrite ^/.well-known/caldav /remote.php/caldav/ redirect;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1490. echo ' rewrite ^(/core/doc/[^\/]+/)$ $1/index.html;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1491. echo ' try_files $uri $uri/ index.php;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1492. echo ' }' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1493. echo ' location ~ ^(.+?\.php)(/.*)?$ {' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1494. echo ' try_files $1 =404;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1495. echo ' fastcgi_split_path_info ^(.+\.php)(/.+)$;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1496. echo ' fastcgi_pass unix:/var/run/php5-fpm.sock;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1497. echo ' fastcgi_index index.php;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1498. echo ' include fastcgi_params;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1499. echo ' fastcgi_param SCRIPT_FILENAME $document_root$1;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1500. echo ' fastcgi_param PATH_INFO $2;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1501. echo ' fastcgi_param HTTPS on;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1502. echo ' }' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1503. echo ' # Optional: set long EXPIRES header on static assets' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1504. echo ' location ~* ^.+\.(jpg|jpeg|gif|bmp|ico|png|css|js|swf)$ {' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1505. echo ' expires 30d;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1506. echo " # Optional: Don't log access to assets" >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1507. echo ' access_log off;' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1508. echo ' }' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1509. echo '}' >> /etc/nginx/sites-available/$OWNCLOUD_DOMAIN_NAME
  1510. sed -i "s/memory_limit = 128M/memory_limit = $MAX_PHP_MEMORYM/g" /etc/php5/fpm/php.ini
  1511. sed -i 's/;cgi.fix_pathinfo=1/cgi.fix_pathinfo=0/g' /etc/php5/fpm/php.ini
  1512. sed -i "s/memory_limit = -1/memory_limit = $MAX_PHP_MEMORYM/g" /etc/php5/cli/php.ini
  1513. sed -i "s/upload_max_filesize = 2M/upload_max_filesize = 50M/g" /etc/php5/fpm/php.ini
  1514. sed -i "s/post_max_size = 8M/post_max_size = 50M/g" /etc/php5/fpm/php.ini
  1515. sed -i "s/memory_limit = /memory_limit = $MAX_PHP_MEMORYM/g" /etc/php5/cli/php.ini
  1516. if [ ! -f /etc/ssl/private/$OWNCLOUD_DOMAIN_NAME.key ]; then
  1517. makecert $OWNCLOUD_DOMAIN_NAME
  1518. fi
  1519. # download owncloud
  1520. cd $INSTALL_DIR
  1521. if [ ! -f $INSTALL_DIR/$OWNCLOUD_ARCHIVE ]; then
  1522. wget $OWNCLOUD_DOWNLOAD
  1523. fi
  1524. if [ ! -f $INSTALL_DIR/$OWNCLOUD_ARCHIVE ]; then
  1525. echo 'Owncloud could not be downloaded. Check that it exists at '
  1526. echo $OWNCLOUD_DOWNLOAD
  1527. echo 'And if neccessary update the version number and hash within this script'
  1528. exit 18
  1529. fi
  1530. # Check that the hash is correct
  1531. CHECKSUM=$(sha256sum $OWNCLOUD_ARCHIVE | awk -F ' ' '{print $1}')
  1532. if [[ $CHECKSUM != $OWNCLOUD_HASH ]]; then
  1533. echo 'The sha256 hash of the owncloud download is incorrect. Possibly the file may have been tampered with. Check the hash on the Owncloud web site.'
  1534. exit 19
  1535. fi
  1536. tar -xjf $OWNCLOUD_ARCHIVE
  1537. echo 'Copying files...'
  1538. cp -r owncloud/* /var/www/$OWNCLOUD_DOMAIN_NAME/htdocs
  1539. chown -R www-data:www-data /var/www/$OWNCLOUD_DOMAIN_NAME/htdocs/apps
  1540. chown -R www-data:www-data /var/www/$OWNCLOUD_DOMAIN_NAME/htdocs/config
  1541. chown www-data:www-data /var/www/$OWNCLOUD_DOMAIN_NAME/htdocs
  1542. nginx_ensite $OWNCLOUD_DOMAIN_NAME
  1543. service php5-fpm restart
  1544. service nginx restart
  1545. # update the dynamic DNS
  1546. if [[ $OWNCLOUD_FREEDNS_SUBDOMAIN_CODE != $FREEDNS_SUBDOMAIN_CODE ]]; then
  1547. if ! grep -q "$OWNCLOUD_DOMAIN_NAME" /usr/bin/dynamicdns; then
  1548. echo "# $OWNCLOUD_DOMAIN_NAME" >> /usr/bin/dynamicdns
  1549. echo "wget -O - https://freedns.afraid.org/dynamic/update.php?$OWNCLOUD_FREEDNS_SUBDOMAIN_CODE== >> /dev/null 2>&1" >> /usr/bin/dynamicdns
  1550. fi
  1551. fi
  1552. echo 'install_owncloud' >> $COMPLETION_FILE
  1553. if [[ $SYSTEM_TYPE == "cloud" ]]; then
  1554. # unmount any attached usb drive
  1555. if [ -d /media/usb ]; then
  1556. umount /media/usb
  1557. rm -rf /media/usb
  1558. fi
  1559. echo ''
  1560. echo $OWNCLOUD_COMPLETION_MSG1
  1561. echo $OWNCLOUD_COMPLETION_MSG2
  1562. exit 0
  1563. fi
  1564. }
  1565. function install_xmpp {
  1566. if [[ $SYSTEM_TYPE == "writer" || $SYSTEM_TYPE == "email" || $SYSTEM_TYPE == "mailbox" || $SYSTEM_TYPE == "cloud" || $SYSTEM_TYPE == "social" ]]; then
  1567. return
  1568. fi
  1569. if grep -Fxq "install_xmpp" $COMPLETION_FILE; then
  1570. return
  1571. fi
  1572. apt-get -y --force-yes install prosody
  1573. makecert xmpp
  1574. chown prosody:prosody /etc/ssl/private/xmpp.key
  1575. chown prosody:prosody /etc/ssl/certs/xmpp.*
  1576. cp -a /etc/prosody/conf.avail/example.com.cfg.lua /etc/prosody/conf.avail/xmpp.cfg.lua
  1577. sed -i 's|/etc/prosody/certs/example.com.key|/etc/ssl/private/xmpp.key|g' /etc/prosody/conf.avail/xmpp.cfg.lua
  1578. sed -i 's|/etc/prosody/certs/example.com.crt|/etc/ssl/certs/xmpp.crt|g' /etc/prosody/conf.avail/xmpp.cfg.lua
  1579. if ! grep -q "xmpp.dhparam" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  1580. sed -i '/certificate =/a\ dhparam = "/etc/ssl/certs/xmpp.dhparam";' /etc/prosody/conf.avail/xmpp.cfg.lua
  1581. fi
  1582. sed -i "s/example.com/$DOMAIN_NAME/g" /etc/prosody/conf.avail/xmpp.cfg.lua
  1583. sed -i 's/enabled = false -- Remove this line to enable this host//g' /etc/prosody/conf.avail/xmpp.cfg.lua
  1584. if ! grep -q "modules_enabled" /etc/prosody/conf.avail/xmpp.cfg.lua; then
  1585. echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  1586. echo 'modules_enabled = {' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  1587. echo ' "bosh"; -- Enable mod_bosh' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  1588. echo ' "tls"; -- Enable mod_tls' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  1589. echo '}' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  1590. echo '' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  1591. echo 'c2s_require_encryption = true' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  1592. echo 's2s_require_encryption = true' >> /etc/prosody/conf.avail/xmpp.cfg.lua
  1593. fi
  1594. ln -sf /etc/prosody/conf.avail/xmpp.cfg.lua /etc/prosody/conf.d/xmpp.cfg.lua
  1595. sed -i 's|/etc/prosody/certs/localhost.key|/etc/ssl/private/xmpp.key|g' /etc/prosody/prosody.cfg.lua
  1596. sed -i 's|/etc/prosody/certs/localhost.crt|/etc/ssl/certs/xmpp.crt|g' /etc/prosody/prosody.cfg.lua
  1597. if ! grep -q "xmpp.dhparam" /etc/prosody/prosody.cfg.lua; then
  1598. sed -i '/certificate =/a\ dhparam = "/etc/ssl/certs/xmpp.dhparam";' /etc/prosody/prosody.cfg.lua
  1599. fi
  1600. sed -i 's/c2s_require_encryption = false/c2s_require_encryption = true/g' /etc/prosody/prosody.cfg.lua
  1601. if ! grep -q "s2s_require_encryption" /etc/prosody/prosody.cfg.lua; then
  1602. sed -i '/c2s_require_encryption/a\s2s_require_encryption = true' /etc/prosody/prosody.cfg.lua
  1603. fi
  1604. sed -i 's/--"bosh";/"bosh";/g' /etc/prosody/prosody.cfg.lua
  1605. prosodyctl adduser $MY_USERNAME@$DOMAIN_NAME
  1606. service prosody restart
  1607. echo 'install_xmpp' >> $COMPLETION_FILE
  1608. }
  1609. function install_final {
  1610. if grep -Fxq "install_final" $COMPLETION_FILE; then
  1611. return
  1612. fi
  1613. # unmount any attached usb drive
  1614. if [ -d /media/usb ]; then
  1615. umount /media/usb
  1616. rm -rf /media/usb
  1617. fi
  1618. apt-get -y --force-yes autoremove
  1619. echo 'install_final' >> $COMPLETION_FILE
  1620. echo ''
  1621. echo ' *** Freedombone installation is complete. Rebooting... ***'
  1622. echo ''
  1623. reboot
  1624. }
  1625. argument_checks
  1626. configure_firewall
  1627. configure_firewall_for_ssh
  1628. configure_firewall_for_dns
  1629. configure_firewall_for_ftp
  1630. configure_firewall_for_web_access
  1631. remove_proprietary_repos
  1632. change_debian_repos
  1633. enable_backports
  1634. configure_dns
  1635. initial_setup
  1636. install_editor
  1637. change_login_message
  1638. update_the_kernel
  1639. enable_zram
  1640. random_number_generator
  1641. set_your_domain_name
  1642. time_synchronisation
  1643. configure_internet_protocol
  1644. configure_ssh
  1645. search_for_attached_usb_drive
  1646. regenerate_ssh_keys
  1647. script_to_make_self_signed_certificates
  1648. configure_email
  1649. #spam_filtering
  1650. configure_imap
  1651. configure_gpg
  1652. email_client
  1653. configure_firewall_for_email
  1654. folders_for_mailing_lists
  1655. folders_for_email_addresses
  1656. dynamic_dns_freedns
  1657. #create_private_mailing_list
  1658. import_email
  1659. install_web_server
  1660. configure_firewall_for_web_server
  1661. install_owncloud
  1662. install_xmpp
  1663. configure_firewall_for_xmpp
  1664. install_final
  1665. echo 'Freedombone installation is complete'
  1666. exit 0