From 3e4ede907e12705ccf62f756b66e7e6e8706b694 Mon Sep 17 00:00:00 2001 From: Damien Date: Thu, 30 Jul 2026 13:34:05 +0200 Subject: [PATCH] openbao,gitea-runner: fail loudly if lib/common.sh sourcing fails source <(curl ...) swallows curl failures (404, network error): an empty stream still makes `source` return 0, so the failure would otherwise only surface later as a confusing "command not found" for one of lib/common.sh's functions. Check that a known function landed after the source, and exit 1 with the attempted URL if not. --- gitea-runner/install.sh | 12 +++++++++++- openbao/install.sh | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/gitea-runner/install.sh b/gitea-runner/install.sh index 19a782a..3025354 100644 --- a/gitea-runner/install.sh +++ b/gitea-runner/install.sh @@ -57,10 +57,20 @@ require_root() { # failure mode. # ============================================================ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-.}")" 2>/dev/null && pwd || true)" +LIB_COMMON_URL="$(dirname "$(dirname "$SCRIPT_URL")")/lib/common.sh" if [[ -n "$SCRIPT_DIR" && -f "${SCRIPT_DIR}/../lib/common.sh" ]]; then source "${SCRIPT_DIR}/../lib/common.sh" else - source <(curl -fsSL "$(dirname "$(dirname "$SCRIPT_URL")")/lib/common.sh") + source <(curl -fsSL "$LIB_COMMON_URL") +fi + +# `source <(curl ...)` swallows curl failures: an empty stream still makes +# `source` return 0, so a 404/network error would otherwise only surface +# later as a confusing "command not found" for detect_latest_alpine_template +# et al. Fail loudly here instead, with the URL that was tried. +if ! declare -F detect_latest_alpine_template >/dev/null; then + log_error "Failed to load lib/common.sh (tried: ${LIB_COMMON_URL})." + exit 1 fi # --- Helpers --- diff --git a/openbao/install.sh b/openbao/install.sh index f5a62e1..d2fa2de 100755 --- a/openbao/install.sh +++ b/openbao/install.sh @@ -73,10 +73,20 @@ log_error() { echo -e "${RED}[ERROR]${NC} $1" >&2; } # download the bao binary, so this adds no new failure mode. # ============================================================ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-.}")" 2>/dev/null && pwd || true)" +LIB_COMMON_URL="$(dirname "$(dirname "$SCRIPT_URL")")/lib/common.sh" if [[ -n "$SCRIPT_DIR" && -f "${SCRIPT_DIR}/../lib/common.sh" ]]; then source "${SCRIPT_DIR}/../lib/common.sh" else - source <(curl -fsSL "$(dirname "$(dirname "$SCRIPT_URL")")/lib/common.sh") + source <(curl -fsSL "$LIB_COMMON_URL") +fi + +# `source <(curl ...)` swallows curl failures: an empty stream still makes +# `source` return 0, so a 404/network error would otherwise only surface +# later as a confusing "command not found" for detect_latest_alpine_template +# et al. Fail loudly here instead, with the URL that was tried. +if ! declare -F detect_latest_alpine_template >/dev/null; then + log_error "Failed to load lib/common.sh (tried: ${LIB_COMMON_URL})." + exit 1 fi # ============================================================