install-freedombone.sh 37KB

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