install-freedombone.sh 109KB

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