#!/bin/bash -l
# Copyright (C) 2016 Ian Kelling
-# distro setup full using fai. (assuming we already synced data files to the host)
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+
+# http://www.apache.org/licenses/LICENSE-2.0
+
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
set -eE -o pipefail
cleanup() { :; }
shift
fi
+usage() {
+ cat <<EOF
+Usage: ${0##*/} [OPTIONS] HOST
+distro setup full using fai. (assuming we already synced data files to the host)
+
+--no-r Don't ssh to host and reboot.
+-k ssh to host and kexec, don't use pxe. implies --no-r
+-h|--help Print help and exit.
+
+Note: Uses GNU getopt options parsing style
+EOF
+ exit $1
+}
+
+##### begin command line parsing ########
+
+reboot=true
+kexec=false
+temp=$(getopt -l help,no-r hk "$@") || usage 1
+eval set -- "$temp"
+while true; do
+ case $1 in
+ --no-r) reboot=false; shift ;;
+ -k) kexec=true; reboot=false; shift ;;
+ -h|--help) usage ;;
+ --) shift; break ;;
+ *) echo "$0: Internal error!" ; exit 1 ;;
+ esac
+done
host=$1
-if [[ ! $host || $host == -h ]]; then
+##### end command line parsing ########
+
+
+if [[ ! $host ]]; then
echo "$0: error: expected 1 arg of hostname"
exit 1
fi
-set -x
-if $reboot; then
- # untested, this caused hang using here doc.
- ssh $host "touch /tmp/keyscript-off; sudo reboot" ||:
-fi
+e() { echo "$@"; "$@"; }
+if $kexec; then
+ e fai-redep
+ e myfai-chboot $host
+ e fai-kexec $host ||:
+else
+ cleanup() { pxe-server; }
+ e pxe-server $host fai
-cleanup() { pxe-server :; }
-pxe-server -a fai $host
-cleanup() { :; }
+ if $reboot; then
+ # untested, this caused hang using here doc.
+ ssh $host "touch /tmp/keyscript-off; sudo reboot" ||: &
+ fi
+
+ e pxe-server -a
+ cleanup() { :; }
+fi
-timedout=true
+error=true
for ((i=0; i<240; i++)); do
if timeout -s 9 10 ssh $host :; then
- timedout=false
+ error=false
break
fi
sleep 5
done
-if $timeout; then
+if $error; then
echo "$0: error: timeout"
exit 1
fi
-dsremote $host
+e dsremote $host