mirror of
https://github.com/alexbelgium/hassio-addons.git
synced 2026-07-18 12:00:31 +02:00
Refactor root user creation logic in 99-run.sh
This commit is contained in:
@@ -97,13 +97,6 @@ setup_root_user() {
|
||||
fi
|
||||
fi
|
||||
|
||||
# Try to connect as root using the default insecure password.
|
||||
if psql "postgres://root:securepassword@${DB_HOSTNAME}:${DB_PORT}/postgres" -c '\q' 2> /dev/null; then
|
||||
bashio::log.info "Detected root user with default password. Updating to new DB_ROOT_PASSWORD..."
|
||||
psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" << EOF
|
||||
ALTER ROLE root WITH PASSWORD '${DB_ROOT_PASSWORD}';
|
||||
EOF
|
||||
else
|
||||
# Check if the root user exists.
|
||||
if ! psql "postgres://${DB_USERNAME}:${DB_PASSWORD}@${DB_HOSTNAME}:${DB_PORT}" -tAc "SELECT 1 FROM pg_roles WHERE rolname='root'" | grep -q 1; then
|
||||
bashio::log.info "Root user does not exist. Creating root user with DB_ROOT_PASSWORD..."
|
||||
@@ -113,7 +106,6 @@ EOF
|
||||
else
|
||||
bashio::log.info "Root user exists with a non-default password. No migration needed."
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Function to set up the database
|
||||
|
||||
Reference in New Issue
Block a user