diff options
Diffstat (limited to 'scripts/maintenance-lib.sh')
| -rw-r--r-- | scripts/maintenance-lib.sh | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/scripts/maintenance-lib.sh b/scripts/maintenance-lib.sh new file mode 100644 index 0000000..33e7e07 --- /dev/null +++ b/scripts/maintenance-lib.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +# Set args and maintenance_run for one domain of a maintenance request. +# shellcheck disable=SC2034 +_maintenance_select() { + local scope=$1 domain=$2 role raw target + shift 2 + role=$(_machine_role) || return 1 + args=() + maintenance_run=false + if [ "$scope" = host ]; then + _require_host || return 1 + args=("$@") + maintenance_run=true + return + fi + for raw in "$@"; do + case "$raw" in + /etc/* | etc/*) + [ "$role" = host ] || { + echo 'error: /etc paths require the host role' >&2 + return 1 + } + target=etc + ;; + */*) target=home ;; + *) + echo "error: expected a file path: $raw" >&2 + return 1 + ;; + esac + [ "$target" != "$domain" ] || args+=("$raw") + done + if [ ${#args[@]} -gt 0 ] || { [ $# -eq 0 ] && { [ "$domain" = home ] || [ "$role" = host ]; }; }; then + maintenance_run=true + fi + return 0 +} |
