Fix credentials loading to handle values with spaces
This commit is contained in:
parent
285d6609b1
commit
76f5276f4b
2 changed files with 13 additions and 4 deletions
|
|
@ -25,8 +25,12 @@ REPO_ROOT="$(cd "${SCRIPT_DIR}/.." && pwd)"
|
||||||
# Load secrets from credentials file if present
|
# Load secrets from credentials file if present
|
||||||
CREDS_FILE=/root/hotel-manage-credentials.txt
|
CREDS_FILE=/root/hotel-manage-credentials.txt
|
||||||
if [[ -f "$CREDS_FILE" ]]; then
|
if [[ -f "$CREDS_FILE" ]]; then
|
||||||
# shellcheck disable=SC1090
|
while IFS= read -r line || [[ -n "$line" ]]; do
|
||||||
set -a; source <(grep -v '^#' "$CREDS_FILE" | grep '='); set +a
|
[[ "$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
|
fi
|
||||||
|
|
||||||
# ── Collect config ────────────────────────────────────────────────────────────
|
# ── Collect config ────────────────────────────────────────────────────────────
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,13 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" 2>/dev/null && pwd || echo /tm
|
||||||
CREDS_FILE=/root/hotel-manage-credentials.txt
|
CREDS_FILE=/root/hotel-manage-credentials.txt
|
||||||
[[ -f "$CREDS_FILE" ]] || msg_error "Stack credentials not found at ${CREDS_FILE} — run install-stack.sh first"
|
[[ -f "$CREDS_FILE" ]] || msg_error "Stack credentials not found at ${CREDS_FILE} — run install-stack.sh first"
|
||||||
|
|
||||||
# shellcheck disable=SC1090
|
# Read credentials — split on first = only so values with spaces (e.g. SITE_NAME=Hotel Number Four) work correctly
|
||||||
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"
|
||||||
|
|
||||||
[[ -z "${CENTRAL_AUTH_SECRET:-}" ]] && msg_error "CENTRAL_AUTH_SECRET missing from ${CREDS_FILE}"
|
[[ -z "${CENTRAL_AUTH_SECRET:-}" ]] && msg_error "CENTRAL_AUTH_SECRET missing from ${CREDS_FILE}"
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue