install-freedombone.sh 109KB

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