-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_database.sh
33 lines (23 loc) · 971 Bytes
/
install_database.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
#!/usr/bin/env bash
# This script creates the Master database and configures the initial scripts.
PGDATABASE="mydb"
PGLOGINUSER="muser"
PGLOGINPASSWORD="password"
create_database() {
logger "Creating database ...."
echo "CREATE DATABASE \"${PGDATABASE}\";"
sudo -u postgres psql -c "CREATE DATABASE \"${PGDATABASE}\";"
echo "GRANT ALL PRIVILEGES ON DATABASE \"${PGDATABASE}\" to \"${PGLOGINUSER}\";"
}
# allow a user to connect and login to any databases
create_user() {
logger "Creating a login user ..."
logger "Create login user..."
echo "CREATE ROLE $PGLOGINUSER WITH LOGIN PASSWORD '$PGLOGINPASSWORD';"
sudo -u postgres psql -c "CREATE ROLE $PGLOGINUSER WITH LOGIN PASSWORD '$PGLOGINPASSWORD';"
logger "Allow health user to connect..."
echo "GRANT ALL PRIVILEGES ON DATABASE $PGDATABASE TO $PGLOGINUSER;"
sudo -u postgres psql -c "GRANT ALL PRIVILEGES ON DATABASE $PGDATABASE TO $PGLOGINUSER;"
}
create_database
create_user