install-freedombone.sh 55KB

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