diff --git a/misc/alpine-install.func b/misc/alpine-install.func index 8b05cd5b5..9dd3548d5 100644 --- a/misc/alpine-install.func +++ b/misc/alpine-install.func @@ -12,17 +12,22 @@ fi export TELEMETRY_CONTEXT="container" # A freshly booted container may not have DNS up yet. `source <(curl ...)` hides # curl's exit code, so a failed download would silently source an empty stream. +_bootstrap_die() { + if declare -f msg_error >/dev/null 2>&1; then + msg_error "$1" + else + echo "FATAL: $1" >&2 + fi + exit 115 +} + _bootstrap_source() { local url="$1" probe="$2" content - content=$(curl -fsSL --connect-timeout 10 --retry 5 --retry-connrefused --retry-delay 2 "$url") || { - echo "FATAL: failed to download ${url##*/}" >&2 - exit 115 - } + content=$(curl -fsSL --connect-timeout 10 --retry 5 --retry-connrefused --retry-delay 2 "$url") || + _bootstrap_die "Failed to download ${url##*/}" source /dev/stdin <<<"$content" - declare -f "$probe" >/dev/null 2>&1 || { - echo "FATAL: ${url##*/} loaded but incomplete (missing ${probe})" >&2 - exit 115 - } + declare -f "$probe" >/dev/null 2>&1 || + _bootstrap_die "${url##*/} loaded but incomplete (missing ${probe})" } _FUNC_BASE="https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc" diff --git a/misc/build.func b/misc/build.func index 07b0b2186..561f0f62b 100644 --- a/misc/build.func +++ b/misc/build.func @@ -90,6 +90,15 @@ variables() { # `source <(curl ...)` hides the download exit code, so a failed fetch would # silently source an empty stream and leave the helpers undefined. +_bootstrap_die() { + if declare -f msg_error >/dev/null 2>&1; then + msg_error "$1" + else + echo "FATAL: $1" >&2 + fi + exit 115 +} + _bootstrap_source() { local url="$1" probe="$2" content="" if command -v curl >/dev/null 2>&1; then @@ -97,18 +106,12 @@ _bootstrap_source() { elif command -v wget >/dev/null 2>&1; then content=$(wget -qO- --tries=5 --timeout=10 "$url") || content="" else - echo "FATAL: neither curl nor wget available" >&2 - exit 115 - fi - if [[ -z "$content" ]]; then - echo "FATAL: failed to download ${url##*/}" >&2 - exit 115 + _bootstrap_die "Neither curl nor wget available" fi + [[ -n "$content" ]] || _bootstrap_die "Failed to download ${url##*/}" source /dev/stdin <<<"$content" - if ! declare -f "$probe" >/dev/null 2>&1; then - echo "FATAL: ${url##*/} loaded but incomplete (missing ${probe})" >&2 - exit 115 - fi + declare -f "$probe" >/dev/null 2>&1 || + _bootstrap_die "${url##*/} loaded but incomplete (missing ${probe})" } _FUNC_BASE="https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc" diff --git a/misc/install.func b/misc/install.func index a3bfa231d..922f24993 100644 --- a/misc/install.func +++ b/misc/install.func @@ -39,17 +39,22 @@ export TELEMETRY_CONTEXT="container" # A freshly booted container may not have DNS up yet. `source <(curl ...)` hides # curl's exit code, so a failed download would silently source an empty stream. +_bootstrap_die() { + if declare -f msg_error >/dev/null 2>&1; then + msg_error "$1" + else + echo "FATAL: $1" >&2 + fi + exit 115 +} + _bootstrap_source() { local url="$1" probe="$2" content - content=$(curl -fsSL --connect-timeout 10 --retry 5 --retry-connrefused --retry-delay 2 "$url") || { - echo "FATAL: failed to download ${url##*/}" >&2 - exit 115 - } + content=$(curl -fsSL --connect-timeout 10 --retry 5 --retry-connrefused --retry-delay 2 "$url") || + _bootstrap_die "Failed to download ${url##*/}" source /dev/stdin <<<"$content" - declare -f "$probe" >/dev/null 2>&1 || { - echo "FATAL: ${url##*/} loaded but incomplete (missing ${probe})" >&2 - exit 115 - } + declare -f "$probe" >/dev/null 2>&1 || + _bootstrap_die "${url##*/} loaded but incomplete (missing ${probe})" } _FUNC_BASE="https://raw.githubusercontent.com/community-scripts/ProxmoxVE/main/misc"