install-freedombone.sh 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. #!/bin/bash
  2. DOMAIN_NAME=$1
  3. MY_USERNAME=$2
  4. # Directory where source code is downloaded and compiled
  5. INSTALL_DIR=/root/build
  6. function initial_setup {
  7. apt-get -y update
  8. apt-get -y dist-upgrade
  9. apt-get -y install ca-certificates emacs24
  10. }
  11. function install_editor {
  12. update-alternatives --set editor /usr/bin/emacs24
  13. }
  14. function enable_backports {
  15. echo "deb http://ftp.us.debian.org/debian jessie-backports main" >> /etc/apt/sources.list
  16. }
  17. function remove_proprietary_repos {
  18. sed 's/ non-free//g' /etc/apt/sources.list > /tmp/sources.list
  19. cp -f /tmp/sources.list /etc/apt/sources.list
  20. }
  21. function update_the_kernel {
  22. cd /opt/scripts/tools
  23. ./update_kernel.sh --kernel v3.15.10-bone7
  24. }
  25. function enable_zram {
  26. echo "options zram num_devices=1" >> /etc/modprobe.d/zram.conf
  27. echo "#!/bin/bash" > /etc/init.d/zram
  28. echo "### BEGIN INIT INFO" >> /etc/init.d/zram
  29. echo "# Provides: zram" >> /etc/init.d/zram
  30. echo "# Required-Start:" >> /etc/init.d/zram
  31. echo "# Required-Stop:" >> /etc/init.d/zram
  32. echo "# Default-Start: 2 3 4 5" >> /etc/init.d/zram
  33. echo "# Default-Stop: 0 1 6" >> /etc/init.d/zram
  34. echo "# Short-Description: Increased Performance In Linux With zRam (Virtual Swap Compressed in RAM)" >> /etc/init.d/zram
  35. echo "# Description: Adapted from systemd scripts at https://github.com/mystilleef/FedoraZram" >> /etc/init.d/zram
  36. echo "### END INIT INFO" >> /etc/init.d/zram
  37. echo "start() {" >> /etc/init.d/zram
  38. echo " # get the number of CPUs" >> /etc/init.d/zram
  39. echo " num_cpus=$(grep -c processor /proc/cpuinfo)" >> /etc/init.d/zram
  40. echo " # if something goes wrong, assume we have 1" >> /etc/init.d/zram
  41. echo " [ \"$num_cpus\" != 0 ] || num_cpus=1" >> /etc/init.d/zram
  42. echo " # set decremented number of CPUs" >> /etc/init.d/zram
  43. echo " decr_num_cpus=$((num_cpus - 1))" >> /etc/init.d/zram
  44. echo " # get the amount of memory in the machine" >> /etc/init.d/zram
  45. echo " mem_total_kb=$(grep MemTotal /proc/meminfo | grep -E --only-matching '[[:digit:]]+')" >> /etc/init.d/zram
  46. echo " mem_total=$((mem_total_kb * 1024))" >> /etc/init.d/zram
  47. echo " # load dependency modules" >> /etc/init.d/zram
  48. echo " modprobe zram num_devices=$num_cpus" >> /etc/init.d/zram
  49. echo " # initialize the devices" >> /etc/init.d/zram
  50. echo " for i in $(seq 0 $decr_num_cpus); do" >> /etc/init.d/zram
  51. echo " echo $((mem_total / num_cpus)) > /sys/block/zram$i/disksize" >> /etc/init.d/zram
  52. echo " done" >> /etc/init.d/zram
  53. echo " # Creating swap filesystems" >> /etc/init.d/zram
  54. echo " for i in $(seq 0 $decr_num_cpus); do" >> /etc/init.d/zram
  55. echo " mkswap /dev/zram$i" >> /etc/init.d/zram
  56. echo " done" >> /etc/init.d/zram
  57. echo " # Switch the swaps on" >> /etc/init.d/zram
  58. echo " for i in $(seq 0 $decr_num_cpus); do" >> /etc/init.d/zram
  59. echo " swapon -p 100 /dev/zram$i" >> /etc/init.d/zram
  60. echo " done" >> /etc/init.d/zram
  61. echo "}" >> /etc/init.d/zram
  62. echo "stop() {" >> /etc/init.d/zram
  63. echo " # get the number of CPUs" >> /etc/init.d/zram
  64. echo " num_cpus=$(grep -c processor /proc/cpuinfo)" >> /etc/init.d/zram
  65. echo " # set decremented number of CPUs" >> /etc/init.d/zram
  66. echo " decr_num_cpus=$((num_cpus - 1))" >> /etc/init.d/zram
  67. echo " # Switching off swap" >> /etc/init.d/zram
  68. echo " for i in $(seq 0 $decr_num_cpus); do" >> /etc/init.d/zram
  69. echo " if [ \"$(grep /dev/zram$i /proc/swaps)\" != \"\" ]; then" >> /etc/init.d/zram
  70. echo " swapoff /dev/zram$i" >> /etc/init.d/zram
  71. echo " sleep 1" >> /etc/init.d/zram
  72. echo " fi" >> /etc/init.d/zram
  73. echo " done" >> /etc/init.d/zram
  74. echo " sleep 1" >> /etc/init.d/zram
  75. echo " rmmod zram" >> /etc/init.d/zram
  76. echo "}" >> /etc/init.d/zram
  77. echo "case \"$1\" in" >> /etc/init.d/zram
  78. echo " start)" >> /etc/init.d/zram
  79. echo " start" >> /etc/init.d/zram
  80. echo " ;;" >> /etc/init.d/zram
  81. echo " stop)" >> /etc/init.d/zram
  82. echo " stop" >> /etc/init.d/zram
  83. echo " ;;" >> /etc/init.d/zram
  84. echo " restart)" >> /etc/init.d/zram
  85. echo " stop" >> /etc/init.d/zram
  86. echo " sleep 3" >> /etc/init.d/zram
  87. echo " start" >> /etc/init.d/zram
  88. echo " ;;" >> /etc/init.d/zram
  89. echo " *)" >> /etc/init.d/zram
  90. echo " echo \"Usage: $0 {start|stop|restart}\"" >> /etc/init.d/zram
  91. echo " RETVAL=1" >> /etc/init.d/zram
  92. echo "esac" >> /etc/init.d/zram
  93. echo "exit $RETVAL" >> /etc/init.d/zram
  94. chmod +x /etc/init.d/zram
  95. update-rc.d zram defaults
  96. }
  97. function hardware_random_number_generator
  98. apt-get -y install rng-tools
  99. sed 's|#HRNGDEVICE=/dev/hwrng|HRNGDEVICE=/dev/hwrng|g' /etc/default/rng-tools > /tmp/rng-tools
  100. cp -f /tmp/rng-tools /etc/default/rng-tools
  101. service rng-tools restart
  102. }
  103. function configure_ssh {
  104. sed 's/PermitRootLogin without-password/PermitRootLogin no/g' /etc/ssh/sshd_config > /tmp/sshd_config
  105. cp -f /tmp/sshd_config /etc/ssh/sshd_config
  106. sed 's/X11Forwarding yes/X11Forwarding no/g' /etc/ssh/sshd_config > /tmp/sshd_config
  107. cp -f /tmp/sshd_config /etc/ssh/sshd_config
  108. sed 's/ServerKeyBits 1024/ServerKeyBits 4096/g' /etc/ssh/sshd_config > /tmp/sshd_config
  109. cp -f /tmp/sshd_config /etc/ssh/sshd_config
  110. sed 's/TCPKeepAlive yes/TCPKeepAlive no/g' /etc/ssh/sshd_config > /tmp/sshd_config
  111. cp -f /tmp/sshd_config /etc/ssh/sshd_config
  112. sed 's|HostKey /etc/ssh/ssh_host_dsa_key|#HostKey /etc/ssh/ssh_host_dsa_key|g' /etc/ssh/sshd_config > /tmp/sshd_config
  113. cp -f /tmp/sshd_config /etc/ssh/sshd_config
  114. sed 's|HostKey /etc/ssh/ssh_host_ecdsa_key|#HostKey /etc/ssh/ssh_host_ecdsa_key|g' /etc/ssh/sshd_config > /tmp/sshd_config
  115. cp -f /tmp/sshd_config /etc/ssh/sshd_config
  116. echo "ClientAliveInterval 60" >> /etc/ssh/sshd_config
  117. echo "ClientAliveCountMax 3" >> /etc/ssh/sshd_config
  118. echo "Ciphers aes256-ctr,aes128-ctr" >> /etc/ssh/sshd_config
  119. echo "MACs hmac-sha2-512,hmac-sha2-256,hmac-ripemd160
  120. KexAlgorithms diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1" >> /etc/ssh/sshd_config
  121. service ssh restart
  122. apt-get -y install fail2ban
  123. }
  124. function regenerate_ssh_keys {
  125. rm -f /etc/ssh/ssh_host_*
  126. dpkg-reconfigure openssh-server
  127. service ssh restart
  128. }
  129. function set_your_domain_name {
  130. echo "$DOMAIN_NAME" > /etc/hostname
  131. hostname $DOMAIN_NAME
  132. echo "127.0.1.1 $DOMAIN_NAME" >> /etc/hosts
  133. }
  134. function time_synchronisation {
  135. apt-get -y install build-essential automake git pkg-config autoconf libtool libssl-dev
  136. apt-get -y remove ntpdate
  137. mkdir $INSTALL_DIR
  138. cd $INSTALL_DIR
  139. git clone https://github.com/ioerror/tlsdate.git
  140. cd $INSTALL_DIR/tlsdate
  141. ./autogen.sh
  142. ./configure
  143. make
  144. make install
  145. echo "#!/bin/bash" > /usr/bin/updatedate
  146. echo "TIMESOURCE=google.com" >> /usr/bin/updatedate
  147. echo "TIMESOURCE2=www.ptb.de" >> /usr/bin/updatedate
  148. echo "LOGFILE=/var/log/tlsdate.log" >> /usr/bin/updatedate
  149. echo "TIMEOUT=5" >> /usr/bin/updatedate
  150. echo "EMAIL=$MY_USERNAME@$DOMAIN_NAME" >> /usr/bin/updatedate
  151. echo "# File which contains the previous date as a number" >> /usr/bin/updatedate
  152. echo "BEFORE_DATE_FILE=/var/log/tlsdateprevious.txt" >> /usr/bin/updatedate
  153. echo "# File which contains the previous date as a string" >> /usr/bin/updatedate
  154. echo "BEFORE_FULLDATE_FILE=/var/log/tlsdate.txt" >> /usr/bin/updatedate
  155. echo "DATE_BEFORE=$(date)" >> /usr/bin/updatedate
  156. echo "BEFORE=$(date -d "$Y-$M-$D" '+%s')" >> /usr/bin/updatedate
  157. echo "BACKWARDS_BETWEEN=0" >> /usr/bin/updatedate
  158. echo "# If the date was previously set" >> /usr/bin/updatedate
  159. echo "if [[ -f \"$BEFORE_DATE_FILE\" ]]; then" >> /usr/bin/updatedate
  160. echo " BEFORE_FILE=$(cat $BEFORE_DATE_FILE)" >> /usr/bin/updatedate
  161. echo " BEFORE_FULLDATE=$(cat $BEFORE_FULLDATE_FILE)" >> /usr/bin/updatedate
  162. echo " # is the date going backwards?" >> /usr/bin/updatedate
  163. echo " if (( BEFORE_FILE > BEFORE )); then" >> /usr/bin/updatedate
  164. echo " echo -n \"Date went backwards between tlsdate updates. \" >> $LOGFILE" >> /usr/bin/updatedate
  165. echo " echo -n \"$BEFORE_FILE > $BEFORE, \" >> $LOGFILE" >> /usr/bin/updatedate
  166. echo " echo \"$BEFORE_FULLDATE > $DATE_BEFORE\" >> $LOGFILE" >> /usr/bin/updatedate
  167. echo " # Send a warning email" > /usr/bin/updatedate
  168. echo " echo $(tail $LOGFILE -n 2) | mail -s \"tlsdate anomaly\" $EMAIL" >> /usr/bin/updatedate
  169. echo " # Try another time source" >> /usr/bin/updatedate
  170. echo " TIMESOURCE=$TIMESOURCE2" >> /usr/bin/updatedate
  171. echo " # try running without any parameters" >> /usr/bin/updatedate
  172. echo " tlsdate >> $LOGFILE" >> /usr/bin/updatedate
  173. echo " BACKWARDS_BETWEEN=1" >> /usr/bin/updatedate
  174. echo " fi" >> /usr/bin/updatedate
  175. echo "fi" >> /usr/bin/updatedate
  176. echo "# Set the date" >> /usr/bin/updatedate
  177. echo "/usr/bin/timeout $TIMEOUT tlsdate -l -t -H $TIMESOURCE -p 443 >> $LOGFILE" >> /usr/bin/updatedate
  178. echo "DATE_AFTER=$(date)" >> /usr/bin/updatedate
  179. echo "AFTER=$(date -d "$Y-$M-$D" '+%s')" >> /usr/bin/updatedate
  180. echo "# After setting the date did it go backwards?" >> /usr/bin/updatedate
  181. echo "if (( AFTER < BEFORE )); then" >> /usr/bin/updatedate
  182. echo " echo \"Incorrect date: $DATE_BEFORE -> $DATE_AFTER\" >> $LOGFILE" >> /usr/bin/updatedate
  183. echo " # Send a warning email" >> /usr/bin/updatedate
  184. echo " echo $(tail $LOGFILE -n 2) | mail -s \"tlsdate anomaly\" $EMAIL" >> /usr/bin/updatedate
  185. echo " # Try resetting the date from another time source" >> /usr/bin/updatedate
  186. echo " /usr/bin/timeout $TIMEOUT tlsdate -l -t -H $TIMESOURCE2 -p 443 >> $LOGFILE" >> /usr/bin/updatedate
  187. echo " DATE_AFTER=$(date)" >> /usr/bin/updatedate
  188. echo " AFTER=$(date -d "$Y-$M-$D" '+%s')" >> /usr/bin/updatedate
  189. echo "else" >> /usr/bin/updatedate
  190. echo " echo -n $TIMESOURCE >> $LOGFILE" >> /usr/bin/updatedate
  191. echo " if [[ -f \"$BEFORE_DATE_FILE\" ]]; then" >> /usr/bin/updatedate
  192. echo " echo -n \" \" >> $LOGFILE" >> /usr/bin/updatedate
  193. echo " echo -n $BEFORE_FILE >> $LOGFILE" >> /usr/bin/updatedate
  194. echo " fi" >> /usr/bin/updatedate
  195. echo " echo -n \" \" >> $LOGFILE" >> /usr/bin/updatedate
  196. echo " echo -n $BEFORE >> $LOGFILE" >> /usr/bin/updatedate
  197. echo " echo -n \" \" >> $LOGFILE" >> /usr/bin/updatedate
  198. echo " echo -n $AFTER >> $LOGFILE" >> /usr/bin/updatedate
  199. echo " echo -n \" \" >> $LOGFILE" >> /usr/bin/updatedate
  200. echo " echo $DATE_AFTER >> $LOGFILE" >> /usr/bin/updatedate
  201. echo "fi" >> /usr/bin/updatedate
  202. echo "# Log the last date" >> /usr/bin/updatedate
  203. echo "if [ BACKWARDS_BETWEEN == 0 ]; then" >> /usr/bin/updatedate
  204. echo " echo \"$AFTER\" > $BEFORE_DATE_FILE" >> /usr/bin/updatedate
  205. echo " echo \"$DATE_AFTER\" > $BEFORE_FULLDATE_FILE" >> /usr/bin/updatedate
  206. echo " exit 0" >> /usr/bin/updatedate
  207. echo "else" >> /usr/bin/updatedate
  208. echo " exit 1" >> /usr/bin/updatedate
  209. echo "fi" >> /usr/bin/updatedate
  210. chmod +x /usr/bin/updatedate
  211. echo "*/15 * * * * root /usr/bin/updatedate" >> /etc/crontab
  212. service cron restart
  213. echo "#!/bin/bash" > /etc/init.d/tlsdate
  214. echo "# /etc/init.d/tlsdate" >> /etc/init.d/tlsdate
  215. echo "### BEGIN INIT INFO" >> /etc/init.d/tlsdate
  216. echo "# Provides: tlsdate" >> /etc/init.d/tlsdate
  217. echo "# Required-Start: $remote_fs $syslog" >> /etc/init.d/tlsdate
  218. echo "# Required-Stop: $remote_fs $syslog" >> /etc/init.d/tlsdate
  219. echo "# Default-Start: 2 3 4 5" >> /etc/init.d/tlsdate
  220. echo "# Default-Stop: 0 1 6" >> /etc/init.d/tlsdate
  221. echo "# Short-Description: Initially calls tlsdate with the timewarp option" >> /etc/init.d/tlsdate
  222. echo "# Description: Initially calls tlsdate with the timewarp option" >> /etc/init.d/tlsdate
  223. echo "### END INIT INFO" >> /etc/init.d/tlsdate
  224. echo "# Author: Bob Mottram <bob@robotics.uk.to>" >> /etc/init.d/tlsdate
  225. echo "PATH='/usr/local/sbin:/usr/local/bin:/usr/bin:/sbin:/usr/sbin:/bin'" >> /etc/init.d/tlsdate
  226. echo "LOGFILE=\"/var/log/tlsdate.log\"" >> /etc/init.d/tlsdate
  227. echo "TLSDATECOMMAND=\"tlsdate --timewarp -l -H www.ptb.de -p 443 >> $LOGFILE\"" >> /etc/init.d/tlsdate
  228. echo "#Start-Stop here" >> /etc/init.d/tlsdate
  229. echo "case "$1" in" >> /etc/init.d/tlsdate
  230. echo " start)" >> /etc/init.d/tlsdate
  231. echo " echo "tlsdate started"" >> /etc/init.d/tlsdate
  232. echo " $TLSDATECOMMAND" >> /etc/init.d/tlsdate
  233. echo " ;;" >> /etc/init.d/tlsdate
  234. echo " stop)" >> /etc/init.d/tlsdate
  235. echo " echo "tlsdate stopped"" >> /etc/init.d/tlsdate
  236. echo " ;;" >> /etc/init.d/tlsdate
  237. echo " restart)" >> /etc/init.d/tlsdate
  238. echo " echo "tlsdate restarted"" >> /etc/init.d/tlsdate
  239. echo " $TLSDATECOMMAND" >> /etc/init.d/tlsdate
  240. echo " ;;" >> /etc/init.d/tlsdate
  241. echo " *)" >> /etc/init.d/tlsdate
  242. echo " echo "Usage: $0 {start|stop|restart}"" >> /etc/init.d/tlsdate
  243. echo " exit 1" >> /etc/init.d/tlsdate
  244. echo " ;;" >> /etc/init.d/tlsdate
  245. echo "esac" >> /etc/init.d/tlsdate
  246. echo "exit 0" >> /etc/init.d/tlsdate
  247. chmod +x /etc/init.d/tlsdate
  248. update-rc.d tlsdate defaults
  249. }
  250. function defend_against_port_scanning
  251. apt-get -y install portsentry
  252. }
  253. function configure_firewall {
  254. iptables -P INPUT ACCEPT
  255. ip6tables -P INPUT ACCEPT
  256. iptables -F
  257. ip6tables -F
  258. iptables -X
  259. ip6tables -X
  260. iptables -P INPUT DROP
  261. ip6tables -P INPUT DROP
  262. }
  263. function configure_firewall_for_email {
  264. iptables -A INPUT -i eth0 -p tcp --dport 22 -j ACCEPT
  265. iptables -A INPUT -i eth0 -p tcp --dport 25 -j ACCEPT
  266. iptables -A INPUT -i eth0 -p tcp --dport 587 -j ACCEPT
  267. iptables -A INPUT -i eth0 -p tcp --dport 465 -j ACCEPT
  268. iptables -A INPUT -i eth0 -p tcp --dport 993 -j ACCEPT
  269. }
  270. function save_firewall_settings {
  271. # TODO
  272. }
  273. function configure_internet_protocol {
  274. sed "s/#net.ipv4.tcp_syncookies=1/net.ipv4.tcp_syncookies=1/g" /etc/sysctl.conf > /tmp/sysctl.conf
  275. cp -f /tmp/sysctl.conf /etc/sysctl.conf
  276. sed "s/#net.ipv4.conf.all.accept_redirects = 0/net.ipv4.conf.all.accept_redirects = 0/g" /etc/sysctl.conf > /tmp/sysctl.conf
  277. cp -f /tmp/sysctl.conf /etc/sysctl.conf
  278. sed "s/#net.ipv6.conf.all.accept_redirects = 0/net.ipv6.conf.all.accept_redirects = 0/g" /etc/sysctl.conf > /tmp/sysctl.conf
  279. cp -f /tmp/sysctl.conf /etc/sysctl.conf
  280. sed "s/#net.ipv4.conf.all.send_redirects = 0/net.ipv4.conf.all.send_redirects = 0/g" /etc/sysctl.conf > /tmp/sysctl.conf
  281. cp -f /tmp/sysctl.conf /etc/sysctl.conf
  282. sed "s/#net.ipv4.conf.all.accept_source_route = 0/net.ipv4.conf.all.accept_source_route = 0/g" /etc/sysctl.conf > /tmp/sysctl.conf
  283. cp -f /tmp/sysctl.conf /etc/sysctl.conf
  284. sed "s/#net.ipv6.conf.all.accept_source_route = 0/net.ipv6.conf.all.accept_source_route = 0/g" /etc/sysctl.conf > /tmp/sysctl.conf
  285. cp -f /tmp/sysctl.conf /etc/sysctl.conf
  286. sed "s/#net.ipv4.conf.default.rp_filter=1/net.ipv4.conf.default.rp_filter=1/g" /etc/sysctl.conf > /tmp/sysctl.conf
  287. cp -f /tmp/sysctl.conf /etc/sysctl.conf
  288. sed "s/#net.ipv4.conf.all.rp_filter=1/net.ipv4.conf.all.rp_filter=1/g" /etc/sysctl.conf > /tmp/sysctl.conf
  289. cp -f /tmp/sysctl.conf /etc/sysctl.conf
  290. sed "s/#net.ipv4.ip_forward=1/net.ipv4.ip_forward=0/g" /etc/sysctl.conf > /tmp/sysctl.conf
  291. cp -f /tmp/sysctl.conf /etc/sysctl.conf
  292. sed "s/#net.ipv6.conf.all.forwarding=1/net.ipv6.conf.all.forwarding=0/g" /etc/sysctl.conf > /tmp/sysctl.conf
  293. cp -f /tmp/sysctl.conf /etc/sysctl.conf
  294. echo "# ignore pings" >> /etc/sysctl.conf
  295. echo "net.ipv4.icmp_echo_ignore_all = 1" >> /etc/sysctl.conf
  296. echo "net.ipv6.icmp_echo_ignore_all = 1" >> /etc/sysctl.conf
  297. echo "# disable ipv6" >> /etc/sysctl.conf
  298. echo "net.ipv6.conf.all.disable_ipv6 = 1" >> /etc/sysctl.conf
  299. echo "net.ipv4.tcp_synack_retries = 2" >> /etc/sysctl.conf
  300. echo "net.ipv4.tcp_syn_retries = 1" >> /etc/sysctl.conf
  301. echo "# keepalive" >> /etc/sysctl.conf
  302. echo "net.ipv4.tcp_keepalive_probes = 9" >> /etc/sysctl.conf
  303. echo "net.ipv4.tcp_keepalive_intvl = 75" >> /etc/sysctl.conf
  304. echo "net.ipv4.tcp_keepalive_time = 7200" >> /etc/sysctl.conf
  305. }
  306. function script_to_make_self_signed_certificates {
  307. echo "#!/bin/bash" > /usr/bin/makecert
  308. echo "HOSTNAME=$1" >> /usr/bin/makecert
  309. echo "COUNTRY_CODE=\"US\"" >> /usr/bin/makecert
  310. echo "AREA=\"Free Speech Zone\"" >> /usr/bin/makecert
  311. echo "LOCATION=\"Freedomville\"" >> /usr/bin/makecert
  312. echo "ORGANISATION=\"Freedombone\"" >> /usr/bin/makecert
  313. echo "UNIT=\"Freedombone Unit\"" >> /usr/bin/makecert
  314. echo "if ! which openssl > /dev/null ;then" >> /usr/bin/makecert
  315. echo " echo "$0: openssl is not installed, exiting" 1>&2" >> /usr/bin/makecert
  316. echo " exit 1" >> /usr/bin/makecert
  317. echo "fi" >> /usr/bin/makecert
  318. 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
  319. echo "openssl dhparam -check -text -5 1024 -out /etc/ssl/certs/$HOSTNAME.dhparam" >> /usr/bin/makecert
  320. echo "chmod 400 /etc/ssl/private/$HOSTNAME.key" >> /usr/bin/makecert
  321. echo "chmod 640 /etc/ssl/certs/$HOSTNAME.crt" >> /usr/bin/makecert
  322. echo "chmod 640 /etc/ssl/certs/$HOSTNAME.dhparam" >> /usr/bin/makecert
  323. echo "/etc/init.d/nginx reload" >> /usr/bin/makecert
  324. echo "# add the public certificate to a separate directory" >> /usr/bin/makecert
  325. echo "# so that we can redistribute it easily" >> /usr/bin/makecert
  326. echo "if [ ! -d /etc/ssl/mycerts ]; then" >> /usr/bin/makecert
  327. echo " mkdir /etc/ssl/mycerts" >> /usr/bin/makecert
  328. echo "fi" >> /usr/bin/makecert
  329. echo "cp /etc/ssl/certs/$HOSTNAME.crt /etc/ssl/mycerts" >> /usr/bin/makecert
  330. echo "# Create a bundle of your certificates" >> /usr/bin/makecert
  331. echo "cat /etc/ssl/mycerts/*.crt > /etc/ssl/freedombone-bundle.crt" >> /usr/bin/makecert
  332. echo "tar -czvf /etc/ssl/freedombone-certs.tar.gz /etc/ssl/mycerts/*.crt" >> /usr/bin/makecert
  333. chmod +x /usr/bin/makecert
  334. }
  335. function configure_email {
  336. apt-get -y remove postfix
  337. apt-get -y install exim4 sasl2-bin swaks libnet-ssleay-perl procmail
  338. echo "dc_eximconfig_configtype='internet'" > /etc/exim4/update-exim4.conf.conf
  339. echo "dc_other_hostnames='$DOMAIN_NAME'" >> /etc/exim4/update-exim4.conf.conf
  340. echo "dc_local_interfaces=''" >> /etc/exim4/update-exim4.conf.conf
  341. echo "dc_readhost=''" >> /etc/exim4/update-exim4.conf.conf
  342. echo "dc_relay_domains=''" >> /etc/exim4/update-exim4.conf.conf
  343. echo "dc_minimaldns='false'" >> /etc/exim4/update-exim4.conf.conf
  344. echo "dc_relay_nets='192.168.1.0/24'" >> /etc/exim4/update-exim4.conf.conf
  345. echo "dc_smarthost=''" >> /etc/exim4/update-exim4.conf.conf
  346. echo "CFILEMODE='644'" >> /etc/exim4/update-exim4.conf.conf
  347. echo "dc_use_split_config='false'" >> /etc/exim4/update-exim4.conf.conf
  348. echo "dc_hide_mailname=''" >> /etc/exim4/update-exim4.conf.conf
  349. echo "dc_mailname_in_oh='true'" >> /etc/exim4/update-exim4.conf.conf
  350. echo "dc_localdelivery='maildir_home'" >> /etc/exim4/update-exim4.conf.conf
  351. update-exim4.conf
  352. sed "s/START=no/START=yes/g" /etc/default/saslauthd > /tmp/saslauthd
  353. cp -f /tmp/saslauthd /etc/default/saslauthd
  354. /etc/init.d/saslauthd start
  355. makecert exim
  356. mv /etc/ssl/private/exim.key /etc/exim4
  357. mv /etc/ssl/certs/exim.crt /etc/exim4
  358. mv /etc/ssl/certs/exim.dhparam /etc/exim4
  359. chown root:Debian-exim /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
  360. chmod 640 /etc/exim4/exim.key /etc/exim4/exim.crt /etc/exim4/exim.dhparam
  361. #editor /etc/exim4/exim4.conf.template
  362. }
  363. initial_setup
  364. install_editor
  365. enable_backports
  366. remove_proprietary_repos
  367. update_the_kernel
  368. enable_zram
  369. hardware_random_number_generator
  370. configure_ssh
  371. regenerate_ssh_keys
  372. set_your_domain_name
  373. time_synchronisation
  374. defend_against_port_scanning
  375. configure_firewall
  376. configure_firewall_for_email
  377. save_firewall_settings
  378. configure_internet_protocol
  379. script_to_make_self_signed_certificates
  380. configure_email