install-freedombone.sh 110KB

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