install-freedombone.sh 102KB

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