blob: a39f33df74a8a0ddcecf40761c4132b9f64e9b4f [file] [log] [blame]
#!/bin/sh
set -e
secret() {
seed=$(cat /run/secrets/seed)
printf "%s:%40s" "${seed}" "$*" | sha256sum | sed 's/[[:space:]].*//'
}
add_user_db() {
user="$1"
psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
CREATE USER ${user} WITH ENCRYPTED PASSWORD '$(secret db:${user})';
CREATE DATABASE ${user} WITH ENCODING='UTF8' OWNER ${user};
EOSQL
}
add_user_db keycloak