minor fixes and documentation
[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 set -eE -o pipefail
17 cleanup() { :; }
18 trap 'cleanup; echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
19
20 reboot=true
21 if [[ $1 == -r ]]; then
22 reboot=false
23 shift
24 fi
25
26 usage() {
27 cat <<EOF
28 Usage: ${0##*/} [OPTIONS] HOST
29 "distro setup full" using fai.
30
31 Note: relies on other repos and paths specific to Ian's system.
32 Note: disables btrbk.timer. If it was active before, it should
33 be manual reenabled after completion.
34
35 --no-r Don't ssh to host and reboot.
36 -k ssh to host and kexec, don't use pxe. implies --no-r
37 -h|--help Print help and exit.
38
39 Note: Uses GNU getopt options parsing style
40 EOF
41 exit $1
42 }
43
44 ##### begin command line parsing ########
45
46 reboot=true
47 kexec=false
48 temp=$(getopt -l help,no-r hk "$@") || usage 1
49 eval set -- "$temp"
50 while true; do
51 case $1 in
52 --no-r) reboot=false; shift ;;
53 -k) kexec=true; reboot=false; shift ;;
54 -h|--help) usage ;;
55 --) shift; break ;;
56 *) echo "$0: Internal error!" ; exit 1 ;;
57 esac
58 done
59 host=$1
60
61 ##### end command line parsing ########
62
63 e ser stop btrbk.timer
64 if [[ ! $host ]]; then
65 echo "$0: error: expected 1 arg of hostname"
66 exit 1
67 fi
68
69 e() { echo "$@"; "$@"; }
70 if $kexec; then
71 e fai-redep
72 e myfai-chboot $host
73 e fai-kexec $host ||:
74 else
75 cleanup() { pxe-server; }
76 e pxe-server $host fai
77
78 if $reboot; then
79 # untested, this caused hang using here doc.
80 ssh $host "touch /tmp/keyscript-off; sudo reboot" ||: &
81 fi
82
83 e pxe-server -a
84 cleanup() { :; }
85 fi
86
87 error=true
88 for ((i=0; i<240; i++)); do
89 if timeout -s 9 10 ssh $host :; then
90 error=false
91 break
92 fi
93 sleep 5
94 done
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 e dsremote $host