install-freedombone.sh 43KB

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