add helper scripts, docs
[automated-distro-installer] / dsfull
diff --git a/dsfull b/dsfull
index e24c549fdf70818e8ee02a448c3778fafaa32f56..06af7f8f68e2ac0cd0f5fb768e83fcaf93dde284 100755 (executable)
--- a/dsfull
+++ b/dsfull
@@ -1,10 +1,17 @@
 #!/bin/bash -l
 # Copyright (C) 2016 Ian Kelling
 
-# distro setup full using fai. (assuming we already synced data files to the host)
-# Usage: dsfull [-r] HOST
-# -r for no reboot.
+# 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() { :; }
@@ -16,27 +23,63 @@ if [[ $1 == -r ]]; then
     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
-
-cleanup() { pxe-server; }
-pxe-server $host fai
+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
 
+    if $reboot; then
+        # untested, this caused hang using here doc.
+        ssh $host "touch /tmp/keyscript-off; sudo reboot" ||: &
+    fi
 
-if $reboot; then
-    # untested, this caused hang using here doc.
-    ssh $host "touch /tmp/keyscript-off; sudo reboot" ||: &
+    e pxe-server -a
+    cleanup() { :; }
 fi
 
-pxe-server -a
-cleanup() { :; }
-
 error=true
 for ((i=0; i<240; i++)); do
     if timeout -s 9 10 ssh $host :; then
@@ -49,4 +92,4 @@ if $error; then
     echo "$0: error: timeout"
     exit 1
 fi
-dsremote $host
+dsremote $host