add helper scripts, docs
[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. (assuming we already synced data files to the host)
30
31 --no-r Don't ssh to host and reboot.
32 -k ssh to host and kexec, don't use pxe. implies --no-r
33 -h|--help Print help and exit.
34
35 Note: Uses GNU getopt options parsing style
36 EOF
37 exit $1
38 }
39
40 ##### begin command line parsing ########
41
42 reboot=true
43 kexec=false
44 temp=$(getopt -l help,no-r hk "$@") || usage 1
45 eval set -- "$temp"
46 while true; do
47 case $1 in
48 --no-r) reboot=false; shift ;;
49 -k) kexec=true; reboot=false; shift ;;
50 -h|--help) usage ;;
51 --) shift; break ;;
52 *) echo "$0: Internal error!" ; exit 1 ;;
53 esac
54 done
55 host=$1
56
57 ##### end command line parsing ########
58
59
60 if [[ ! $host ]]; then
61 echo "$0: error: expected 1 arg of hostname"
62 exit 1
63 fi
64
65 e() { echo "$@"; "$@"; }
66 if $kexec; then
67 e fai-redep
68 e myfai-chboot $host
69 e fai-kexec $host ||:
70 else
71 cleanup() { pxe-server; }
72 e pxe-server $host fai
73
74 if $reboot; then
75 # untested, this caused hang using here doc.
76 ssh $host "touch /tmp/keyscript-off; sudo reboot" ||: &
77 fi
78
79 e pxe-server -a
80 cleanup() { :; }
81 fi
82
83 error=true
84 for ((i=0; i<240; i++)); do
85 if timeout -s 9 10 ssh $host :; then
86 error=false
87 break
88 fi
89 sleep 5
90 done
91 if $error; then
92 echo "$0: error: timeout"
93 exit 1
94 fi
95 e dsremote $host