install-freedombone.sh 103KB

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