fix env configuring

This commit is contained in:
Doctor Delpy 2025-12-11 11:02:18 +03:00
parent 8db69bbc09
commit ecd4970dd5
1 changed files with 17 additions and 7 deletions

View File

@ -115,6 +115,12 @@ sanitize_assignment() {
value="${value#\'}"
value="${value%\'}"
# Trim leading/trailing whitespace (for safety we assume env values
# do not intentionally start or end with spaces)
if command -v awk >/dev/null 2>&1; then
value=$(printf '%s\n' "$value" | awk '{$1=$1;print}')
fi
echo "$value"
}
@ -271,10 +277,14 @@ update_env() {
ensure_env_default() {
local key=$1 default=$2
local cur
cur=$(ini_val "$key")
local raw cur
raw=$(ini_val "$key")
cur=$(sanitize_assignment "$key" "$raw")
if [[ -z "$cur" ]]; then
update_env "$key" "$default"
elif [[ "$cur" != "$raw" ]]; then
# Normalise the existing value if it only differed by quotes/whitespace
update_env "$key" "$cur"
fi
}
@ -314,11 +324,11 @@ ensure_env_default POSTGRES_HOST "db"
ensure_env_default POSTGRES_PORT "5432"
ensure_env_default POSTGRES_FORWARD_PORT "13580"
pg_user=$(ini_val POSTGRES_USER)
pg_pass=$(ini_val POSTGRES_PASSWORD)
pg_host=$(ini_val POSTGRES_HOST)
pg_port=$(ini_val POSTGRES_PORT)
pg_db=$(ini_val POSTGRES_DB)
pg_user=$(sanitize_assignment POSTGRES_USER "$(ini_val POSTGRES_USER)")
pg_pass=$(sanitize_assignment POSTGRES_PASSWORD "$(ini_val POSTGRES_PASSWORD)")
pg_host=$(sanitize_assignment POSTGRES_HOST "$(ini_val POSTGRES_HOST)")
pg_port=$(sanitize_assignment POSTGRES_PORT "$(ini_val POSTGRES_PORT)")
pg_db=$(sanitize_assignment POSTGRES_DB "$(ini_val POSTGRES_DB)")
update_env DATABASE_URL "postgresql+psycopg2://${pg_user}:${pg_pass}@${pg_host}:${pg_port}/${pg_db}"
ensure_env_default FRONTEND_HTTP_PORT "13300"