74aaef8664b806c6e10e6a9cb8329518840e3d66
[automated-distro-installer] / faiserver-disable
1 #!/bin/bash
2
3 if ! test "$BASH_VERSION"; then echo "error: shell is not bash" >&2; exit 1; fi
4 shopt -s inherit_errexit 2>/dev/null ||: # ignore fail in bash < 4.4
5 set -eE -o pipefail
6 trap 'echo "$0:$LINENO:error: \"$BASH_COMMAND\" exit status: $?, PIPESTATUS: ${PIPESTATUS[*]}" >&2' ERR
7
8 this_file="$(readlink -f -- "${BASH_SOURCE[0]}")"
9 readonly this_file this_dir="${this_file%/*}"
10 cd "$this_dir"
11
12 usage() {
13 cat <<'EOF'
14 Usage: faiserver-disable
15 Disable the fai nfs server exports
16 EOF
17 exit $1
18 }
19
20 if [[ $1 ]]; then
21 usage 1
22 fi
23
24
25
26 faiserver_addr=$(host faiserver.b8.nz | sed -rn 's/^\S+ has address //p;T;q' ||:)
27 if ip a | grep "^ *inet.\? $faiserver_addr" &>/dev/null; then
28 echo "$0: disabling fai nfs exports or apache site"
29 ./faiserver-disable-local
30 else
31 echo "$0: sshing to $(chost faiserver.b8.nz) to disable fai nfs exports or apache site"
32 ssh root@$(chost faiserver.b8.nz) bash <faiserver-disable-local
33 fi