various fixes, improvements, shellcheck
[automated-distro-installer] / faiserver-disable
index 65e2aa844b6e861b32b3f07ac6c5c91a465e525e..74aaef8664b806c6e10e6a9cb8329518840e3d66 100755 (executable)
@@ -1,16 +1,17 @@
 #!/bin/bash
 
-readonly this_file="$(readlink -f -- "${BASH_SOURCE[0]}")"
-script_dir="${this_file%/*}"
-# shellcheck source=./bash-trace
-source "${script_dir}/bash-trace"
-cd $script_dir
-source "${script_dir}/bash-trace"
+if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi
+shopt -s inherit_errexit 2>/dev/null ||: # ignore fail in bash < 4.4
+set -eE -o pipefail
+trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" exit status: $?, PIPESTATUS: ${PIPESTATUS[*]}" >&2' ERR
 
+this_file="$(readlink -f -- "${BASH_SOURCE[0]}")"
+readonly this_file this_dir="${this_file%/*}"
+cd "$this_dir"
 
 usage() {
-  cat <<EOF
-Usage: ${0##*/}
+  cat <<'EOF'
+Usage: faiserver-disable
 Disable the fai nfs server exports
 EOF
   exit $1
@@ -22,11 +23,11 @@ fi
 
 
 
-faiserver_addr=$(host faiserver | sed -rn 's/^\S+ has address //p;T;q' ||:)
+faiserver_addr=$(host faiserver.b8.nz | sed -rn 's/^\S+ has address //p;T;q' ||:)
 if ip a | grep "^ *inet.\? $faiserver_addr" &>/dev/null; then
   echo "$0: disabling fai nfs exports or apache site"
   ./faiserver-disable-local
 else
-  echo "$0: sshing to $(chost faiserver) to disable fai nfs exports or apache site"
-  ssh root@$(chost faiserver) bash <faiserver-disable-local
+  echo "$0: sshing to $(chost faiserver.b8.nz) to disable fai nfs exports or apache site"
+  ssh root@$(chost faiserver.b8.nz) bash <faiserver-disable-local
 fi