50 lines
1.3 KiB
Bash
50 lines
1.3 KiB
Bash
#!/usr/bin/env bash
|
|
|
|
PATH='/usr/sbin:/usr/bin:/sbin:/bin'
|
|
export PATH
|
|
LC_ALL=C
|
|
export LC_ALL
|
|
umask 077
|
|
|
|
_k3slr_wrapper_initial_guard() {
|
|
local effective_uid="${1-}" shell_options="${2-}"
|
|
[[ "$effective_uid" =~ ^[0-9]+$ && "$effective_uid" != 0 ]] || return 1
|
|
[[ "$shell_options" != *x* ]]
|
|
}
|
|
|
|
if ! _k3slr_wrapper_initial_guard "${EUID:-}" "$-"; then
|
|
printf 'ERROR: lifecycle wrapper refuses root or xtrace execution\n' >&2
|
|
return 1 2>/dev/null || exit 1
|
|
fi
|
|
|
|
if [[ "${BASH_SOURCE[0]}" == */* ]]; then
|
|
K3SLR_WRAPPER_DIRECTORY="${BASH_SOURCE[0]%/*}"
|
|
else
|
|
K3SLR_WRAPPER_DIRECTORY='.'
|
|
fi
|
|
K3SLR_WRAPPER_ROOT="$(cd -- "${K3SLR_WRAPPER_DIRECTORY}/../.." && pwd -P)" || {
|
|
return 1 2>/dev/null || exit 1
|
|
}
|
|
K3SLR_WRAPPER_CONTRACT="${K3SLR_WRAPPER_ROOT}/infrastructure/security/k3s/local-recovery.env"
|
|
# shellcheck source=/dev/null
|
|
source "${K3SLR_WRAPPER_ROOT}/scripts/lib/k3s-local-recovery.sh" || {
|
|
return 1 2>/dev/null || exit 1
|
|
}
|
|
|
|
_k3slr_open_usage() {
|
|
printf 'Usage: bash scripts/bootstrap/open-k3s-local-recovery.sh [--execute]\n' >&2
|
|
}
|
|
|
|
_k3slr_open_main() {
|
|
local execution_mode
|
|
if ! _k3slr_parse_lifecycle_cli execution_mode "$@"; then
|
|
_k3slr_open_usage
|
|
return 2
|
|
fi
|
|
_k3slr_lifecycle_main open "$execution_mode"
|
|
}
|
|
|
|
if [[ "${BASH_SOURCE[0]}" == "$0" ]]; then
|
|
_k3slr_open_main "$@"
|
|
fi
|