28 lines
702 B
Bash
Executable file
28 lines
702 B
Bash
Executable file
#!/bin/sh
|
|
set -e
|
|
|
|
# Run background synchronization once PostgreSQL is up on local unix socket
|
|
sync_credentials() {
|
|
until pg_isready -q -h /var/run/postgresql; do
|
|
sleep 0.5
|
|
done
|
|
|
|
USER="${POSTGRES_USER:-postgres}"
|
|
PASS="${POSTGRES_PASSWORD:-postgres}"
|
|
|
|
psql -v ON_ERROR_STOP=0 -h /var/run/postgresql -U postgres -d postgres <<-EOSQL >/dev/null 2>&1
|
|
DO \$\$
|
|
BEGIN
|
|
IF NOT EXISTS (SELECT FROM pg_catalog.pg_roles WHERE rolname = '$USER') THEN
|
|
CREATE ROLE "$USER" WITH LOGIN SUPERUSER PASSWORD '$PASS';
|
|
ELSE
|
|
ALTER ROLE "$USER" WITH LOGIN SUPERUSER PASSWORD '$PASS';
|
|
END IF;
|
|
END
|
|
\$\$;
|
|
EOSQL
|
|
}
|
|
|
|
sync_credentials &
|
|
|
|
exec docker-entrypoint.sh "$@"
|