Skip to content

Commit

Permalink
Added script to setup postgres database using settings in config
Browse files Browse the repository at this point in the history
  • Loading branch information
cicchr committed Apr 14, 2018
1 parent a824f7f commit bc347e9
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 7 deletions.
2 changes: 1 addition & 1 deletion libaris/res/edu/rpi/aris/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.0.51
0.0.52
62 changes: 62 additions & 0 deletions packaging/extra/server/bin/aris-createdb
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;"
6 changes: 3 additions & 3 deletions packaging/extra/server/bin/aris-server
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ run_aris() {
if [ ! pgrep -x "aris-server" &> /dev/null ]; then
rm /tmp/aris*
fi
CFG=$(cat /etc/aris.cfg | grep config-dir)
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
LOGDIR=$(cat $f | grep log-dir)
LOGDIR=$(cat $f | grep log-dir | grep -vm 1 '#')
if [ $? -eq 0 ]; then
LOGDIR=$(echo ${LOGDIR#"log-dir"} | xargs)
break
Expand All @@ -26,7 +26,7 @@ run_aris() {
done
fi
if [ -z "$LOGDIR" ]; then
LOGDIR=$(cat /etc/aris.cfg | grep log-dir)
LOGDIR=$(cat /etc/aris.cfg | grep log-dir | grep -vm 1 '#')
if [ $? -eq 0 ]; then
LOGDIR=$(echo ${LOGDIR#"log-dir"} | xargs)
else
Expand Down
6 changes: 3 additions & 3 deletions packaging/extra/server/bin/aris-update
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ update_aris() {
rm /tmp/aris*
fi
TMP=$(dirname $(mktemp -u))
CFG=$(cat /etc/aris.cfg | grep config-dir)
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
LOGDIR=$(cat $f | grep log-dir)
LOGDIR=$(cat $f | grep log-dir | grep -vm 1 '#')
if [ $? -eq 0 ]; then
LOGDIR=$(echo ${LOGDIR#"log-dir"} | xargs)
break
Expand All @@ -25,7 +25,7 @@ update_aris() {
done
fi
if [ -z "$LOGDIR" ]; then
LOGDIR=$(cat /etc/aris.cfg | grep log-dir)
LOGDIR=$(cat /etc/aris.cfg | grep log-dir | grep -vm 1 '#')
if [ $? -eq 0 ]; then
LOGDIR=$(echo ${LOGDIR#"log-dir"} | xargs)
else
Expand Down

0 comments on commit bc347e9

Please sign in to comment.