install-freedombone.sh 50KB

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