mirror of
https://github.com/coollabsio/coolify.git
synced 2026-11-06 13:10:37 -04:00
fix(upgrade): quote root user credentials with spaces in the .env file
Installers before 4.5.1 and manual edits could leave ROOT_USERNAME (or the root email or password) with spaces and no quotes. The running container ignores .env because its config is cached, so the next upgrade recreated it and phpdotenv failed, which made every page return HTTP 500. The upgrade now quotes these values before it restarts Coolify. Closes #12375 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
607daf80be
commit
43933ee6cc
@@ -205,7 +205,42 @@ set_env_var() {
|
||||
fi
|
||||
}
|
||||
|
||||
# Quote a value so that Docker Compose and phpdotenv both read it back unchanged (same as install.sh).
|
||||
quote_env_value() {
|
||||
local value="$1"
|
||||
case "$value" in
|
||||
*\'*)
|
||||
value=${value//\\/\\\\}
|
||||
value=${value//\"/\\\"}
|
||||
value=${value//\$/\\\$}
|
||||
printf '"%s"' "$value"
|
||||
;;
|
||||
*)
|
||||
printf "'%s'" "$value"
|
||||
;;
|
||||
esac
|
||||
}
|
||||
|
||||
# Installers before 4.5.1 (and manual edits) wrote root user credentials with spaces without quotes.
|
||||
# phpdotenv cannot parse such a line, so the recreated Coolify container returns HTTP 500 for every page.
|
||||
# Only quote lines that phpdotenv rejects: unquoted values that contain whitespace but no comment.
|
||||
quote_root_user_env_values() {
|
||||
local key value
|
||||
for key in ROOT_USERNAME ROOT_USER_EMAIL ROOT_USER_PASSWORD; do
|
||||
value=$(grep -m1 "^${key}=" "$ENV_FILE" | cut -d '=' -f2-) || continue
|
||||
case "$value" in
|
||||
\"* | \'* | *[[:space:]]\#*) continue ;;
|
||||
*[[:space:]]*) ;;
|
||||
*) continue ;;
|
||||
esac
|
||||
# awk reads the value from the environment, so characters such as | & \ in it stay literal
|
||||
KEY="$key" VALUE="$(quote_env_value "$value")" awk '!done && index($0, ENVIRON["KEY"] "=") == 1 { $0 = ENVIRON["KEY"] "=" ENVIRON["VALUE"]; done = 1 } { print }' "$ENV_FILE" >"$ENV_FILE.tmp" && mv "$ENV_FILE.tmp" "$ENV_FILE"
|
||||
log "Quoted ${key} (its value has spaces)"
|
||||
done
|
||||
}
|
||||
|
||||
log "Checking environment variables..."
|
||||
quote_root_user_env_values
|
||||
set_env_var "REGISTRY_URL" "$REGISTRY_URL"
|
||||
update_env_var "PUSHER_APP_ID" "$(openssl rand -hex 32)"
|
||||
update_env_var "PUSHER_APP_KEY" "$(openssl rand -hex 32)"
|
||||
|
||||
Reference in New Issue
Block a user