Selaa lähdekoodia

Keep track of installation completion

Bob Mottram 10 vuotta sitten
vanhempi
commit
75302efe5f
1 muutettua tiedostoa jossa 99 lisäystä ja 0 poistoa
  1. 99
    0
      install-freedombone.sh

+ 99
- 0
install-freedombone.sh Näytä tiedosto

13
 
13
 
14
 export DEBIAN_FRONTEND=noninteractive
14
 export DEBIAN_FRONTEND=noninteractive
15
 
15
 
16
+# File which keeps track of what has already been installed
17
+COMPLETION_FILE=/root/freedombone-completed.txt
18
+if [ ! -f $COMPLETION_FILE ]; then
19
+	touch $COMPLETION_FILE
20
+fi
21
+
16
 function argument_checks {
22
 function argument_checks {
17
   if [ ! $DOMAIN_NAME ]; then
23
   if [ ! $DOMAIN_NAME ]; then
18
 	  echo "Please specify your domain name"
24
 	  echo "Please specify your domain name"
25
 }
31
 }
26
 
32
 
27
 function remove_proprietary_repos {
33
 function remove_proprietary_repos {
34
+  if [ grep -Fxq "remove_proprietary_repos" $COMPLETION_FILE ]; then
35
+	  return
36
+  fi
28
   sed -i 's/ non-free//g' /etc/apt/sources.list
37
   sed -i 's/ non-free//g' /etc/apt/sources.list
38
+  echo 'remove_proprietary_repos' >> $COMPLETION_FILE
29
 }
39
 }
30
 
40
 
31
 function initial_setup {
41
 function initial_setup {
42
+  if [ grep -Fxq "initial_setup" $COMPLETION_FILE ]; then
43
+	  return
44
+  fi
32
   apt-get -y update
45
   apt-get -y update
33
   apt-get -y dist-upgrade
46
   apt-get -y dist-upgrade
34
   apt-get -y install ca-certificates emacs24
47
   apt-get -y install ca-certificates emacs24
48
+  echo 'initial_setup' >> $COMPLETION_FILE
35
 }
49
 }
36
 
50
 
37
 function install_editor {
51
 function install_editor {
52
+  if [ grep -Fxq "install_editor" $COMPLETION_FILE ]; then
53
+	  return
54
+  fi
38
   update-alternatives --set editor /usr/bin/emacs24
55
   update-alternatives --set editor /usr/bin/emacs24
56
+  echo 'install_editor' >> $COMPLETION_FILE
39
 }
57
 }
40
 
58
 
41
 function enable_backports {
59
 function enable_backports {
60
+  if [ grep -Fxq "enable_backports" $COMPLETION_FILE ]; then
61
+	  return
62
+  fi
42
   echo "deb http://ftp.us.debian.org/debian jessie-backports main" >> /etc/apt/sources.list
63
   echo "deb http://ftp.us.debian.org/debian jessie-backports main" >> /etc/apt/sources.list
64
+  echo 'enable_backports' >> $COMPLETION_FILE
43
 }
65
 }
44
 
66
 
45
 function update_the_kernel {
67
 function update_the_kernel {
68
+  if [ grep -Fxq "update_the_kernel" $COMPLETION_FILE ]; then
69
+	  return
70
+  fi
46
   cd /opt/scripts/tools
71
   cd /opt/scripts/tools
47
   ./update_kernel.sh --kernel $KERNEL_VERSION
72
   ./update_kernel.sh --kernel $KERNEL_VERSION
73
+  echo 'update_the_kernel' >> $COMPLETION_FILE
48
 }
74
 }
49
 
75
 
50
 function enable_zram {
76
 function enable_zram {
77
+  if [ grep -Fxq "enable_zram" $COMPLETION_FILE ]; then
78
+	  return
79
+  fi
51
   echo "options zram num_devices=1" >> /etc/modprobe.d/zram.conf
80
   echo "options zram num_devices=1" >> /etc/modprobe.d/zram.conf
52
   echo '#!/bin/bash' > /etc/init.d/zram
81
   echo '#!/bin/bash' > /etc/init.d/zram
53
   echo '### BEGIN INIT INFO' >> /etc/init.d/zram
82
   echo '### BEGIN INIT INFO' >> /etc/init.d/zram
118
   echo 'exit $RETVAL' >> /etc/init.d/zram
147
   echo 'exit $RETVAL' >> /etc/init.d/zram
119
   chmod +x /etc/init.d/zram
148
   chmod +x /etc/init.d/zram
120
   update-rc.d zram defaults
149
   update-rc.d zram defaults
150
+  echo 'enable_zram' >> $COMPLETION_FILE
121
 }
151
 }
122
 
152
 
123
 function random_number_generator {
153
 function random_number_generator {
154
+  if [ grep -Fxq "random_number_generator" $COMPLETION_FILE ]; then
155
+	  return
156
+  fi
124
   if [ $USE_HWRNG == "yes" ]; then
157
   if [ $USE_HWRNG == "yes" ]; then
125
     apt-get -y install rng-tools
158
     apt-get -y install rng-tools
126
     sed -i 's|#HRNGDEVICE=/dev/hwrng|HRNGDEVICE=/dev/hwrng|g' /etc/default/rng-tools
159
     sed -i 's|#HRNGDEVICE=/dev/hwrng|HRNGDEVICE=/dev/hwrng|g' /etc/default/rng-tools
131
   else
164
   else
132
 	apt-get -y install haveged
165
 	apt-get -y install haveged
133
   fi
166
   fi
167
+  echo 'random_number_generator' >> $COMPLETION_FILE
134
 }
168
 }
135
 
169
 
136
 function configure_ssh {
170
 function configure_ssh {
171
+  if [ grep -Fxq "configure_ssh" $COMPLETION_FILE ]; then
172
+	  return
173
+  fi
137
   sed -i "s/Port 22/Port $SSH_PORT/g" /etc/ssh/sshd_config
174
   sed -i "s/Port 22/Port $SSH_PORT/g" /etc/ssh/sshd_config
138
   sed -i 's/PermitRootLogin without-password/PermitRootLogin no/g' /etc/ssh/sshd_config
175
   sed -i 's/PermitRootLogin without-password/PermitRootLogin no/g' /etc/ssh/sshd_config
139
   sed -i 's/X11Forwarding yes/X11Forwarding no/g' /etc/ssh/sshd_config
176
   sed -i 's/X11Forwarding yes/X11Forwarding no/g' /etc/ssh/sshd_config
148
   KexAlgorithms diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1' >> /etc/ssh/sshd_config
185
   KexAlgorithms diffie-hellman-group-exchange-sha256,diffie-hellman-group14-sha1,diffie-hellman-group-exchange-sha1' >> /etc/ssh/sshd_config
149
   service ssh restart
186
   service ssh restart
150
   apt-get -y install fail2ban
187
   apt-get -y install fail2ban
188
+  echo 'configure_ssh' >> $COMPLETION_FILE
151
 }
189
 }
152
 
190
 
153
 function regenerate_ssh_keys {
191
 function regenerate_ssh_keys {
192
+  if [ grep -Fxq "regenerate_ssh_keys" $COMPLETION_FILE ]; then
193
+	  return
194
+  fi
154
   rm -f /etc/ssh/ssh_host_*
195
   rm -f /etc/ssh/ssh_host_*
155
   dpkg-reconfigure openssh-server
196
   dpkg-reconfigure openssh-server
156
   service ssh restart
197
   service ssh restart
198
+  echo 'regenerate_ssh_keys' >> $COMPLETION_FILE
157
 }
199
 }
158
 
200
 
159
 function set_your_domain_name {
201
 function set_your_domain_name {
202
+  if [ grep -Fxq "set_your_domain_name" $COMPLETION_FILE ]; then
203
+	  return
204
+  fi
160
   echo "$DOMAIN_NAME" > /etc/hostname
205
   echo "$DOMAIN_NAME" > /etc/hostname
161
   hostname $DOMAIN_NAME
206
   hostname $DOMAIN_NAME
162
   echo "127.0.1.1  $DOMAIN_NAME" >> /etc/hosts
207
   echo "127.0.1.1  $DOMAIN_NAME" >> /etc/hosts
208
+  echo 'set_your_domain_name' >> $COMPLETION_FILE
163
 }
209
 }
164
 
210
 
165
 function time_synchronisation {
211
 function time_synchronisation {
212
+  if [ grep -Fxq "time_synchronisation" $COMPLETION_FILE ]; then
213
+	  return
214
+  fi
166
   apt-get -y install build-essential automake git pkg-config autoconf libtool libssl-dev
215
   apt-get -y install build-essential automake git pkg-config autoconf libtool libssl-dev
167
   apt-get -y remove ntpdate
216
   apt-get -y remove ntpdate
168
   mkdir $INSTALL_DIR
217
   mkdir $INSTALL_DIR
279
   echo 'exit 0' >> /etc/init.d/tlsdate
328
   echo 'exit 0' >> /etc/init.d/tlsdate
280
   chmod +x /etc/init.d/tlsdate
329
   chmod +x /etc/init.d/tlsdate
281
   update-rc.d tlsdate defaults
330
   update-rc.d tlsdate defaults
331
+  echo 'time_synchronisation' >> $COMPLETION_FILE
282
 }
332
 }
283
 
333
 
284
 function configure_firewall {
334
 function configure_firewall {
335
+  if [ grep -Fxq "configure_firewall" $COMPLETION_FILE ]; then
336
+	  return
337
+  fi
285
   iptables -P INPUT ACCEPT
338
   iptables -P INPUT ACCEPT
286
   ip6tables -P INPUT ACCEPT
339
   ip6tables -P INPUT ACCEPT
287
   iptables -F
340
   iptables -F
290
   ip6tables -X
343
   ip6tables -X
291
   iptables -P INPUT DROP
344
   iptables -P INPUT DROP
292
   ip6tables -P INPUT DROP
345
   ip6tables -P INPUT DROP
346
+  echo 'configure_firewall' >> $COMPLETION_FILE
293
 }
347
 }
294
 
348
 
295
 function configure_firewall_for_ssh {
349
 function configure_firewall_for_ssh {
350
+  if [ grep -Fxq "configure_firewall_for_ssh" $COMPLETION_FILE ]; then
351
+	  return
352
+  fi
296
   iptables -A INPUT -i eth0 -p tcp --dport $SSH_PORT -j ACCEPT
353
   iptables -A INPUT -i eth0 -p tcp --dport $SSH_PORT -j ACCEPT
354
+  echo 'configure_firewall_for_ssh' >> $COMPLETION_FILE
297
 }
355
 }
298
 
356
 
299
 function configure_firewall_for_email {
357
 function configure_firewall_for_email {
358
+  if [ grep -Fxq "configure_firewall_for_email" $COMPLETION_FILE ]; then
359
+	  return
360
+  fi
300
   iptables -A INPUT -i eth0 -p tcp --dport 25 -j ACCEPT
361
   iptables -A INPUT -i eth0 -p tcp --dport 25 -j ACCEPT
301
   iptables -A INPUT -i eth0 -p tcp --dport 587 -j ACCEPT
362
   iptables -A INPUT -i eth0 -p tcp --dport 587 -j ACCEPT
302
   iptables -A INPUT -i eth0 -p tcp --dport 465 -j ACCEPT
363
   iptables -A INPUT -i eth0 -p tcp --dport 465 -j ACCEPT
303
   iptables -A INPUT -i eth0 -p tcp --dport 993 -j ACCEPT
364
   iptables -A INPUT -i eth0 -p tcp --dport 993 -j ACCEPT
365
+  echo 'configure_firewall_for_email' >> $COMPLETION_FILE
304
 }
366
 }
305
 
367
 
306
 function save_firewall_settings {
368
 function save_firewall_settings {
313
 }
375
 }
314
 
376
 
315
 function configure_internet_protocol {
377
 function configure_internet_protocol {
378
+  if [ grep -Fxq "configure_internet_protocol" $COMPLETION_FILE ]; then
379
+	  return
380
+  fi
316
   sed -i "s/#net.ipv4.tcp_syncookies=1/net.ipv4.tcp_syncookies=1/g" /etc/sysctl.conf
381
   sed -i "s/#net.ipv4.tcp_syncookies=1/net.ipv4.tcp_syncookies=1/g" /etc/sysctl.conf
317
   sed -i "s/#net.ipv4.conf.all.accept_redirects = 0/net.ipv4.conf.all.accept_redirects = 0/g" /etc/sysctl.conf
382
   sed -i "s/#net.ipv4.conf.all.accept_redirects = 0/net.ipv4.conf.all.accept_redirects = 0/g" /etc/sysctl.conf
318
   sed -i "s/#net.ipv6.conf.all.accept_redirects = 0/net.ipv6.conf.all.accept_redirects = 0/g" /etc/sysctl.conf
383
   sed -i "s/#net.ipv6.conf.all.accept_redirects = 0/net.ipv6.conf.all.accept_redirects = 0/g" /etc/sysctl.conf
334
   echo 'net.ipv4.tcp_keepalive_probes = 9' >> /etc/sysctl.conf
399
   echo 'net.ipv4.tcp_keepalive_probes = 9' >> /etc/sysctl.conf
335
   echo 'net.ipv4.tcp_keepalive_intvl = 75' >> /etc/sysctl.conf
400
   echo 'net.ipv4.tcp_keepalive_intvl = 75' >> /etc/sysctl.conf
336
   echo 'net.ipv4.tcp_keepalive_time = 7200' >> /etc/sysctl.conf
401
   echo 'net.ipv4.tcp_keepalive_time = 7200' >> /etc/sysctl.conf
402
+  echo 'configure_internet_protocol' >> $COMPLETION_FILE
337
 }
403
 }
338
 
404
 
339
 function script_to_make_self_signed_certificates {
405
 function script_to_make_self_signed_certificates {
406
+  if [ grep -Fxq "script_to_make_self_signed_certificates" $COMPLETION_FILE ]; then
407
+	  return
408
+  fi
340
   echo '#!/bin/bash' > /usr/bin/makecert
409
   echo '#!/bin/bash' > /usr/bin/makecert
341
   echo 'HOSTNAME=$1' >> /usr/bin/makecert
410
   echo 'HOSTNAME=$1' >> /usr/bin/makecert
342
   echo 'COUNTRY_CODE="US"' >> /usr/bin/makecert
411
   echo 'COUNTRY_CODE="US"' >> /usr/bin/makecert
364
   echo 'cat /etc/ssl/mycerts/*.crt > /etc/ssl/freedombone-bundle.crt' >> /usr/bin/makecert
433
   echo 'cat /etc/ssl/mycerts/*.crt > /etc/ssl/freedombone-bundle.crt' >> /usr/bin/makecert
365
   echo 'tar -czvf /etc/ssl/freedombone-certs.tar.gz /etc/ssl/mycerts/*.crt' >> /usr/bin/makecert
434
   echo 'tar -czvf /etc/ssl/freedombone-certs.tar.gz /etc/ssl/mycerts/*.crt' >> /usr/bin/makecert
366
   chmod +x /usr/bin/makecert
435
   chmod +x /usr/bin/makecert
436
+  echo 'script_to_make_self_signed_certificates' >> $COMPLETION_FILE
367
 }
437
 }
368
 
438
 
369
 function configure_email {
439
 function configure_email {
440
+  if [ grep -Fxq "configure_email" $COMPLETION_FILE ]; then
441
+	  return
442
+  fi
370
   apt-get -y remove postfix
443
   apt-get -y remove postfix
371
   apt-get -y install exim4 sasl2-bin swaks libnet-ssleay-perl procmail
444
   apt-get -y install exim4 sasl2-bin swaks libnet-ssleay-perl procmail
372
   echo 'dc_eximconfig_configtype="internet"' > /etc/exim4/update-exim4.conf.conf
445
   echo 'dc_eximconfig_configtype="internet"' > /etc/exim4/update-exim4.conf.conf
439
 	ln -s /home/$MY_USERNAME/Maildir/.learn-ham /home/$MY_USERNAME/Maildir/ham
512
 	ln -s /home/$MY_USERNAME/Maildir/.learn-ham /home/$MY_USERNAME/Maildir/ham
440
 	chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Maildir
513
 	chown -R $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/Maildir
441
   fi
514
   fi
515
+  echo 'configure_email' >> $COMPLETION_FILE
442
 }
516
 }
443
 
517
 
444
 function spam_filtering {
518
 function spam_filtering {
519
+  if [ grep -Fxq "spam_filtering" $COMPLETION_FILE ]; then
520
+	  return
521
+  fi
445
   apt-get -y install spamassassin exim4-daemon-heavy
522
   apt-get -y install spamassassin exim4-daemon-heavy
446
   sed -i 's/ENABLED=0/ENABLED=1/g' /etc/default/spamassassin
523
   sed -i 's/ENABLED=0/ENABLED=1/g' /etc/default/spamassassin
447
   sed -i 's/# spamd_address = 127.0.0.1 783/spamd_address = 127.0.0.1 783/g' /etc/exim4/exim4.conf.template
524
   sed -i 's/# spamd_address = 127.0.0.1 783/spamd_address = 127.0.0.1 783/g' /etc/exim4/exim4.conf.template
525
   service spamassassin restart
602
   service spamassassin restart
526
   service exim4 restart
603
   service exim4 restart
527
   service cron restart
604
   service cron restart
605
+  echo 'spam_filtering' >> $COMPLETION_FILE
528
 }
606
 }
529
 
607
 
530
 function configure_imap {
608
 function configure_imap {
609
+  if [ grep -Fxq "configure_imap" $COMPLETION_FILE ]; then
610
+	  return
611
+  fi
531
   apt-get -y install dovecot-common dovecot-imapd
612
   apt-get -y install dovecot-common dovecot-imapd
532
   makecert dovecot
613
   makecert dovecot
533
   chown root:dovecot /etc/ssl/certs/dovecot.crt
614
   chown root:dovecot /etc/ssl/certs/dovecot.crt
546
   sed -i 's/#disable_plaintext_auth = yes/disable_plaintext_auth = no/g' /etc/dovecot/conf.d/10-auth.conf
627
   sed -i 's/#disable_plaintext_auth = yes/disable_plaintext_auth = no/g' /etc/dovecot/conf.d/10-auth.conf
547
   sed -i 's/auth_mechanisms = plain/auth_mechanisms = plain login/g' /etc/dovecot/conf.d/10-auth.conf
628
   sed -i 's/auth_mechanisms = plain/auth_mechanisms = plain login/g' /etc/dovecot/conf.d/10-auth.conf
548
   sed -i 's|#   mail_location = maildir:~/Maildir|   mail_location = maildir:~/Maildir:LAYOUT=fs|g' /etc/dovecot/conf.d/10-mail.conf
629
   sed -i 's|#   mail_location = maildir:~/Maildir|   mail_location = maildir:~/Maildir:LAYOUT=fs|g' /etc/dovecot/conf.d/10-mail.conf
630
+  echo 'configure_imap' >> $COMPLETION_FILE
549
 }
631
 }
550
 
632
 
551
 function configure_gpg {
633
 function configure_gpg {
634
+  if [ grep -Fxq "configure_gpg" $COMPLETION_FILE ]; then
635
+	  return
636
+  fi
552
   apt-get -y install gnupg
637
   apt-get -y install gnupg
638
+  echo 'configure_gpg' >> $COMPLETION_FILE
553
 }
639
 }
554
 
640
 
555
 function email_client {
641
 function email_client {
642
+  if [ grep -Fxq "email_client" $COMPLETION_FILE ]; then
643
+	  return
644
+  fi
556
   apt-get -y install mutt-patched lynx abook
645
   apt-get -y install mutt-patched lynx abook
557
   if [ ! -d /home/$MY_USERNAME/.mutt ]; then
646
   if [ ! -d /home/$MY_USERNAME/.mutt ]; then
558
     mkdir /home/$MY_USERNAME/.mutt
647
     mkdir /home/$MY_USERNAME/.mutt
646
   touch /home/$MY_USERNAME/.mutt-alias
735
   touch /home/$MY_USERNAME/.mutt-alias
647
   chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.muttrc
736
   chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.muttrc
648
   chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.mutt-alias
737
   chown $MY_USERNAME:$MY_USERNAME /home/$MY_USERNAME/.mutt-alias
738
+
739
+  echo 'email_client' >> $COMPLETION_FILE
649
 }
740
 }
650
 
741
 
651
 function folders_for_mailing_lists {
742
 function folders_for_mailing_lists {
743
+  if [ grep -Fxq "folders_for_mailing_lists" $COMPLETION_FILE ]; then
744
+	  return
745
+  fi
652
   echo '#!/bin/bash' > /usr/bin/mailinglistrule
746
   echo '#!/bin/bash' > /usr/bin/mailinglistrule
653
   echo 'MYUSERNAME=$1' >> /usr/bin/mailinglistrule
747
   echo 'MYUSERNAME=$1' >> /usr/bin/mailinglistrule
654
   echo 'MAILINGLIST=$2' >> /usr/bin/mailinglistrule
748
   echo 'MAILINGLIST=$2' >> /usr/bin/mailinglistrule
678
   echo '  chown -R $MYUSERNAME:$MYUSERNAME $PROCMAILLOG' >> /usr/bin/mailinglistrule
772
   echo '  chown -R $MYUSERNAME:$MYUSERNAME $PROCMAILLOG' >> /usr/bin/mailinglistrule
679
   echo 'fi' >> /usr/bin/mailinglistrule
773
   echo 'fi' >> /usr/bin/mailinglistrule
680
   chmod +x /usr/bin/mailinglistrule
774
   chmod +x /usr/bin/mailinglistrule
775
+  echo 'folders_for_mailing_lists' >> $COMPLETION_FILE
681
 }
776
 }
682
 
777
 
683
 function folders_for_email_addresses {
778
 function folders_for_email_addresses {
779
+  if [ grep -Fxq "folders_for_email_addresses" $COMPLETION_FILE ]; then
780
+	  return
781
+  fi
684
   echo '#!/bin/bash' > /usr/bin/emailrule
782
   echo '#!/bin/bash' > /usr/bin/emailrule
685
   echo 'MYUSERNAME=$1' >> /usr/bin/emailrule
783
   echo 'MYUSERNAME=$1' >> /usr/bin/emailrule
686
   echo 'EMAILADDRESS=$2' >> /usr/bin/emailrule
784
   echo 'EMAILADDRESS=$2' >> /usr/bin/emailrule
710
   echo '  chown -R $MYUSERNAME:$MYUSERNAME $PROCMAILLOG' >> /usr/bin/emailrule
808
   echo '  chown -R $MYUSERNAME:$MYUSERNAME $PROCMAILLOG' >> /usr/bin/emailrule
711
   echo 'fi' >> /usr/bin/emailrule
809
   echo 'fi' >> /usr/bin/emailrule
712
   chmod +x /usr/bin/emailrule
810
   chmod +x /usr/bin/emailrule
811
+  echo 'folders_for_email_addresses' >> $COMPLETION_FILE
713
 }
812
 }
714
 
813
 
715
 argument_checks
814
 argument_checks