various fixes, improvements, shellcheck
[automated-distro-installer] / myfai-chboot
index a653ae6a020240208dbb20913d1bcf5b673762f1..aa3c0881152c3f48c530a3ce4d58dfb08e65b3c2 100755 (executable)
 set -eE -o pipefail
 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" returned $?" >&2' ERR
 
-x=$(readlink -f "$BASH_SOURCE"); cd ${x%/*}
+this_file="$(readlink -f -- "${BASH_SOURCE[0]}")"
+readonly this_file this_dir="${this_file%/*}"
+cd "$this_dir"
 
 usage() {
-  cat <<EOF
-usage: ${0##*/} [OPTIONS] [HOSTNAME|IP|default]
+  cat <<'EOF'
+usage: myfai-chboot [OPTIONS] [HOSTNAME|IP|default]
 
-Sets up tftp pxe config and nfs server on host "faiserver".
+Sets up tftp pxe config and nfs server on host "faiserver.b8.nz".
 
 If our kernel has no nfs support, uses apache intead of nfs, and depends
 on another repo of Ian Kelling, basic-https-conf, where the file is at
@@ -54,15 +56,15 @@ HOSTNAME|IP|default  Sets the host to enable it for.  No argument
 -h|--help   Print help and exit.
 
 EOF
-  exit $1
+  exit 0
 }
 case $1 in
   -h|--help) usage ;;
 esac
 
 
-faiserver_addr=$(host faiserver | sed -rn 's/^\S+ has address //p;T;q' ||:)
-host=$(./chost faiserver)
+faiserver_addr=$(host faiserver.b8.nz | sed -rn 's/^\S+ has address //p;T;q' ||:)
+host=$(./chost faiserver.b8.nz)
 if ip a | grep "^ *inet.\? $faiserver_addr" &>/dev/null; then
   ./myfai-chboot-local "$@"
 else