various fixes, improve flidas
[automated-distro-installer] / dsfull
1 #!/bin/bash -l
2 # Copyright (C) 2016 Ian Kelling
3
4 # Licensed under the Apache License, Version 2.0 (the "License");
5 # you may not use this file except in compliance with the License.
6 # You may obtain a copy of the License at
7
8 # http://www.apache.org/licenses/LICENSE-2.0
9
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15
16 x="$(readlink -f "$BASH_SOURCE")"; source "${x%/*}/bash-trace"
17
18 reboot=true
19 if [[ $1 == -r ]]; then
20 reboot=false
21 shift
22 fi
23
24 usage() {
25 cat <<EOF
26 Usage: ${0##*/} [OPTIONS] HOST
27 "distro setup full" using fai.
28
29 Note: relies on other repos and paths specific to Ian's system.
30 Note: disables btrbk.timer. If it was active before, it should
31 be manual reenabled after completion.
32
33 -k ssh to host and kexec, don't use pxe. implies --no-r
34 --no-r Don't ssh to host and reboot. Use this for when you are
35 booting or rebooting from some other means.
36 -h|--help Print help and exit.
37
38 Note: Uses GNU getopt options parsing style
39 EOF
40 exit $1
41 }
42
43 ##### begin command line parsing ########
44
45 reboot=true
46 kexec=false
47 temp=$(getopt -l help,no-r hk "$@") || usage 1
48 eval set -- "$temp"
49 while true; do
50 case $1 in
51 --no-r) reboot=false; shift ;;
52 -k) kexec=true; reboot=false; shift ;;
53 -h|--help) usage ;;
54 --) shift; break ;;
55 *) echo "$0: Internal error!" ; exit 1 ;;
56 esac
57 done
58 host=$1
59
60 ##### end command line parsing ########
61
62 e ser stop btrbk.timer
63 if [[ ! $host ]]; then
64 echo "$0: error: expected 1 arg of hostname"
65 exit 1
66 fi
67
68 e() { echo "$@"; "$@"; }
69 if $kexec; then
70 e fai-redep
71 e myfai-chboot $host
72 e fai-kexec $host ||:
73 else
74 cleanup() { pxe-server; }; _errcatch_cleanup=cleanup
75 e pxe-server $host fai
76
77 if $reboot; then
78 # untested, this caused hang using here doc.
79 ssh $host "touch /tmp/keyscript-off; sudo reboot" ||: &
80 fi
81
82 e pxe-server -a
83 unset _errcatch_cleanup
84 fi
85
86 error=true
87 for ((i=0; i<240; i++)); do
88 if timeout -s 9 10 ssh $host :; then
89 error=false
90 break
91 fi
92 sleep 5
93 done
94 e faiserver-disable
95 if $error; then
96 echo "$0: error: timeout"
97 exit 1
98 fi
99 while [[ $(ser is-active btrbk.service) == active ]]; do
100 sleep 5
101 done
102 e btrbk-run -t $host
103 ssh $host /a/bin/distro-setup/distro-begin
104 # this should be done instead of distro-begin, but
105 # keeping it to 2 steps for now
106 #e dsremote $host