#!/bin/sh
#
# sh sql/create1db.sh $DBUSER $DBPASSWD $DBNAME $DBTABLE 

DBADMIN=$1
DBADMIN_PWD=$2

DBUSER=$3
DBUSER_PWD=$4

DBNAME=$5
DBTABLE=$6

#
#  Usage
#
if [ $# -lt 6 ]
then
	echo "> sh sql/create1db.sh DBADMIN DBADMIN_PWD DBUSER DBUSER_PWD DBNAME DBTABLE "
exit
fi


######################################
# Create Database
######################################

#echo ""
#echo -n "Create database $DBNAME ? y/n"
#read CREATEDB
CREATEDB=y

if [ $CREATEDB = "y" ]
then
	#echo "Type root password for postgresql ... "
	#createdb -U postgres $DBNAME
	echo "Type $DBADMIN password for postgresql ... "
	createdb -h localhost -U $DBADMIN $DBNAME
fi

######################################
# Create Tables and Set Permission
######################################

psql -h localhost -e -f $DBTABLE -U $DBADMIN $DBNAME 





echo "Done. DB $DBNAME created"

