-
Notifications
You must be signed in to change notification settings - Fork 2
/
create_geocint_user.sh
45 lines (37 loc) · 1015 Bytes
/
create_geocint_user.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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/bin/sh
# Set variables
. ${GEOCINT_WORK_DIRECTORY}/config.inc.sh
export PGUSER
PSQL_SELECT='psql -t -A -U $PGUSER -c'
PSQL_COMMAND='psql -q -U $PGUSER -c'
username=$1
if [ -z "${username}" ]; then
printf 'Enter username: '
read -r username
echo
fi
if [ -z "${username}" ]; then
echo "Empty string is not a valid username"
exit 1
fi
if [ -z "$(${PSQL_SELECT} "SELECT to_regrole('geocint_users');")" ]; then
echo "Create group role geocint_users"
${PSQL_COMMAND} "
CREATE ROLE geocint_users;
GRANT pg_monitor TO geocint_users;
GRANT pg_signal_backend TO geocint_users;
"
fi
if [ -z "$(${PSQL_SELECT} "SELECT to_regrole('${username}');")" ]; then
echo "Create login role ${username}"
${PSQL_COMMAND} "
CREATE ROLE ${username} LOGIN;
GRANT geocint_users TO ${username};
"
fi
if [ -z "$(${PSQL_SELECT} "SELECT to_regnamespace('${username}');")" ]; then
echo "Creating user schema ${username}"
${PSQL_COMMAND} "
CREATE SCHEMA AUTHORIZATION ${username};
"
fi