blob: a39f33df74a8a0ddcecf40761c4132b9f64e9b4f [file] [log] [blame]
Nico Huber5d7a1cb2023-07-23 19:36:14 +00001#!/bin/sh
2
3set -e
4
Nico Huber472cfc72023-07-25 14:20:55 +00005secret() {
6 seed=$(cat /run/secrets/seed)
7 printf "%s:%40s" "${seed}" "$*" | sha256sum | sed 's/[[:space:]].*//'
8}
Nico Huber5d7a1cb2023-07-23 19:36:14 +00009
Nico Huber472cfc72023-07-25 14:20:55 +000010add_user_db() {
11 user="$1"
Nico Huber5d7a1cb2023-07-23 19:36:14 +000012 psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL
Nico Huber472cfc72023-07-25 14:20:55 +000013 CREATE USER ${user} WITH ENCRYPTED PASSWORD '$(secret db:${user})';
14 CREATE DATABASE ${user} WITH ENCODING='UTF8' OWNER ${user};
Nico Huber5d7a1cb2023-07-23 19:36:14 +000015EOSQL
16}
Nico Huber472cfc72023-07-25 14:20:55 +000017
18add_user_db keycloak