-
Notifications
You must be signed in to change notification settings - Fork 46
/
Copy pathinit_dbs.sh
executable file
·28 lines (24 loc) · 1011 Bytes
/
init_dbs.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#!/bin/bash -x
# https://github.com/olivergondza/bash-strict-mode
set -eEuo pipefail
trap 's=$?; echo >&2 "$0: Error on line "$LINENO": $BASH_COMMAND"; exit $s' ERR
if [[ -v POSTGRESQL_USER || -v POSTGRESQL_PASSWORD || -v POSTGRESQL_DATABASE ]]; then
cat >&2 <<EOF
You have mounted the RHSM init_dbs.sh script.
This script is *incompatible* with setting the POSTGRESL_USER/POSTGRESQL_DATABASE environment
variables. This script runs very early and later, the container scripts attempt to run
createuser $POSTGRESQL_USER and if the user already exists, createuser fails and the container
stops.
Either do not mount init_dbs.sh or do not set the POSTGRESQL_USER and POSTGRESQL_DATABASE
environment variables.
EOF
exit 1
fi
for db in rhsm-subscriptions insights unleash; do
psql --set ON_ERROR_STOP=1 <<-EOSQL
CREATE USER "$db" WITH PASSWORD '$db';
CREATE DATABASE "$db";
GRANT ALL PRIVILEGES ON DATABASE "$db" TO "$db";
ALTER USER "$db" WITH SUPERUSER;
EOSQL
done