All checks were successful
Deploy to Production / test (push) Successful in 34s
The raw 'source .env' pattern breaks when values contain special bash characters like ) in passwords or database URLs. This caused deploy:remote to fail with 'syntax error near unexpected token )'. Changes: - Created shared/scripts/lib/load-env.sh: reads .env line-by-line with export instead of source, safely handling special characters - Updated db-backup.sh, db-restore.sh, deploy-remote.sh, remote.sh to use the shared loader - Reordered deploy-remote.sh: git pull now runs first (step 1) so the remote always has the latest scripts before running backup (step 2)
39 lines
1.2 KiB
Bash
39 lines
1.2 KiB
Bash
#!/bin/bash
|
|
# =============================================================================
|
|
# Shared .env loader for Aurora scripts
|
|
# =============================================================================
|
|
# Safely loads .env files without using `source`, which breaks on values
|
|
# containing special bash characters like ), (, !, etc.
|
|
#
|
|
# Usage: source shared/scripts/lib/load-env.sh
|
|
# load_env # loads .env from current directory
|
|
# load_env .env.test # loads a specific file
|
|
# =============================================================================
|
|
|
|
load_env() {
|
|
local env_file="${1:-.env}"
|
|
|
|
if [ ! -f "$env_file" ]; then
|
|
return 0
|
|
fi
|
|
|
|
while IFS= read -r line || [ -n "$line" ]; do
|
|
# Skip comments and empty lines
|
|
[[ -z "$line" || "$line" =~ ^[[:space:]]*# ]] && continue
|
|
|
|
# Skip lines without an = sign
|
|
[[ "$line" != *"="* ]] && continue
|
|
|
|
# Strip leading/trailing whitespace
|
|
line="${line#"${line%%[![:space:]]*}"}"
|
|
|
|
# Remove surrounding quotes from the value (KEY="value" → KEY=value)
|
|
local key="${line%%=*}"
|
|
local value="${line#*=}"
|
|
value="${value#\"}" ; value="${value%\"}"
|
|
value="${value#\'}" ; value="${value%\'}"
|
|
|
|
export "$key=$value"
|
|
done < "$env_file"
|
|
}
|