install-freedombone.sh 42KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899
  1. #!/bin/bash
  2. # Freedombone install script intended for use with Debian Jessie
  3. DOMAIN_NAME=$1
  4. MY_USERNAME=$2
  5. SSH_PORT=2222
  6. KERNEL_VERSION="v3.15.10-bone7"
  7. USE_HWRNG="yes"
  8. # Directory where source code is downloaded and compiled
  9. INSTALL_DIR=/root/build
  10. export DEBIAN_FRONTEND=noninteractive
  11. # File which keeps track of what has already been installed
  12. COMPLETION_FILE=/root/freedombone-completed.txt
  13. if [ ! -f $COMPLETION_FILE ]; then
  14. touch $COMPLETION_FILE
  15. fi
  16. function argument_checks {
  17. if [ ! $DOMAIN_NAME ]; then
  18. echo "Please specify your domain name"
  19. exit
  20. fi
  21. if [ ! $MY_USERNAME ]; then
  22. echo "Please specify your username"
  23. exit
  24. fi
  25. }
  26. function change_login_message {
  27. if grep -Fxq "change_login_message" $COMPLETION_FILE; then
  28. return
  29. fi
  30. echo '' > /etc/motd
  31. echo ".---. . . " >> /etc/motd
  32. echo "| | | " >> /etc/motd
  33. echo "|--- .--. .-. .-. .-.| .-. .--.--. |.-. .-. .--. .-. " >> /etc/motd
  34. echo "| | (.-' (.-' ( | ( )| | | | )( )| | (.-' " >> /etc/motd
  35. echo "' ' `--' `--' `-'`- `-' ' ' `-'`-' `-' ' `- `--'" >> /etc/motd
  36. echo "" >> /etc/motd
  37. echo " Freedom in the Cloud" >> /etc/motd
  38. echo "" >> /etc/motd
  39. echo 'change_login_message' >> $COMPLETION_FILE
  40. }
  41. function remove_proprietary_repos {
  42. if grep -Fxq "remove_proprietary_repos" $COMPLETION_FILE; then
  43. return
  44. fi
  45. sed -i 's/ non-free//g' /etc/apt/sources.list
  46. echo 'remove_proprietary_repos' >> $COMPLETION_FILE
  47. }
  48. function initial_setup {
  49. if grep -Fxq "initial_setup" $COMPLETION_FILE; then
  50. return
  51. fi
  52. apt-get -y update
  53. apt-get -y dist-upgrade
  54. apt-get -y install ca-certificates emacs24
  55. echo 'initial_setup' >> $COMPLETION_FILE
  56. }
  57. function install_editor {
  58. if grep -Fxq "install_editor" $COMPLETION_FILE; then
  59. return
  60. fi
  61. update-alternatives --set editor /usr/bin/emacs24
  62. echo 'install_editor' >> $COMPLETION_FILE
  63. }
  64. function enable_backports {
  65. if grep -Fxq "enable_backports" $COMPLETION_FILE; then
  66. return
  67. fi
  68. if ! grep -Fxq "deb http://ftp.us.debian.org/debian jessie-backports main" /etc/apt/sources.list; then
  69. echo "deb http://ftp.us.debian.org/debian jessie-backports main" >> /etc/apt/sources.list
  70. fi
  71. echo 'enable_backports' >> $COMPLETION_FILE
  72. }
  73. function update_the_kernel {
  74. if grep -Fxq "update_the_kernel" $COMPLETION_FILE; then
  75. return
  76. fi
  77. cd /opt/scripts/tools
  78. ./update_kernel.sh --kernel $KERNEL_VERSION
  79. echo 'update_the_kernel' >> $COMPLETION_FILE
  80. }
  81. function enable_zram {
  82. if grep -Fxq "enable_zram" $COMPLETION_FILE; then
  83. return
  84. fi
  85. echo "options zram num_devices=1" >> /etc/modprobe.d/zram.conf
  86. echo '#!/bin/bash' > /etc/init.d/zram
  87. echo '### BEGIN INIT INFO' >> /etc/init.d/zram
  88. echo '# Provides: zram' >> /etc/init.d/zram
  89. echo '# Required-Start:' >> /etc/init.d/zram
  90. echo '# Required-Stop:' >> /etc/init.d/zram
  91. echo '# Default-Start: 2 3 4 5' >> /etc/init.d/zram
  92. echo '# Default-Stop: 0 1 6' >> /etc/init.d/zram
  93. echo '# Short-Description: Increased Performance In Linux With zRam (Virtual Swap Compressed in RAM)' >> /etc/init.d/zram
  94. echo '# Description: Adapted from systemd scripts at https://github.com/mystilleef/FedoraZram' >> /etc/init.d/zram
  95. echo '### END INIT INFO' >> /etc/init.d/zram
  96. echo 'start() {' >> /etc/init.d/zram
  97. echo ' # get the number of CPUs' >> /etc/init.d/zram
  98. echo ' num_cpus=$(grep -c processor /proc/cpuinfo)' >> /etc/init.d/zram
  99. echo ' # if something goes wrong, assume we have 1' >> /etc/init.d/zram
  100. echo ' [ "$num_cpus" != 0 ] || num_cpus=1' >> /etc/init.d/zram
  101. echo ' # set decremented number of CPUs' >> /etc/init.d/zram
  102. echo ' decr_num_cpus=$((num_cpus - 1))' >> /etc/init.d/zram
  103. echo ' # get the amount of memory in the machine' >> /etc/init.d/zram
  104. echo ' mem_total_kb=$(grep MemTotal /proc/meminfo | grep -E --only-matching "[[:digit:]]+")' >> /etc/init.d/zram
  105. echo ' mem_total=$((mem_total_kb * 1024))' >> /etc/init.d/zram
  106. echo ' # load dependency modules' >> /etc/init.d/zram
  107. echo ' modprobe zram num_devices=$num_cpus' >> /etc/init.d/zram
  108. echo ' # initialize the devices' >> /etc/init.d/zram
  109. echo ' for i in $(seq 0 $decr_num_cpus); do' >> /etc/init.d/zram
  110. echo ' echo $((mem_total / num_cpus)) > /sys/block/zram$i/disksize' >> /etc/init.d/zram
  111. echo ' done' >> /etc/init.d/zram
  112. echo ' # Creating swap filesystems' >> /etc/init.d/zram
  113. echo ' for i in $(seq 0 $decr_num_cpus); do' >> /etc/init.d/zram
  114. echo ' mkswap /dev/zram$i' >> /etc/init.d/zram
  115. echo ' done' >> /etc/init.d/zram
  116. echo ' # Switch the swaps on' >> /etc/init.d/zram
  117. echo ' for i in $(seq 0 $decr_num_cpus); do' >> /etc/init.d/zram
  118. echo ' swapon -p 100 /dev/zram$i' >> /etc/init.d/zram
  119. echo ' done' >> /etc/init.d/zram
  120. echo '}' >> /etc/init.d/zram
  121. echo 'stop() {' >> /etc/init.d/zram
  122. echo ' # get the number of CPUs' >> /etc/init.d/zram
  123. echo ' num_cpus=$(grep -c processor /proc/cpuinfo)' >> /etc/init.d/zram
  124. echo ' # set decremented number of CPUs' >> /etc/init.d/zram
  125. echo ' decr_num_cpus=$((num_cpus - 1))' >> /etc/init.d/zram
  126. echo ' # Switching off swap' >> /etc/init.d/zram
  127. echo ' for i in $(seq 0 $decr_num_cpus); do' >> /etc/init.d/zram
  128. echo ' if [ "$(grep /dev/zram$i /proc/swaps)" != "" ]; then' >> /etc/init.d/zram
  129. echo ' swapoff /dev/zram$i' >> /etc/init.d/zram
  130. echo ' sleep 1' >> /etc/init.d/zram
  131. echo ' fi' >> /etc/init.d/zram
  132. echo ' done' >> /etc/init.d/zram
  133. echo ' sleep 1' >> /etc/init.d/zram
  134. echo ' rmmod zram' >> /etc/init.d/zram
  135. echo '}' >> /etc/init.d/zram
  136. echo 'case "$1" in' >> /etc/init.d/zram
  137. echo ' start)' >> /etc/init.d/zram
  138. echo ' start' >> /etc/init.d/zram
  139. echo ' ;;' >> /etc/init.d/zram
  140. echo ' stop)' >> /etc/init.d/zram
  141. echo ' stop' >> /etc/init.d/zram
  142. echo ' ;;' >> /etc/init.d/zram
  143. echo ' restart)' >> /etc/init.d/zram
  144. echo ' stop' >> /etc/init.d/zram
  145. echo ' sleep 3' >> /etc/init.d/zram
  146. echo ' start' >> /etc/init.d/zram
  147. echo ' ;;' >> /etc/init.d/zram
  148. echo ' *)' >> /etc/init.d/zram
  149. echo ' echo "Usage: $0 {start|stop|restart}"' >> /etc/init.d/zram
  150. echo ' RETVAL=1' >> /etc/init.d/zram
  151. echo 'esac' >> /etc/init.d/zram
  152. echo 'exit $RETVAL' >> /etc/init.d/zram
  153. chmod +x /etc/init.d/zram
  154. update-rc.d zram defaults
  155. echo 'enable_zram' >> $COMPLETION_FILE
  156. }
  157. function random_number_generator {
  158. if grep -Fxq "random_number_generator" $COMPLETION_FILE; then
  159. return
  160. fi
  161. if [ $USE_HWRNG == "yes" ]; then
  162. apt-get -y install rng-tools
  163. sed -i 's|#HRNGDEVICE=/dev/hwrng|HRNGDEVICE=/dev/hwrng|g' /etc/default/rng-tools
  164. else
  165. apt-get -y install haveged
  166. fi
  167. echo 'random_number_generator' >> $COMPLETION_FILE
  168. }
  169. function configure_ssh {
  170. if grep -Fxq "configure_ssh" $COMPLETION_FILE; then
  171. return
  172. fi
  173. sed -i "s/Port 22/Port $SSH_PORT/g" /etc/ssh/sshd_config
  174. sed -i 's/PermitRootLogin without-password/PermitRootLogin no/g' /etc/ssh/sshd_config
  175. sed -i 's/X11Forwarding yes/X11Forwarding no/g' /etc/ssh/sshd_config
  176. sed -i 's/ServerKeyBits 1024/ServerKeyBits 4096/g' /etc/ssh/sshd_config
  177. sed -i 's/TCPKeepAlive yes/TCPKeepAlive no/g' /etc/ssh/sshd_config
  178. sed -i 's|HostKey /etc/ssh/ssh_host_dsa_key|#HostKey /etc/ssh/ssh_host_dsa_key|g' /etc/ssh/sshd_config
  179. sed -i 's|HostKey /etc/ssh/ssh_host_ecdsa_key|#HostKey /etc/ssh/ssh_host_ecdsa_key|g' /etc/ssh/sshd_config
  180. echo 'ClientAliveInterval 60' >> /etc/ssh/sshd_config
  181. echo 'ClientAliveCountMax 3' >> /etc/ssh/sshd_config
  182. echo 'Ciphers aes256-ctr,aes128-ctr' >> /etc/ssh/sshd_config
  183. echo 'MACs hmac-sha2-512,hmac-sha2-256,hmac-ripemd160
  184. KexAlgorithms diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1' >> /etc/ssh/sshd_config
  185. service ssh restart
  186. apt-get -y install fail2ban
  187. echo 'configure_ssh' >> $COMPLETION_FILE
  188. echo ''
  189. echo ''
  190. echo ' *** Rebooting to initialise ssh settings and random number generator ***'
  191. echo ''
  192. echo " *** Reconnect via ssh on port $SSH_PORT, then run this script again ***"
  193. echo ''
  194. reboot
  195. }
  196. function regenerate_ssh_keys {
  197. if grep -Fxq "regenerate_ssh_keys" $COMPLETION_FILE; then
  198. return
  199. fi
  200. rm -f /etc/ssh/ssh_host_*
  201. dpkg-reconfigure openssh-server
  202. service ssh restart
  203. echo 'regenerate_ssh_keys' >> $COMPLETION_FILE
  204. }
  205. function configure_dns {
  206. if grep -Fxq "configure_dns" $COMPLETION_FILE; then
  207. return
  208. fi
  209. if ! grep -Fxq "nameserver 213.73.91.35" /etc/resolv.conf; then
  210. echo 'nameserver 213.73.91.35' >> /etc/resolv.conf
  211. fi
  212. if ! grep -Fxq "nameserver 85.214.20.141" /etc/resolv.conf; then
  213. echo 'nameserver 85.214.20.141' >> /etc/resolv.conf
  214. fi
  215. echo 'configure_dns' >> $COMPLETION_FILE
  216. }
  217. function set_your_domain_name {
  218. if grep -Fxq "set_your_domain_name" $COMPLETION_FILE; then
  219. return
  220. fi
  221. echo "$DOMAIN_NAME" > /etc/hostname
  222. hostname $DOMAIN_NAME
  223. sed -i "s/127.0.1.1 arm/127.0.1.1 $DOMAIN_NAME/g" /etc/hosts
  224. echo "127.0.1.1 $DOMAIN_NAME" >> /etc/hosts
  225. echo 'set_your_domain_name' >> $COMPLETION_FILE
  226. }
  227. function time_synchronisation {
  228. if grep -Fxq "time_synchronisation" $COMPLETION_FILE; then
  229. return
  230. fi
  231. apt-get -y install build-essential automake git pkg-config autoconf libtool libssl-dev libevent-dev
  232. apt-get -y remove ntpdate
  233. mkdir $INSTALL_DIR
  234. cd $INSTALL_DIR
  235. git clone https://github.com/ioerror/tlsdate.git
  236. cd $INSTALL_DIR/tlsdate
  237. ./autogen.sh
  238. ./configure
  239. make
  240. make install
  241. echo '#!/bin/bash' > /usr/bin/updatedate
  242. echo 'TIMESOURCE=google.com' >> /usr/bin/updatedate
  243. echo 'TIMESOURCE2=www.ptb.de' >> /usr/bin/updatedate
  244. echo 'LOGFILE=/var/log/tlsdate.log' >> /usr/bin/updatedate
  245. echo 'TIMEOUT=5' >> /usr/bin/updatedate
  246. echo "EMAIL=$MY_USERNAME@$DOMAIN_NAME" >> /usr/bin/updatedate
  247. echo '# File which contains the previous date as a number' >> /usr/bin/updatedate
  248. echo 'BEFORE_DATE_FILE=/var/log/tlsdateprevious.txt' >> /usr/bin/updatedate
  249. echo '# File which contains the previous date as a string' >> /usr/bin/updatedate
  250. echo 'BEFORE_FULLDATE_FILE=/var/log/tlsdate.txt' >> /usr/bin/updatedate
  251. echo 'DATE_BEFORE=$(date)' >> /usr/bin/updatedate
  252. echo 'BEFORE=$(date -d "$Y-$M-$D" "+%s")' >> /usr/bin/updatedate
  253. echo 'BACKWARDS_BETWEEN=0' >> /usr/bin/updatedate
  254. echo '# If the date was previously set' >> /usr/bin/updatedate
  255. echo 'if [[ -f "$BEFORE_DATE_FILE" ]]; then' >> /usr/bin/updatedate
  256. echo ' BEFORE_FILE=$(cat $BEFORE_DATE_FILE)' >> /usr/bin/updatedate
  257. echo ' BEFORE_FULLDATE=$(cat $BEFORE_FULLDATE_FILE)' >> /usr/bin/updatedate
  258. echo ' # is the date going backwards?' >> /usr/bin/updatedate
  259. echo ' if (( BEFORE_FILE > BEFORE )); then' >> /usr/bin/updatedate
  260. echo ' echo -n "Date went backwards between tlsdate updates. " >> $LOGFILE' >> /usr/bin/updatedate
  261. echo ' echo -n "$BEFORE_FILE > $BEFORE, " >> $LOGFILE' >> /usr/bin/updatedate
  262. echo ' echo "$BEFORE_FULLDATE > $DATE_BEFORE" >> $LOGFILE' >> /usr/bin/updatedate
  263. echo ' # Send a warning email' > /usr/bin/updatedate
  264. echo ' echo $(tail $LOGFILE -n 2) | mail -s "tlsdate anomaly" $EMAIL' >> /usr/bin/updatedate
  265. echo ' # Try another time source' >> /usr/bin/updatedate
  266. echo ' TIMESOURCE=$TIMESOURCE2' >> /usr/bin/updatedate
  267. echo ' # try running without any parameters' >> /usr/bin/updatedate
  268. echo ' tlsdate >> $LOGFILE' >> /usr/bin/updatedate
  269. echo ' BACKWARDS_BETWEEN=1' >> /usr/bin/updatedate
  270. echo ' fi' >> /usr/bin/updatedate
  271. echo 'fi' >> /usr/bin/updatedate
  272. echo '# Set the date' >> /usr/bin/updatedate
  273. echo '/usr/bin/timeout $TIMEOUT tlsdate -l -t -H $TIMESOURCE -p 443 >> $LOGFILE' >> /usr/bin/updatedate
  274. echo 'DATE_AFTER=$(date)' >> /usr/bin/updatedate
  275. echo 'AFTER=$(date -d "$Y-$M-$D" '+%s')' >> /usr/bin/updatedate
  276. echo '# After setting the date did it go backwards?' >> /usr/bin/updatedate
  277. echo 'if (( AFTER < BEFORE )); then' >> /usr/bin/updatedate
  278. echo ' echo "Incorrect date: $DATE_BEFORE -> $DATE_AFTER" >> $LOGFILE' >> /usr/bin/updatedate
  279. echo ' # Send a warning email' >> /usr/bin/updatedate
  280. echo ' echo $(tail $LOGFILE -n 2) | mail -s "tlsdate anomaly" $EMAIL' >> /usr/bin/updatedate
  281. echo ' # Try resetting the date from another time source' >> /usr/bin/updatedate
  282. echo ' /usr/bin/timeout $TIMEOUT tlsdate -l -t -H $TIMESOURCE2 -p 443 >> $LOGFILE' >> /usr/bin/updatedate
  283. echo ' DATE_AFTER=$(date)' >> /usr/bin/updatedate
  284. echo ' AFTER=$(date -d "$Y-$M-$D" "+%s")' >> /usr/bin/updatedate
  285. echo 'else' >> /usr/bin/updatedate
  286. echo ' echo -n $TIMESOURCE >> $LOGFILE' >> /usr/bin/updatedate
  287. echo ' if [[ -f "$BEFORE_DATE_FILE" ]]; then' >> /usr/bin/updatedate
  288. echo ' echo -n " " >> $LOGFILE' >> /usr/bin/updatedate
  289. echo ' echo -n $BEFORE_FILE >> $LOGFILE' >> /usr/bin/updatedate
  290. echo ' fi' >> /usr/bin/updatedate
  291. echo ' echo -n " " >> $LOGFILE' >> /usr/bin/updatedate
  292. echo ' echo -n $BEFORE >> $LOGFILE' >> /usr/bin/updatedate
  293. echo ' echo -n " " >> $LOGFILE' >> /usr/bin/updatedate
  294. echo ' echo -n $AFTER >> $LOGFILE' >> /usr/bin/updatedate
  295. echo ' echo -n " " >> $LOGFILE' >> /usr/bin/updatedate
  296. echo ' echo $DATE_AFTER >> $LOGFILE' >> /usr/bin/updatedate
  297. echo 'fi' >> /usr/bin/updatedate
  298. echo '# Log the last date' >> /usr/bin/updatedate
  299. echo 'if [ BACKWARDS_BETWEEN == 0 ]; then' >> /usr/bin/updatedate
  300. echo ' echo "$AFTER" > $BEFORE_DATE_FILE' >> /usr/bin/updatedate
  301. echo ' echo "$DATE_AFTER" > $BEFORE_FULLDATE_FILE' >> /usr/bin/updatedate
  302. echo ' exit 0' >> /usr/bin/updatedate
  303. echo 'else' >> /usr/bin/updatedate
  304. echo ' exit 1' >> /usr/bin/updatedate
  305. echo 'fi' >> /usr/bin/updatedate
  306. chmod +x /usr/bin/updatedate
  307. echo '*/15 * * * * root /usr/bin/updatedate' >> /etc/crontab
  308. service cron restart
  309. echo '#!/bin/bash' > /etc/init.d/tlsdate
  310. echo '# /etc/init.d/tlsdate' >> /etc/init.d/tlsdate
  311. echo '### BEGIN INIT INFO' >> /etc/init.d/tlsdate
  312. echo '# Provides: tlsdate' >> /etc/init.d/tlsdate
  313. echo '# Required-Start: $remote_fs $syslog' >> /etc/init.d/tlsdate
  314. echo '# Required-Stop: $remote_fs $syslog' >> /etc/init.d/tlsdate
  315. echo '# Default-Start: 2 3 4 5' >> /etc/init.d/tlsdate
  316. echo '# Default-Stop: 0 1 6' >> /etc/init.d/tlsdate
  317. echo '# Short-Description: Initially calls tlsdate with the timewarp option' >> /etc/init.d/tlsdate
  318. echo '# Description: Initially calls tlsdate with the timewarp option' >> /etc/init.d/tlsdate
  319. echo '### END INIT INFO' >> /etc/init.d/tlsdate
  320. echo '# Author: Bob Mottram <bob@robotics.uk.to>' >> /etc/init.d/tlsdate
  321. echo 'PATH="/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin"' >> /etc/init.d/tlsdate
  322. echo 'LOGFILE="/var/log/tlsdate.log"' >> /etc/init.d/tlsdate
  323. echo 'TLSDATECOMMAND="tlsdate --timewarp -l -H www.ptb.de -p 443 >> $LOGFILE"' >> /etc/init.d/tlsdate
  324. echo '#Start-Stop here' >> /etc/init.d/tlsdate
  325. echo 'case "$1" in' >> /etc/init.d/tlsdate
  326. echo ' start)' >> /etc/init.d/tlsdate
  327. echo ' echo "tlsdate started"' >> /etc/init.d/tlsdate
  328. echo ' $TLSDATECOMMAND' >> /etc/init.d/tlsdate
  329. echo ' ;;' >> /etc/init.d/tlsdate
  330. echo ' stop)' >> /etc/init.d/tlsdate
  331. echo ' echo "tlsdate stopped"' >> /etc/init.d/tlsdate
  332. echo ' ;;' >> /etc/init.d/tlsdate
  333. echo ' restart)' >> /etc/init.d/tlsdate
  334. echo ' echo "tlsdate restarted"' >> /etc/init.d/tlsdate
  335. echo ' $TLSDATECOMMAND' >> /etc/init.d/tlsdate
  336. echo ' ;;' >> /etc/init.d/tlsdate
  337. echo ' *)' >> /etc/init.d/tlsdate
  338. echo ' echo "Usage: $0 {start|stop|restart}"' >> /etc/init.d/tlsdate
  339. echo ' exit 1' >> /etc/init.d/tlsdate
  340. echo ' ;;' >> /etc/init.d/tlsdate
  341. echo 'esac' >> /etc/init.d/tlsdate
  342. echo 'exit 0' >> /etc/init.d/tlsdate
  343. chmod +x /etc/init.d/tlsdate
  344. update-rc.d tlsdate defaults
  345. echo 'time_synchronisation' >> $COMPLETION_FILE
  346. }
  347. function configure_firewall {
  348. if grep -Fxq "configure_firewall" $COMPLETION_FILE; then
  349. return
  350. fi
  351. iptables -P INPUT ACCEPT
  352. ip6tables -P INPUT ACCEPT
  353. iptables -F
  354. ip6tables -F
  355. iptables -X
  356. ip6tables -X
  357. iptables -P INPUT DROP
  358. ip6tables -P INPUT DROP
  359. echo 'configure_firewall' >> $COMPLETION_FILE
  360. }
  361. function save_firewall_settings {
  362. iptables-save > /etc/firewall.conf
  363. ip6tables-save > /etc/firewall6.conf
  364. printf '#!/bin/sh\n' > /etc/network/if-up.d/iptables
  365. printf 'iptables-restore < /etc/firewall.conf\n' >> /etc/network/if-up.d/iptables
  366. printf 'ip6tables-restore < /etc/firewall6.conf\n' >> /etc/network/if-up.d/iptables
  367. chmod +x /etc/network/if-up.d/iptables
  368. }
  369. function configure_firewall_for_ssh {
  370. if grep -Fxq "configure_firewall_for_ssh" $COMPLETION_FILE; then
  371. return
  372. fi
  373. iptables -A INPUT -i eth0 -p tcp --dport $SSH_PORT -j ACCEPT
  374. save_firewall_settings
  375. echo 'configure_firewall_for_ssh' >> $COMPLETION_FILE
  376. }
  377. function configure_firewall_for_git {
  378. if grep -Fxq "configure_firewall_for_git" $COMPLETION_FILE; then
  379. return
  380. fi
  381. iptables -A INPUT -i eth0 -p tcp --dport 9418 -j ACCEPT
  382. save_firewall_settings
  383. echo 'configure_firewall_for_git' >> $COMPLETION_FILE
  384. }
  385. function configure_firewall_for_email {
  386. if grep -Fxq "configure_firewall_for_email" $COMPLETION_FILE; then
  387. return
  388. fi
  389. iptables -A INPUT -i eth0 -p tcp --dport 25 -j ACCEPT
  390. iptables -A INPUT -i eth0 -p tcp --dport 587 -j ACCEPT
  391. iptables -A INPUT -i eth0 -p tcp --dport 465 -j ACCEPT
  392. iptables -A INPUT -i eth0 -p tcp --dport 993 -j ACCEPT
  393. save_firewall_settings
  394. echo 'configure_firewall_for_email' >> $COMPLETION_FILE
  395. }
  396. function configure_internet_protocol {
  397. if grep -Fxq "configure_internet_protocol" $COMPLETION_FILE; then
  398. return
  399. fi
  400. sed -i "s/#net.ipv4.tcp_syncookies=1/net.ipv4.tcp_syncookies=1/g" /etc/sysctl.conf
  401. sed -i "s/#net.ipv4.conf.all.accept_redirects = 0/net.ipv4.conf.all.accept_redirects = 0/g" /etc/sysctl.conf
  402. sed -i "s/#net.ipv6.conf.all.accept_redirects = 0/net.ipv6.conf.all.accept_redirects = 0/g" /etc/sysctl.conf
  403. sed -i "s/#net.ipv4.conf.all.send_redirects = 0/net.ipv4.conf.all.send_redirects = 0/g" /etc/sysctl.conf
  404. sed -i "s/#net.ipv4.conf.all.accept_source_route = 0/net.ipv4.conf.all.accept_source_route = 0/g" /etc/sysctl.conf
  405. sed -i "s/#net.ipv6.conf.all.accept_source_route = 0/net.ipv6.conf.all.accept_source_route = 0/g" /etc/sysctl.conf
  406. sed -i "s/#net.ipv4.conf.default.rp_filter=1/net.ipv4.conf.default.rp_filter=1/g" /etc/sysctl.conf
  407. sed -i "s/#net.ipv4.conf.all.rp_filter=1/net.ipv4.conf.all.rp_filter=1/g" /etc/sysctl.conf
  408. sed -i "s/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=0/g" /etc/sysctl.conf
  409. sed -i "s/#net.ipv6.conf.all.forwarding=1/net.ipv6.conf.all.forwarding=0/g" /etc/sysctl.conf
  410. echo '# ignore pings' >> /etc/sysctl.conf
  411. echo 'net.ipv4.icmp_echo_ignore_all = 1' >> /etc/sysctl.conf
  412. echo 'net.ipv6.icmp_echo_ignore_all = 1' >> /etc/sysctl.conf
  413. echo '# disable ipv6' >> /etc/sysctl.conf
  414. echo 'net.ipv6.conf.all.disable_ipv6 = 1' >> /etc/sysctl.conf
  415. echo 'net.ipv4.tcp_synack_retries = 2' >> /etc/sysctl.conf
  416. echo 'net.ipv4.tcp_syn_retries = 1' >> /etc/sysctl.conf
  417. echo '# keepalive' >> /etc/sysctl.conf
  418. echo 'net.ipv4.tcp_keepalive_probes = 9' >> /etc/sysctl.conf
  419. echo 'net.ipv4.tcp_keepalive_intvl = 75' >> /etc/sysctl.conf
  420. echo 'net.ipv4.tcp_keepalive_time = 7200' >> /etc/sysctl.conf
  421. echo 'configure_internet_protocol' >> $COMPLETION_FILE
  422. }
  423. function script_to_make_self_signed_certificates {
  424. if grep -Fxq "script_to_make_self_signed_certificates" $COMPLETION_FILE; then
  425. return
  426. fi
  427. echo '#!/bin/bash' > /usr/bin/makecert
  428. echo 'HOSTNAME=$1' >> /usr/bin/makecert
  429. echo 'COUNTRY_CODE="US"' >> /usr/bin/makecert
  430. echo 'AREA="Free Speech Zone"' >> /usr/bin/makecert
  431. echo 'LOCATION="Freedomville"' >> /usr/bin/makecert
  432. echo 'ORGANISATION="Freedombone"' >> /usr/bin/makecert
  433. echo 'UNIT="Freedombone Unit"' >> /usr/bin/makecert
  434. echo 'if ! which openssl > /dev/null ;then' >> /usr/bin/makecert
  435. echo ' echo "$0: openssl is not installed, exiting" 1>&2' >> /usr/bin/makecert
  436. echo ' exit 1' >> /usr/bin/makecert
  437. echo 'fi' >> /usr/bin/makecert
  438. 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
  439. echo 'openssl dhparam -check -text -5 1024 -out /etc/ssl/certs/$HOSTNAME.dhparam' >> /usr/bin/makecert
  440. echo 'chmod 400 /etc/ssl/private/$HOSTNAME.key' >> /usr/bin/makecert
  441. echo 'chmod 640 /etc/ssl/certs/$HOSTNAME.crt' >> /usr/bin/makecert
  442. echo 'chmod 640 /etc/ssl/certs/$HOSTNAME.dhparam' >> /usr/bin/makecert
  443. echo '/etc/init.d/nginx reload' >> /usr/bin/makecert
  444. echo '# add the public certificate to a separate directory' >> /usr/bin/makecert
  445. echo '# so that we can redistribute it easily' >> /usr/bin/makecert
  446. echo 'if [ ! -d /etc/ssl/mycerts ]; then' >> /usr/bin/makecert
  447. echo ' mkdir /etc/ssl/mycerts' >> /usr/bin/makecert
  448. echo 'fi' >> /usr/bin/makecert
  449. echo 'cp /etc/ssl/certs/$HOSTNAME.crt /etc/ssl/mycerts' >> /usr/bin/makecert
  450. echo '# Create a bundle of your certificates' >> /usr/bin/makecert
  451. echo 'cat /etc/ssl/mycerts/*.crt > /etc/ssl/freedombone-bundle.crt' >> /usr/bin/makecert
  452. echo 'tar -czvf /etc/ssl/freedombone-certs.tar.gz /etc/ssl/mycerts/*.crt' >> /usr/bin/makecert
  453. chmod +x /usr/bin/makecert
  454. echo 'script_to_make_self_signed_certificates' >> $COMPLETION_FILE
  455. }
  456. function configure_email {
  457. if grep -Fxq "configure_email" $COMPLETION_FILE; then
  458. return
  459. fi
  460. apt-get -y remove postfix
  461. apt-get -y install exim4 sasl2-bin swaks libnet-ssleay-perl procmail
  462. echo 'dc_eximconfig_configtype="internet"' > /etc/exim4/update-exim4.conf.conf
  463. echo "dc_other_hostnames='$DOMAIN_NAME'" >> /etc/exim4/update-exim4.conf.conf
  464. echo "dc_local_interfaces=''" >> /etc/exim4/update-exim4.conf.conf
  465. echo "dc_readhost=''" >> /etc/exim4/update-exim4.conf.conf
  466. echo "dc_relay_domains=''" >> /etc/exim4/update-exim4.conf.conf
  467. echo "dc_minimaldns='false'" >> /etc/exim4/update-exim4.conf.conf
  468. echo "dc_relay_nets='192.168.1.0/24'" >> /etc/exim4/update-exim4.conf.conf
  469. echo "dc_smarthost=''" >> /etc/exim4/update-exim4.conf.conf
  470. echo "CFILEMODE='644'" >> /etc/exim4/update-exim4.conf.conf
  471. echo "dc_use_split_config='false'" >> /etc/exim4/update-exim4.conf.conf
  472. echo "dc_hide_mailname=''" >> /etc/exim4/update-exim4.conf.conf
  473. echo "dc_mailname_in_oh='true'" >> /etc/exim4/update-exim4.conf.conf
  474. echo "dc_localdelivery='maildir_home'" >> /etc/exim4/update-exim4.conf.conf
  475. update-exim4.conf
  476. sed -i "s/START=no/START=yes/g" /etc/default/saslauthd
  477. /etc/init.d/saslauthd start
  478. # make a tls certificate for email
  479. makecert exim
  480. mv /etc/ssl/private/exim.key /etc/exim4
  481. mv /etc/ssl/certs/exim.crt /etc/exim4
  482. mv /etc/ssl/certs/exim.dhparam /etc/exim4
  483. chown root:Debian-exim /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
  484. chmod 640 /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
  485. sed -i '/login_saslauthd_server/,/.endif/ s/# *//' /etc/exim4/exim4.conf.template
  486. sed -i "/.ifdef MAIN_HARDCODE_PRIMARY_HOSTNAME/i\MAIN_HARDCODE_PRIMARY_HOSTNAME = $DOMAIN_NAME\nMAIN_TLS_ENABLE = true" /etc/exim4/exim4.conf.template
  487. sed -i "s|SMTPLISTENEROPTIONS=''|SMTPLISTENEROPTIONS='-oX 465:25:587 -oP /var/run/exim4/exim.pid'|g" /etc/default/exim4
  488. sed -i '/03_exim4-config_tlsoptions/a\tls_on_connect_ports=465' /etc/exim4/exim4.conf.template
  489. adduser $MY_USERNAME sasl
  490. addgroup Debian-exim sasl
  491. /etc/init.d/exim4 restart
  492. mkdir -m 700 /etc/skel/Maildir
  493. mkdir -m 700 /etc/skel/Maildir/Sent
  494. mkdir -m 700 /etc/skel/Maildir/Sent/tmp
  495. mkdir -m 700 /etc/skel/Maildir/Sent/cur
  496. mkdir -m 700 /etc/skel/Maildir/Sent/new
  497. mkdir -m 700 /etc/skel/Maildir/.learn-spam
  498. mkdir -m 700 /etc/skel/Maildir/.learn-spam/cur
  499. mkdir -m 700 /etc/skel/Maildir/.learn-spam/new
  500. mkdir -m 700 /etc/skel/Maildir/.learn-spam/tmp
  501. mkdir -m 700 /etc/skel/Maildir/.learn-ham
  502. mkdir -m 700 /etc/skel/Maildir/.learn-ham/cur
  503. mkdir -m 700 /etc/skel/Maildir/.learn-ham/new
  504. mkdir -m 700 /etc/skel/Maildir/.learn-ham/tmp
  505. ln -s /etc/skel/Maildir/.learn-spam /etc/skel/Maildir/spam
  506. ln -s /etc/skel/Maildir/.learn-ham /etc/skel/Maildir/ham
  507. if [ ! -d /home/$MY_USERNAME/Maildir ]; then
  508. mkdir -m 700 /home/$MY_USERNAME/Maildir
  509. mkdir -m 700 /home/$MY_USERNAME/Maildir/cur
  510. mkdir -m 700 /home/$MY_USERNAME/Maildir/tmp
  511. mkdir -m 700 /home/$MY_USERNAME/Maildir/new
  512. mkdir -m 700 /home/$MY_USERNAME/Maildir/Sent
  513. mkdir -m 700 /home/$MY_USERNAME/Maildir/Sent/cur
  514. mkdir -m 700 /home/$MY_USERNAME/Maildir/Sent/tmp
  515. mkdir -m 700 /home/$MY_USERNAME/Maildir/Sent/new
  516. mkdir -m 700 /home/$MY_USERNAME/Maildir/.learn-spam
  517. mkdir -m 700 /home/$MY_USERNAME/Maildir/.learn-spam/cur
  518. mkdir -m 700 /home/$MY_USERNAME/Maildir/.learn-spam/new
  519. mkdir -m 700 /home/$MY_USERNAME/Maildir/.learn-spam/tmp
  520. mkdir -m 700 /home/$MY_USERNAME/Maildir/.learn-ham
  521. mkdir -m 700 /home/$MY_USERNAME/Maildir/.learn-ham/cur
  522. mkdir -m 700 /home/$MY_USERNAME/Maildir/.learn-ham/new
  523. mkdir -m 700 /home/$MY_USERNAME/Maildir/.learn-ham/tmp
  524. ln -s /home/$MY_USERNAME/Maildir/.learn-spam /home/$MY_USERNAME/Maildir/spam
  525. ln -s /home/$MY_USERNAME/Maildir/.learn-ham /home/$MY_USERNAME/Maildir/ham
  526. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Maildir
  527. fi
  528. echo 'configure_email' >> $COMPLETION_FILE
  529. }
  530. function spam_filtering {
  531. if grep -Fxq "spam_filtering" $COMPLETION_FILE; then
  532. return
  533. fi
  534. apt-get -y install spamassassin exim4-daemon-heavy
  535. sed -i 's/ENABLED=0/ENABLED=1/g' /etc/default/spamassassin
  536. sed -i 's/# spamd_address = 127.0.0.1 783/spamd_address = 127.0.0.1 783/g' /etc/exim4/exim4.conf.template
  537. # This configuration is based on https://wiki.debian.org/DebianSpamAssassin
  538. sed -i 's/local_parts = postmaster/local_parts = postmaster:abuse/g' /etc/exim4/conf.d/acl/30_exim4-config_check_rcpt
  539. sed -i '/domains = +local_domains : +relay_to_domains/a\ set acl_m0 = rfcnames' /etc/exim4/conf.d/acl/30_exim4-config_check_rcpt
  540. sed -i 's/accept/accept condition = ${if eq{$acl_m0}{rfcnames} {1}{0}}/g' /etc/exim4/conf.d/acl/40_exim4-config_check_data
  541. echo 'warn message = X-Spam-Score: $spam_score ($spam_bar)' >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
  542. echo ' spam = nobody:true' >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
  543. echo 'warn message = X-Spam-Flag: YES' >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
  544. echo ' spam = nobody' >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
  545. echo 'warn message = X-Spam-Report: $spam_report' >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
  546. echo ' spam = nobody' >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
  547. echo '# reject spam at high scores (> 12)' >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
  548. echo 'deny message = This message scored $spam_score spam points.' >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
  549. echo ' spam = nobody:true' >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
  550. echo ' condition = ${if >{$spam_score_int}{120}{1}{0}}' >> /etc/exim4/conf.d/acl/40_exim4-config_check_data
  551. # procmail configuration
  552. echo 'MAILDIR=$HOME/Maildir' > /home/$MY_USERNAME/.procmailrc
  553. echo 'DEFAULT=$MAILDIR/' >> /home/$MY_USERNAME/.procmailrc
  554. echo 'LOGFILE=$HOME/log/procmail.log' >> /home/$MY_USERNAME/.procmailrc
  555. echo 'LOGABSTRACT=all' >> /home/$MY_USERNAME/.procmailrc
  556. echo '# get spamassassin to check emails' >> /home/$MY_USERNAME/.procmailrc
  557. echo ':0fw: .spamassassin.lock' >> /home/$MY_USERNAME/.procmailrc
  558. echo ' * < 256000' >> /home/$MY_USERNAME/.procmailrc
  559. echo '| spamc' >> /home/$MY_USERNAME/.procmailrc
  560. echo '# strong spam are discarded' >> /home/$MY_USERNAME/.procmailrc
  561. echo ':0' >> /home/$MY_USERNAME/.procmailrc
  562. echo ' * ^X-Spam-Level: \*\*\*\*\*\*' >> /home/$MY_USERNAME/.procmailrc
  563. echo '/dev/null' >> /home/$MY_USERNAME/.procmailrc
  564. echo '# weak spam are kept just in case - clear this out every now and then' >> /home/$MY_USERNAME/.procmailrc
  565. echo ':0' >> /home/$MY_USERNAME/.procmailrc
  566. echo ' * ^X-Spam-Level: \*\*\*\*\*' >> /home/$MY_USERNAME/.procmailrc
  567. echo '.0-spam/' >> /home/$MY_USERNAME/.procmailrc
  568. echo '# otherwise, marginal spam goes here for revision' >> /home/$MY_USERNAME/.procmailrc
  569. echo ':0' >> /home/$MY_USERNAME/.procmailrc
  570. echo ' * ^X-Spam-Level: \*\*' >> /home/$MY_USERNAME/.procmailrc
  571. echo '.spam/' >> /home/$MY_USERNAME/.procmailrc
  572. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.procmailrc
  573. # filtering scripts
  574. echo '#!/bin/bash' > /usr/bin/filterspam
  575. echo 'USERNAME=$1' >> /usr/bin/filterspam
  576. echo 'MAILDIR=/home/$USERNAME/Maildir/.learn-spam' >> /usr/bin/filterspam
  577. echo 'if [ ! -d "$MAILDIR" ]; then' >> /usr/bin/filterspam
  578. echo ' exit' >> /usr/bin/filterspam
  579. echo 'fi' >> /usr/bin/filterspam
  580. echo 'for f in `ls $MAILDIR/cur`' >> /usr/bin/filterspam
  581. echo 'do' >> /usr/bin/filterspam
  582. echo ' spamc -L spam < "$MAILDIR/cur/$f" > /dev/null' >> /usr/bin/filterspam
  583. echo ' rm "$MAILDIR/cur/$f"' >> /usr/bin/filterspam
  584. echo 'done' >> /usr/bin/filterspam
  585. echo 'for f in `ls $MAILDIR/new`' >> /usr/bin/filterspam
  586. echo 'do' >> /usr/bin/filterspam
  587. echo ' spamc -L spam < "$MAILDIR/new/$f" > /dev/null' >> /usr/bin/filterspam
  588. echo ' rm "$MAILDIR/new/$f"' >> /usr/bin/filterspam
  589. echo 'done' >> /usr/bin/filterspam
  590. echo '#!/bin/bash' > /usr/bin/filterham
  591. echo 'USERNAME=$1' >> /usr/bin/filterham
  592. echo 'MAILDIR=/home/$USERNAME/Maildir/.learn-ham' >> /usr/bin/filterham
  593. echo 'if [ ! -d "$MAILDIR" ]; then' >> /usr/bin/filterham
  594. echo ' exit' >> /usr/bin/filterham
  595. echo 'fi' >> /usr/bin/filterham
  596. echo 'for f in `ls $MAILDIR/cur`' >> /usr/bin/filterham
  597. echo 'do' >> /usr/bin/filterham
  598. echo ' spamc -L ham < "$MAILDIR/cur/$f" > /dev/null' >> /usr/bin/filterham
  599. echo ' rm "$MAILDIR/cur/$f"' >> /usr/bin/filterham
  600. echo 'done' >> /usr/bin/filterham
  601. echo 'for f in `ls $MAILDIR/new`' >> /usr/bin/filterham
  602. echo 'do' >> /usr/bin/filterham
  603. echo ' spamc -L ham < "$MAILDIR/new/$f" > /dev/null' >> /usr/bin/filterham
  604. echo ' rm "$MAILDIR/new/$f"' >> /usr/bin/filterham
  605. echo 'done' >> /usr/bin/filterham
  606. echo "*/3 * * * * root /usr/bin/timeout 120 /usr/bin/filterspam $MY_USERNAME" >> /etc/crontab
  607. echo "*/3 * * * * root /usr/bin/timeout 120 /usr/bin/filterham $MY_USERNAME" >> /etc/crontab
  608. chmod 655 /usr/bin/filterspam /usr/bin/filterham
  609. sed -i 's/# use_bayes 1/use_bayes 1/g' /etc/mail/spamassassin/local.cf
  610. sed -i 's/# bayes_auto_learn 1/bayes_auto_learn 1/g' /etc/mail/spamassassin/local.cf
  611. service spamassassin restart
  612. service exim4 restart
  613. service cron restart
  614. echo 'spam_filtering' >> $COMPLETION_FILE
  615. }
  616. function configure_imap {
  617. if grep -Fxq "configure_imap" $COMPLETION_FILE; then
  618. return
  619. fi
  620. apt-get -y install dovecot-common dovecot-imapd
  621. makecert dovecot
  622. chown root:dovecot /etc/ssl/certs/dovecot.crt
  623. chown root:dovecot /etc/ssl/private/dovecot.key
  624. chown root:dovecot /etc/ssl/private/dovecot.dhparams
  625. sed -i 's|#ssl = yes|ssl = yes|g' /etc/dovecot/conf.d/10-ssl.conf
  626. sed -i 's|ssl_cert = </etc/dovecot/dovecot.pem|ssl_cert = </etc/ssl/certs/dovecot.crt|g' /etc/dovecot/conf.d/10-ssl.conf
  627. sed -i 's|ssl_key = </etc/dovecot/private/dovecot.pem|/etc/ssl/private/dovecot.key|g' /etc/dovecot/conf.d/10-ssl.conf
  628. sed -i 's|#ssl_dh_parameters_length = 1024|ssl_dh_parameters_length = 1024|g' /etc/dovecot/conf.d/10-ssl.conf
  629. sed -i 's/#ssl_prefer_server_ciphers = no/ssl_prefer_server_ciphers = yes/g' /etc/dovecot/conf.d/10-ssl.conf
  630. 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
  631. sed -i 's/#listen = *, ::/listen = */g' /etc/dovecot/dovecot.conf
  632. sed -i 's/#disable_plaintext_auth = yes/disable_plaintext_auth = no/g' /etc/dovecot/conf.d/10-auth.conf
  633. sed -i 's/auth_mechanisms = plain/auth_mechanisms = plain login/g' /etc/dovecot/conf.d/10-auth.conf
  634. sed -i 's|# mail_location = maildir:~/Maildir| mail_location = maildir:~/Maildir:LAYOUT=fs|g' /etc/dovecot/conf.d/10-mail.conf
  635. echo 'configure_imap' >> $COMPLETION_FILE
  636. }
  637. function configure_gpg {
  638. if grep -Fxq "configure_gpg" $COMPLETION_FILE; then
  639. return
  640. fi
  641. apt-get -y install gnupg
  642. echo 'configure_gpg' >> $COMPLETION_FILE
  643. }
  644. function email_client {
  645. if grep -Fxq "email_client" $COMPLETION_FILE; then
  646. return
  647. fi
  648. apt-get -y install mutt-patched lynx abook
  649. if [ ! -d /home/$MY_USERNAME/.mutt ]; then
  650. mkdir /home/$MY_USERNAME/.mutt
  651. fi
  652. echo "text/html; lynx -dump -width=78 -nolist %s | sed ‘s/^ //’; copiousoutput; needsterminal; nametemplate=%s.html" > /home/$MY_USERNAME/.mutt/mailcap
  653. chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.mutt
  654. echo 'set mbox_type=Maildir' >> /etc/Muttrc
  655. echo 'set folder="~/Maildir"' >> /etc/Muttrc
  656. echo 'set mask="!^\\.[^.]"' >> /etc/Muttrc
  657. echo 'set mbox="~/Maildir"' >> /etc/Muttrc
  658. echo 'set record="+Sent"' >> /etc/Muttrc
  659. echo 'set postponed="+Drafts"' >> /etc/Muttrc
  660. echo 'set trash="+Trash"' >> /etc/Muttrc
  661. echo 'set spoolfile="~/Maildir"' >> /etc/Muttrc
  662. echo 'auto_view text/x-vcard text/html text/enriched' >> /etc/Muttrc
  663. echo 'set editor="emacs"' >> /etc/Muttrc
  664. echo 'set header_cache="+.cache"' >> /etc/Muttrc
  665. echo '' >> /etc/Muttrc
  666. echo 'macro index S "<tag-prefix><save-message>=.learn-spam<enter>" "move to learn-spam"' >> /etc/Muttrc
  667. echo 'macro pager S "<save-message>=.learn-spam<enter>" "move to learn-spam"' >> /etc/Muttrc
  668. echo 'macro index H "<tag-prefix><copy-message>=.learn-ham<enter>" "copy to learn-ham"' >> /etc/Muttrc
  669. echo 'macro pager H "<copy-message>=.learn-ham<enter>" "copy to learn-ham"' >> /etc/Muttrc
  670. echo '' >> /etc/Muttrc
  671. echo '# set up the sidebar' >> /etc/Muttrc
  672. echo 'set sidebar_width=12' >> /etc/Muttrc
  673. echo 'set sidebar_visible=yes' >> /etc/Muttrc
  674. echo "set sidebar_delim='|'" >> /etc/Muttrc
  675. echo 'set sidebar_sort=yes' >> /etc/Muttrc
  676. echo '' >> /etc/Muttrc
  677. echo 'set rfc2047_parameters' >> /etc/Muttrc
  678. echo '' >> /etc/Muttrc
  679. echo '# Show inbox and sent items' >> /etc/Muttrc
  680. echo 'mailboxes = =Sent' >> /etc/Muttrc
  681. echo '' >> /etc/Muttrc
  682. echo '# Alter these colours as needed for maximum bling' >> /etc/Muttrc
  683. echo 'color sidebar_new yellow default' >> /etc/Muttrc
  684. echo 'color normal white default' >> /etc/Muttrc
  685. echo 'color hdrdefault brightcyan default' >> /etc/Muttrc
  686. echo 'color signature green default' >> /etc/Muttrc
  687. echo 'color attachment brightyellow default' >> /etc/Muttrc
  688. echo 'color quoted green default' >> /etc/Muttrc
  689. echo 'color quoted1 white default' >> /etc/Muttrc
  690. echo 'color tilde blue default' >> /etc/Muttrc
  691. echo '' >> /etc/Muttrc
  692. echo '# ctrl-n, ctrl-p to select next, prev folder' >> /etc/Muttrc
  693. echo '# ctrl-o to open selected folder' >> /etc/Muttrc
  694. echo 'bind index \Cp sidebar-prev' >> /etc/Muttrc
  695. echo 'bind index \Cn sidebar-next' >> /etc/Muttrc
  696. echo 'bind index \Co sidebar-open' >> /etc/Muttrc
  697. echo 'bind pager \Cp sidebar-prev' >> /etc/Muttrc
  698. echo 'bind pager \Cn sidebar-next' >> /etc/Muttrc
  699. echo 'bind pager \Co sidebar-open' >> /etc/Muttrc
  700. echo '' >> /etc/Muttrc
  701. echo '# ctrl-b toggles sidebar visibility' >> /etc/Muttrc
  702. echo "macro index,pager \Cb '<enter-command>toggle sidebar_visible<enter><redraw-screen>' 'toggle sidebar'" >> /etc/Muttrc
  703. echo '' >> /etc/Muttrc
  704. echo '# esc-m Mark new messages as read' >> /etc/Muttrc
  705. echo 'macro index <esc>m "T~N<enter>;WNT~O<enter>;WO\CT~T<enter>" "mark all messages read"' >> /etc/Muttrc
  706. echo '' >> /etc/Muttrc
  707. echo '# Collapsing threads' >> /etc/Muttrc
  708. echo 'macro index [ "<collapse-thread>" "collapse/uncollapse thread"' >> /etc/Muttrc
  709. echo 'macro index ] "<collapse-all>" "collapse/uncollapse all threads"' >> /etc/Muttrc
  710. echo '' >> /etc/Muttrc
  711. echo '# threads containing new messages' >> /etc/Muttrc
  712. echo 'uncolor index "~(~N)"' >> /etc/Muttrc
  713. echo 'color index brightblue default "~(~N)"' >> /etc/Muttrc
  714. echo '' >> /etc/Muttrc
  715. echo '# new messages themselves' >> /etc/Muttrc
  716. echo 'uncolor index "~N"' >> /etc/Muttrc
  717. echo 'color index brightyellow default "~N"' >> /etc/Muttrc
  718. echo '' >> /etc/Muttrc
  719. echo '# GPG/PGP integration' >> /etc/Muttrc
  720. echo '# this set the number of seconds to keep in memory the passphrase used to encrypt/sign' >> /etc/Muttrc
  721. echo 'set pgp_timeout=60' >> /etc/Muttrc
  722. echo '' >> /etc/Muttrc
  723. echo '# automatically sign and encrypt with PGP/MIME' >> /etc/Muttrc
  724. echo 'set pgp_autosign # autosign all outgoing mails' >> /etc/Muttrc
  725. echo 'set pgp_replyencrypt # autocrypt replies to crypted' >> /etc/Muttrc
  726. echo 'set pgp_replysign # autosign replies to signed' >> /etc/Muttrc
  727. echo 'set pgp_auto_decode=yes # decode attachments' >> /etc/Muttrc
  728. echo 'unset smime_is_default' >> /etc/Muttrc
  729. echo '' >> /etc/Muttrc
  730. echo 'set alias_file=~/.mutt-alias' >> /etc/Muttrc
  731. echo 'source ~/.mutt-alias' >> /etc/Muttrc
  732. echo 'set query_command= "abook --mutt-query \"%s\""' >> /etc/Muttrc
  733. echo 'macro index,pager A "<pipe-message>abook --add-email-quiet<return>" "add the sender address to abook"' >> /etc/Muttrc
  734. cp -f /etc/Muttrc /home/$MY_USERNAME/.muttrc
  735. touch /home/$MY_USERNAME/.mutt-alias
  736. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.muttrc
  737. chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.mutt-alias
  738. echo 'email_client' >> $COMPLETION_FILE
  739. }
  740. function folders_for_mailing_lists {
  741. if grep -Fxq "folders_for_mailing_lists" $COMPLETION_FILE; then
  742. return
  743. fi
  744. echo '#!/bin/bash' > /usr/bin/mailinglistrule
  745. echo 'MYUSERNAME=$1' >> /usr/bin/mailinglistrule
  746. echo 'MAILINGLIST=$2' >> /usr/bin/mailinglistrule
  747. echo 'SUBJECTTAG=$3' >> /usr/bin/mailinglistrule
  748. echo 'MUTTRC=/home/$MYUSERNAME/.muttrc' >> /usr/bin/mailinglistrule
  749. echo 'PM=/home/$MYUSERNAME/.procmailrc' >> /usr/bin/mailinglistrule
  750. echo 'LISTDIR=/home/$MYUSERNAME/Maildir/$MAILINGLIST' >> /usr/bin/mailinglistrule
  751. echo 'if [ ! -d "$LISTDIR" ]; then' >> /usr/bin/mailinglistrule
  752. echo ' mkdir -m 700 $LISTDIR' >> /usr/bin/mailinglistrule
  753. echo ' mkdir -m 700 $LISTDIR/tmp' >> /usr/bin/mailinglistrule
  754. echo ' mkdir -m 700 $LISTDIR/new' >> /usr/bin/mailinglistrule
  755. echo ' mkdir -m 700 $LISTDIR/cur' >> /usr/bin/mailinglistrule
  756. echo 'fi' >> /usr/bin/mailinglistrule
  757. echo 'chown -R $MYUSERNAME:$MYUSERNAME $LISTDIR' >> /usr/bin/mailinglistrule
  758. echo 'echo "" >> $PM' >> /usr/bin/mailinglistrule
  759. echo 'echo ":0" >> $PM' >> /usr/bin/mailinglistrule
  760. echo 'echo " * ^Subject:.*()\[$SUBJECTTAG\]" >> $PM' >> /usr/bin/mailinglistrule
  761. echo 'echo "$LISTDIR/new" >> $PM' >> /usr/bin/mailinglistrule
  762. echo 'chown $MYUSERNAME:$MYUSERNAME $PM' >> /usr/bin/mailinglistrule
  763. echo 'if [ ! -f "$MUTTRC" ]; then' >> /usr/bin/mailinglistrule
  764. echo ' cp /etc/Muttrc $MUTTRC' >> /usr/bin/mailinglistrule
  765. echo ' chown $MYUSERNAME:$MYUSERNAME $MUTTRC' >> /usr/bin/mailinglistrule
  766. echo 'fi' >> /usr/bin/mailinglistrule
  767. echo 'PROCMAILLOG=/home/$MYUSERNAME/log' >> /usr/bin/mailinglistrule
  768. echo 'if [ ! -d $PROCMAILLOG ]; then' >> /usr/bin/mailinglistrule
  769. echo ' mkdir $PROCMAILLOG' >> /usr/bin/mailinglistrule
  770. echo ' chown -R $MYUSERNAME:$MYUSERNAME $PROCMAILLOG' >> /usr/bin/mailinglistrule
  771. echo 'fi' >> /usr/bin/mailinglistrule
  772. chmod +x /usr/bin/mailinglistrule
  773. echo 'folders_for_mailing_lists' >> $COMPLETION_FILE
  774. }
  775. function folders_for_email_addresses {
  776. if grep -Fxq "folders_for_email_addresses" $COMPLETION_FILE; then
  777. return
  778. fi
  779. echo '#!/bin/bash' > /usr/bin/emailrule
  780. echo 'MYUSERNAME=$1' >> /usr/bin/emailrule
  781. echo 'EMAILADDRESS=$2' >> /usr/bin/emailrule
  782. echo 'MAILINGLIST=$3' >> /usr/bin/emailrule
  783. echo 'MUTTRC=/home/$MYUSERNAME/.muttrc' >> /usr/bin/emailrule
  784. echo 'PM=/home/$MYUSERNAME/.procmailrc' >> /usr/bin/emailrule
  785. echo 'LISTDIR=/home/$MYUSERNAME/Maildir/$MAILINGLIST' >> /usr/bin/emailrule
  786. echo 'if [ ! -d "$LISTDIR" ]; then' >> /usr/bin/emailrule
  787. echo ' mkdir -m 700 $LISTDIR' >> /usr/bin/emailrule
  788. echo ' mkdir -m 700 $LISTDIR/tmp' >> /usr/bin/emailrule
  789. echo ' mkdir -m 700 $LISTDIR/new' >> /usr/bin/emailrule
  790. echo ' mkdir -m 700 $LISTDIR/cur' >> /usr/bin/emailrule
  791. echo 'fi' >> /usr/bin/emailrule
  792. echo 'chown -R $MYUSERNAME:$MYUSERNAME $LISTDIR' >> /usr/bin/emailrule
  793. echo 'echo "" >> $PM' >> /usr/bin/emailrule
  794. echo 'echo ":0" >> $PM' >> /usr/bin/emailrule
  795. echo 'echo " * ^From: $EMAILADDRESS" >> $PM' >> /usr/bin/emailrule
  796. echo 'echo "$LISTDIR/new" >> $PM' >> /usr/bin/emailrule
  797. echo 'chown $MYUSERNAME:$MYUSERNAME $PM' >> /usr/bin/emailrule
  798. echo 'if [ ! -f "$MUTTRC" ]; then' >> /usr/bin/emailrule
  799. echo ' cp /etc/Muttrc $MUTTRC' >> /usr/bin/emailrule
  800. echo ' chown $MYUSERNAME:$MYUSERNAME $MUTTRC' >> /usr/bin/emailrule
  801. echo 'fi' >> /usr/bin/emailrule
  802. echo 'PROCMAILLOG=/home/$MYUSERNAME/log' >> /usr/bin/emailrule
  803. echo 'if [ ! -d $PROCMAILLOG ]; then' >> /usr/bin/emailrule
  804. echo ' mkdir $PROCMAILLOG' >> /usr/bin/emailrule
  805. echo ' chown -R $MYUSERNAME:$MYUSERNAME $PROCMAILLOG' >> /usr/bin/emailrule
  806. echo 'fi' >> /usr/bin/emailrule
  807. chmod +x /usr/bin/emailrule
  808. echo 'folders_for_email_addresses' >> $COMPLETION_FILE
  809. }
  810. function install_final {
  811. if grep -Fxq "install_final" $COMPLETION_FILE; then
  812. return
  813. fi
  814. echo 'install_final' >> $COMPLETION_FILE
  815. echo ''
  816. echo ' *** Freedombone installation is complete. Rebooting... ***'
  817. echo ''
  818. reboot
  819. }
  820. argument_checks
  821. remove_proprietary_repos
  822. configure_dns
  823. initial_setup
  824. install_editor
  825. change_login_message
  826. enable_backports
  827. update_the_kernel
  828. enable_zram
  829. random_number_generator
  830. configure_firewall
  831. configure_firewall_for_git
  832. configure_firewall_for_ssh
  833. configure_firewall_for_email
  834. set_your_domain_name
  835. time_synchronisation
  836. configure_internet_protocol
  837. configure_ssh
  838. regenerate_ssh_keys
  839. script_to_make_self_signed_certificates
  840. configure_email
  841. spam_filtering
  842. configure_imap
  843. configure_gpg
  844. email_client
  845. folders_for_mailing_lists
  846. folders_for_email_addresses
  847. install_final
  848. echo 'Freedombone installation is complete'