Nico Huber | 5d7a1cb | 2023-07-23 19:36:14 +0000 | [diff] [blame] | 1 | #!/bin/sh |
| 2 | |
| 3 | set -e |
| 4 | |
Nico Huber | 472cfc7 | 2023-07-25 14:20:55 +0000 | [diff] [blame] | 5 | secret() { |
| 6 | seed=$(cat /run/secrets/seed) |
| 7 | printf "%s:%40s" "${seed}" "$*" | sha256sum | sed 's/[[:space:]].*//' |
| 8 | } |
Nico Huber | 5d7a1cb | 2023-07-23 19:36:14 +0000 | [diff] [blame] | 9 | |
Nico Huber | 472cfc7 | 2023-07-25 14:20:55 +0000 | [diff] [blame] | 10 | add_user_db() { |
| 11 | user="$1" |
Nico Huber | 5d7a1cb | 2023-07-23 19:36:14 +0000 | [diff] [blame] | 12 | psql -v ON_ERROR_STOP=1 --username "$POSTGRES_USER" --dbname "$POSTGRES_DB" <<-EOSQL |
Nico Huber | 472cfc7 | 2023-07-25 14:20:55 +0000 | [diff] [blame] | 13 | CREATE USER ${user} WITH ENCRYPTED PASSWORD '$(secret db:${user})'; |
| 14 | CREATE DATABASE ${user} WITH ENCODING='UTF8' OWNER ${user}; |
Nico Huber | 5d7a1cb | 2023-07-23 19:36:14 +0000 | [diff] [blame] | 15 | EOSQL |
| 16 | } |
Nico Huber | 472cfc7 | 2023-07-25 14:20:55 +0000 | [diff] [blame] | 17 | |
| 18 | add_user_db keycloak |