bitnami-create-extra-users.sh
1.39 KB
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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/bin/bash
. /opt/bitnami/scripts/libpostgresql.sh
set -x
ls -al /var/postgresql-config /var/postgresql-secret
declare -i user_index=0 db_index=0
while :; do
user_name="$(< /var/postgresql-config/POSTGRESQL_USER_${user_index}_NAME)"
user_password="$(< /var/postgresql-secret/POSTGRESQL_USER_${user_index}_PASSWORD)"
if [[ -z $user_name ]]; then
break
fi
postgresql_ensure_user_exists "$user_name" --password "$user_password"
user_index=$((user_index + 1))
if [[ ! -e /var/postgresql-config/POSTGRESQL_USER_${user_index}_NAME ]]; then
break
fi
done
first_user=""
while :; do
database_name="$(< /var/postgresql-config/POSTGRESQL_DATABASE_${db_index}_NAME)"
postgresql_ensure_database_exists "$database_name"
user_index=0
while :; do
user_name="$(< /var/postgresql-config/POSTGRESQL_DATABASE_${db_index}_USER_${user_index})"
if [[ -z $user_name ]]; then
break
elif [[ -z $first_user ]]; then
first_user="$user_name"
else
postgresql_ensure_user_has_database_privileges "$user_name" "$database_name"
fi
user_index=$((user_index + 1))
if [[ ! -e /var/postgresql-config/POSTGRESQL_DATABASE_${db_index}_USER_${user_index} ]]; then
break
fi
done
if [[ $first_user ]]; then
postgresql_ensure_user_has_database_privileges "$first_user" "$database_name"
fi
db_index=$((db_index + 1))
if [[ ! -e /var/postgresql-config/POSTGRESQL_DATABASE_${db_index}_NAME ]]; then
break
fi
done