Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve explorer db image config... #21

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 46 additions & 28 deletions app/persistence/postgreSQL/db/createdb.sh
Original file line number Diff line number Diff line change
@@ -1,32 +1,50 @@
#!/usr/bin/env bash

if [[ -z "${DATABASE_USERNAME}" ]]; then
USER=$( jq .pg.username pgconfig.json )
else
USER=$DATABASE_USERNAME
fi
if [[ -z "${DATABASE_DATABASE}" ]]; then
DATABASE=$( jq .pg.database pgconfig.json )
else
DATABASE=$DATABASE_DATABASE
fi
if [[ -z "${DATABASE_PASSWORD}" ]]; then
PASSWD=$(jq .pg.passwd pgconfig.json | sed "y/\"/'/")
else
PASSWD=$DATABASE_PASSWORD
fi
## IF ALREADY CONFIGURED NO NEED TO RECONFIG
if [ ! -f /${PGDATA}/conf.done ]; then

if [[ -z "${DATABASE_USERNAME}" ]]; then
USER=$( jq .pg.username pgconfig.json )
else
USER=$DATABASE_USERNAME
fi
if [[ -z "${DATABASE_DATABASE}" ]]; then
DATABASE=$( jq .pg.database pgconfig.json )
else
DATABASE=$DATABASE_DATABASE
fi
if [[ -z "${DATABASE_PASSWORD}" ]]; then
PASSWD=$(jq .pg.passwd pgconfig.json | sed "y/\"/'/")
else
PASSWD=$DATABASE_PASSWORD
fi

echo "USER=${USER}"
echo "DATABASE=${DATABASE}"
echo "PASSWD=${PASSWD}"
echo "USER=${USER}"
echo "DATABASE=${DATABASE}"
echo "PASSWD=${PASSWD}"

case $OSTYPE in
darwin*) echo "Creating Default user $USER..." ;
psql -U postgres -c "CREATE USER $USER WITH PASSWORD '$PASSWD'" ;
psql postgres -v dbname=$DATABASE -v user=$USER -v passwd=$PASSWD -f ./explorerpg.sql ;
psql postgres -v dbname=$DATABASE -v user=$USER -v passwd=$PASSWD -f ./updatepg.sql ;;
linux*) echo "Creating Default user..." ;
sudo -u postgres psql -U postgres -c "CREATE USER $USER WITH PASSWORD '$PASSWD'" ;
sudo -u postgres psql -v dbname=$DATABASE -v user=$USER -v passwd=$PASSWD -f ./explorerpg.sql ;
sudo -u postgres psql -v dbname=$DATABASE -v user=$USER -v passwd=$PASSWD -f ./updatepg.sql ;;
esac
case $OSTYPE in
darwin*)
echo "Creating Default user $USER..." ;
psql -U postgres -c "CREATE USER $USER WITH PASSWORD '$PASSWD'" ;
psql postgres -v dbname=$DATABASE -v user=$USER -v passwd=$PASSWD -f ./explorerpg.sql ;
psql postgres -v dbname=$DATABASE -v user=$USER -v passwd=$PASSWD -f ./updatepg.sql ;;

linux*)
WHOAMI=`whoami`
if [ "${WHOAMI}" != "postgres" ]; then
echo "Creating Default user..." ;
sudo -u postgres psql -U postgres -c "CREATE USER $USER WITH PASSWORD '$PASSWD'" ;
sudo -u postgres psql -v dbname=$DATABASE -v user=$USER -v passwd=$PASSWD -f ./explorerpg.sql ;
sudo -u postgres psql -v dbname=$DATABASE -v user=$USER -v passwd=$PASSWD -f ./updatepg.sql
else
echo "Creating Default user..." ;
psql -U postgres -c "CREATE USER $USER WITH PASSWORD '$PASSWD'" ;
psql -v dbname=$DATABASE -v user=$USER -v passwd=$PASSWD -f ./explorerpg.sql ;
psql -v dbname=$DATABASE -v user=$USER -v passwd=$PASSWD -f ./updatepg.sql
fi
;;
esac

touch /${PGDATA}/conf.done
fi
2 changes: 1 addition & 1 deletion app/persistence/postgreSQL/db/explorerpg.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
-- SPDX-License-Identifier: Apache-2.0
--

CREATE USER :user WITH PASSWORD :passwd;
-- CREATE USER :user WITH PASSWORD :passwd;
DROP DATABASE IF EXISTS :dbname;
CREATE DATABASE :dbname owner :user;
\c :dbname;
Expand Down