install-freedombone.sh 37KB

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