Fix credentials loading to handle values with spaces

This commit is contained in:
jtricerolph 2026-07-01 19:10:56 +00:00
parent 285d6609b1
commit 76f5276f4b
2 changed files with 13 additions and 4 deletions

View file

@ -25,8 +25,12 @@ REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
# Load secrets from credentials file if present
CREDS_FILE=/root/hotel-manage-credentials.txt
if [[ -f "$CREDS_FILE" ]]; then
# shellcheck disable=SC1090
set -a; source <(grep -v '^#' "$CREDS_FILE" | grep '='); set +a
while IFS= read -r line || [[ -n "$line" ]]; do
[[ "$line" =~ ^[[:space:]]*# ]] && continue
[[ -z "${line//[[:space:]]/}" ]] && continue
[[ "$line" =~ ^([A-Za-z_][A-Za-z0-9_]*)=(.*)$ ]] || continue
export "${BASH_REMATCH[1]}"="${BASH_REMATCH[2]}"
done < "$CREDS_FILE"
fi
# ── Collect config ────────────────────────────────────────────────────────────

View file

@ -43,8 +43,13 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd || echo /tm
CREDS_FILE=/root/hotel-manage-credentials.txt
[[ -f "$CREDS_FILE" ]] || msg_error "Stack credentials not found at ${CREDS_FILE} — run install-stack.sh first"
# shellcheck disable=SC1090
set -a; source <(grep -v '^#' "$CREDS_FILE" | grep '='); set +a
# Read credentials — split on first = only so values with spaces (e.g. SITE_NAME=Hotel Number Four) work correctly
while IFS= read -r line || [[ -n "$line" ]]; do
[[ "$line" =~ ^[[:space:]]*# ]] && continue
[[ -z "${line//[[:space:]]/}" ]] && continue
[[ "$line" =~ ^([A-Za-z_][A-Za-z0-9_]*)=(.*)$ ]] || continue
export "${BASH_REMATCH[1]}"="${BASH_REMATCH[2]}"
done < "$CREDS_FILE"
[[ -z "${CENTRAL_AUTH_SECRET:-}" ]] && msg_error "CENTRAL_AUTH_SECRET missing from ${CREDS_FILE}"