forked from garberlog/ARIS
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added script to setup postgres database using settings in config
- Loading branch information
Showing
4 changed files
with
69 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.0.51 | ||
0.0.52 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
#!/bin/bash | ||
|
||
if [ "$(id -u)" -ne "0" ] && [ "$USER" != "aris" ]; then | ||
echo This script must be run as root | ||
exit 1 | ||
fi | ||
|
||
function getParam() { | ||
NAME=$1 | ||
unset PARAM | ||
shopt -s globstar | ||
CFG=$(cat /etc/aris.cfg | grep config-dir | grep -vm 1 '#') | ||
if [ $? -eq 0 ]; then | ||
CFG=$(echo ${CFG#"config-dir"} | xargs) | ||
for f in $(ls -d -1 $CFG//**/*); do | ||
PARAM=$(cat $f | grep $NAME | grep -vm 1 '#') | ||
if [ $? -eq 0 ]; then | ||
PARAM=$(echo ${PARAM#"$NAME"} | xargs) | ||
break | ||
else | ||
unset PARAM | ||
fi | ||
done | ||
fi | ||
if [ -z "$PARAM" ]; then | ||
PARAM=$(cat /etc/aris.cfg | grep $NAME | grep -vm 1 '#') | ||
if [ $? -eq 0 ]; then | ||
PARAM=$(echo ${PARAM#"$NAME"} | xargs) | ||
else | ||
unset PARAM | ||
fi | ||
fi | ||
} | ||
|
||
getParam db-name | ||
if [ -z "$PARAM" ]; then | ||
echo db-name not set in config | ||
exit 1 | ||
else | ||
DBNAME=$PARAM | ||
fi | ||
|
||
getParam db-user | ||
if [ -z "$PARAM" ]; then | ||
echo db-user not set in config | ||
exit 1 | ||
else | ||
DBUSER=$PARAM | ||
fi | ||
|
||
getParam db-pass | ||
if [ -z "$PARAM" ]; then | ||
echo db-pass not set in config | ||
exit 1 | ||
else | ||
DBPASS=$PARAM | ||
fi | ||
|
||
sudo -u postgres psql -c "CREATE DATABASE $DBNAME;" | ||
sudo -u postgres psql -c "CREATE USER $DBUSER;" | ||
sudo -u postgres psql -c "ALTER USER $DBUSER with encrypted password '$DBPASS';" | ||
sudo -u postgres psql -c "grant all privileges on database $DBNAME to $DBUSER;" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters