add rescue, fix default pxe, ubuntu locale
[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 -k ssh to host and kexec, don't use pxe. implies --no-r
36 --no-r Don't ssh to host and reboot. Use this for when you are
37 booting or rebooting from some other means.
38 -h|--help Print help and exit.
39
40 Note: Uses GNU getopt options parsing style
41 EOF
42 exit $1
43 }
44
45 ##### begin command line parsing ########
46
47 reboot=true
48 kexec=false
49 temp=$(getopt -l help,no-r hk "$@") || usage 1
50 eval set -- "$temp"
51 while true; do
52 case $1 in
53 --no-r) reboot=false; shift ;;
54 -k) kexec=true; reboot=false; shift ;;
55 -h|--help) usage ;;
56 --) shift; break ;;
57 *) echo "$0: Internal error!" ; exit 1 ;;
58 esac
59 done
60 host=$1
61
62 ##### end command line parsing ########
63
64 e ser stop btrbk.timer
65 if [[ ! $host ]]; then
66 echo "$0: error: expected 1 arg of hostname"
67 exit 1
68 fi
69
70 e() { echo "$@"; "$@"; }
71 if $kexec; then
72 e fai-redep
73 e myfai-chboot $host
74 e fai-kexec $host ||:
75 else
76 cleanup() { pxe-server; }
77 e pxe-server $host fai
78
79 if $reboot; then
80 # untested, this caused hang using here doc.
81 ssh $host "touch /tmp/keyscript-off; sudo reboot" ||: &
82 fi
83
84 e pxe-server -a
85 cleanup() { :; }
86 fi
87
88 error=true
89 for ((i=0; i<240; i++)); do
90 if timeout -s 9 10 ssh $host :; then
91 error=false
92 break
93 fi
94 sleep 5
95 done
96 e faiserver-disable
97 if $error; then
98 echo "$0: error: timeout"
99 exit 1
100 fi
101 while [[ $(ser is-active btrbk.service) == active ]]; do
102 sleep 5
103 done
104 e btrbk-run -t $host
105 ssh $host /a/bin/distro-setup/distro-begin
106 #e dsremote $host