fix dsfull
[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
6 set -eE -o pipefail
7 cleanup() { :; }
8 trap 'cleanup; echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
9
10 reboot=true
11 if [[ $1 == -r ]]; then
12 reboot=false
13 shift
14 fi
15
16 host=$1
17
18 if [[ ! $host || $host == -h ]]; then
19 echo "$0: error: expected 1 arg of hostname"
20 exit 1
21 fi
22
23 set -x
24
25 cleanup() { pxe-server :; }
26 pxe-server fai $host
27
28
29 if $reboot; then
30 # untested, this caused hang using here doc.
31 ssh $host "touch /tmp/keyscript-off; sudo reboot" ||: &
32 fi
33
34 pxe-server -a :
35 cleanup() { :; }
36
37 error=true
38 for ((i=0; i<240; i++)); do
39 if timeout -s 9 10 ssh $host :; then
40 error=false
41 break
42 fi
43 sleep 5
44 done
45 if $error; then
46 echo "$0: error: timeout"
47 exit 1
48 fi
49 dsremote $host