ソースを参照

Keep track of installation completion

Bob Mottram 10 年 前
コミット
75302efe5f
共有1 個のファイルを変更した99 個の追加0 個の削除を含む
  1. 99
    0
      install-freedombone.sh

+ 99
- 0
install-freedombone.sh ファイルの表示

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