-#!/bin/bash -l
+#!/bin/bash
# Copyright (C) 2016 Ian Kelling
-# distro setup full. (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
-set -eE -o pipefail
-trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
+# 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.
+
+if [[ -s ~/.bashrc ]];then . ~/.bashrc;fi
reboot=true
if [[ $1 == -r ]]; then
shift
fi
+usage() {
+ cat <<EOF
+Usage: ${0##*/} [OPTIONS] HOST
+"distro setup full" using fai.
+
+Note: relies on other repos and paths specific to Ian's system.
+Note: disables btrbk.timer. If it was active before, it should
+be manual reenabled after completion.
+
+-k ssh to host and kexec, don't use pxe. implies --no-r
+--no-r Don't ssh to host and reboot. Use this for when you are
+ booting or rebooting from some other means.
+-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 ########
+
+ser stop btrbk.timer
+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" ||:
+if $kexec; then
+ fai-redep
+ myfai-chboot $host
+ live-kexec $host ||:
+else
+ err-cleanup() { pxe-server; }
+ pxe-server $host fai
+
+ if $reboot; then
+ # untested, this caused hang using here doc.
+ ssh root@$host "touch /tmp/keyscript-off; reboot" ||: &
+ fi
+
+ pxe-server -a
+ unset err-cleanup
fi
-pxe-server fai $host
-while ! ssh $host :; do
+error=true
+for ((i=0; i<240; i++)); do
+ if timeout -s 9 10 ssh $host :; then
+ error=false
+ break
+ fi
+ sleep 5
+done
+faiserver-disable
+if $error; then
+ echo "$0: error: timeout"
+ exit 1
+fi
+while [[ $(ser is-active btrbk.service) == active ]]; do
sleep 5
done
+# if we partitioned, we do this:
+#btrbk-run -t $host archive
+btrbk-run -t $host
dsremote $host