#!/bin/sh
#
# sh sql/setup_dbuser.sh $DBUSER $DBPASSWD $DBROOT_PWD

DBUSER=$1
DBPASSWD=$2

DBROOT_PWD=$3

#
#  Usage
#
if [ $# -lt 3 ]
then
	echo "> sh sql/setup_dbuser.sh DBUSER DBPASSWD DBROOT_PWD"
exit
fi

##
## Setup Admin Password
##
#psql -c "alter user postgres with password '$DBROOT_PWD'" template1


##
## Setup User Password
##

#createuser -U postgres $DBUSER --no-superuser --no-createdb --no-createrole

# for 7.X?
createuser -U postgres --createdb --no-adduser -h localhost $DBUSER 

psql -U postgres -h localhost -c "alter user $DBUSER encrypted password '$DBPASSWD'" template1


echo "Done. Account $DBUSER was created"

#
# dropuser -U postgres  -h localhost $DBUSER 
#

