install-freedombone.sh 44KB

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