better support for systems with no pxe
[automated-distro-installer] / dsfull
1 #!/bin/bash -l
2 # Copyright (C) 2016 Ian Kelling
3
4 # distro setup full using fai. (assuming we already synced data files to the host)
5 # Usage: dsfull [-r] HOST
6 # -r for no reboot.
7
8
9 set -eE -o pipefail
10 cleanup() { :; }
11 trap 'cleanup; echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
12
13 reboot=true
14 if [[ $1 == -r ]]; then
15 reboot=false
16 shift
17 fi
18
19 host=$1
20
21 if [[ ! $host || $host == -h ]]; then
22 echo "$0: error: expected 1 arg of hostname"
23 exit 1
24 fi
25
26 set -x
27
28 cleanup() { pxe-server :; }
29 pxe-server $host fai
30
31
32 if $reboot; then
33 # untested, this caused hang using here doc.
34 ssh $host "touch /tmp/keyscript-off; sudo reboot" ||: &
35 fi
36
37 pxe-server -a
38 cleanup() { :; }
39
40 error=true
41 for ((i=0; i<240; i++)); do
42 if timeout -s 9 10 ssh $host :; then
43 error=false
44 break
45 fi
46 sleep 5
47 done
48 if $error; then
49 echo "$0: error: timeout"
50 exit 1
51 fi
52 dsremote $host