install-freedombone.sh 37KB

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