#!/bin/sh 

if [ "$USER" != "postgres" ]; then
  echo "$0 must be run by postgres"
fi
echo "Initializing default data base by user $USER ..."

cd

PG_ROOT=/opt/pgsql
PATH=$PATH:$PG_ROOT/bin
PGLIB=$PG_ROOT/lib
PGDATA=$PG_ROOT/data
LD_LIBRARY_PATH=$PGLIB
export PATH PGLIB PGDATA LD_LIBRARY_PATH

dbinfo=`psql -l | grep drupal6`
if [ "_$dbinfo" != "_" ]; then
  echo "Database drupal6 exists:"
  echo $dbinfo;
  exit
fi

# create user www from web access
#createuser -A -D www
#psql -c "alter user www with password 'secret';"

#echo "running... createdb drupal with 8.x createuser command" 
createdb --owner www --encoding UTF8 --template template0 drupal6
createlang plpgsql drupal6

## Do NOT gzip drupal6j.dmp file which will be broken when gunzipped.
#( cd /opt/htdocs/drupal6/; \
#  psql -U www -f custom/drupal6j.dmp drupal6; )
#
