Skip to content
This repository was archived by the owner on Mar 5, 2019. It is now read-only.

Commit 66805d3

Browse files
datedfaustbrian
authored andcommitted
fix: use env variables for database creation (#109)
1 parent 07901bb commit 66805d3

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

modules/database.sh

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ database_drop_user ()
44
{
55
heading "Dropping Database User..."
66

7-
sudo -u postgres dropuser --if-exists "$ARK_DB_USERNAME" | tee -a "$commander_log"
7+
sudo -u postgres dropuser --if-exists "${ARK_DB_USERNAME}" | tee -a "$commander_log"
88

99
success "Dropped Database User!"
1010
}
@@ -13,7 +13,7 @@ database_destroy ()
1313
{
1414
heading "Destroying Database..."
1515

16-
sudo -u postgres dropdb --if-exists "$ARK_DB_DATABASE" | tee -a "$commander_log"
16+
sudo -u postgres dropdb --if-exists "${ARK_DB_DATABASE}" | tee -a "$commander_log"
1717

1818
success "Destroyed Database!"
1919
}
@@ -26,17 +26,17 @@ database_create ()
2626

2727
wait_to_continue
2828

29-
local userExists=$(sudo -u postgres psql -c "SELECT * FROM pg_user WHERE usename = '$USER'" | grep -c "1 row")
29+
local userExists=$(sudo -u postgres psql -c "SELECT * FROM pg_user WHERE username = '${ARK_DB_USERNAME}'" | grep -c "1 row")
3030

3131
if [[ $userExists == 1 ]]; then
32-
read -p "The database user ${USER} already exists, do you want to overwrite it? [y/N] : " choice
32+
read -p "The database user ${ARK_DB_USERNAME} already exists, do you want to overwrite it? [y/N] : " choice
3333

3434
if [[ "$choice" =~ ^(yes|y|Y) ]]; then
35-
sudo -u postgres psql -c "DROP USER $USER" | tee -a "$commander_log"
36-
sudo -u postgres psql -c "CREATE USER $USER WITH PASSWORD 'password' CREATEDB;" | tee -a "$commander_log"
35+
sudo -u postgres psql -c "DROP USER ${ARK_DB_USERNAME}" | tee -a "$commander_log"
36+
sudo -u postgres psql -c "CREATE USER ${ARK_DB_USERNAME} WITH PASSWORD '${ARK_DB_PASSWORD}' CREATEDB;" | tee -a "$commander_log"
3737
fi
3838
else
39-
sudo -u postgres psql -c "CREATE USER $USER WITH PASSWORD 'password' CREATEDB;" | tee -a "$commander_log"
39+
sudo -u postgres psql -c "CREATE USER ${ARK_DB_USERNAME} WITH PASSWORD '${ARK_DB_PASSWORD}' CREATEDB;" | tee -a "$commander_log"
4040
fi
4141

4242
local databaseExists=$(psql -l | grep "${ARK_DB_DATABASE}" | wc -l)

0 commit comments

Comments
 (0)