install-freedombone.sh 51KB

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