install-freedombone.sh 81KB

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