install-freedombone.sh 36KB

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