Add "-D location" to specify alternate database location.

This commit is contained in:
Thomas G. Lockhart 1997-11-07 06:25:25 +00:00
parent 75d5ce28ea
commit c97f6fd197
1 changed files with 45 additions and 25 deletions

View File

@ -11,60 +11,80 @@
# #
# #
# IDENTIFICATION # IDENTIFICATION
# $Header: /cvsroot/pgsql/src/bin/createdb/Attic/createdb.sh,v 1.6 1996/11/17 03:54:44 bryanh Exp $ # $Header: /cvsroot/pgsql/src/bin/createdb/Attic/createdb.sh,v 1.7 1997/11/07 06:25:25 thomas Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
CMDNAME=`basename $0` CMDNAME=`basename $0`
if [ -z "$USER" ]; then if [ -z "$USER" ]; then
if [ -z "$LOGNAME" ]; then if [ -z "$LOGNAME" ]; then
if [ -z "`whoami`" ]; then if [ -z "`whoami`" ]; then
echo "$CMDNAME: cannot determine user name" echo "$CMDNAME: cannot determine user name"
exit 1 exit 1
fi
else
USER=$LOGNAME
export USER
fi fi
else
USER=$LOGNAME
export USER
fi
fi fi
dbname=$USER dbname=$USER
while test -n "$1" while test -n "$1"
do do
case $1 in case $1 in
-a) AUTHSYS=$2; shift;; --help) usage=1;;
-h) PGHOST=$2; shift;;
-p) PGPORT=$2; shift;; -a) AUTHSYS=$2; shift;;
*) dbname=$1;; -h) PGHOST=$2; shift;;
esac -p) PGPORT=$2; shift;;
shift; -D) dbpath=$2; shift;;
-*) echo "$CMDNAME: unrecognized parameter $1"; usage=1;;
*) dbname=$1;;
esac
shift;
done done
if [ "$usage" ]; then
echo "Usage: $CMDNAME -a <authtype> -h <server> -p <portnumber> -D <location> [dbname]"
exit 1
fi
if [ -z "$AUTHSYS" ]; then if [ -z "$AUTHSYS" ]; then
AUTHOPT="" AUTHOPT=""
else else
AUTHOPT="-a $AUTHSYS" AUTHOPT="-a $AUTHSYS"
fi fi
if [ -z "$PGHOST" ]; then if [ -z "$PGHOST" ]; then
PGHOSTOPT="" PGHOSTOPT=""
else else
PGHOSTOPT="-h $PGHOST" PGHOSTOPT="-h $PGHOST"
fi fi
if [ -z "$PGPORT" ]; then if [ -z "$PGPORT" ]; then
PGPORTOPT="" PGPORTOPT=""
else else
PGPORTOPT="-p $PGPORT" PGPORTOPT="-p $PGPORT"
fi fi
psql -tq $AUTHOPT $PGHOSTOPT $PGPORTOPT -c "create database $dbname" template1 if [ -z "$dbpath" ]; then
location=""
else
# if [ ! -d "$dbpath"/base ]; then
# echo "$CMDNAME: database creation failed on $dbname."
# echo "directory $dbpath/base not found."
# exit 1
# fi
location="with location = '$dbpath'"
fi
psql -tq $AUTHOPT $PGHOSTOPT $PGPORTOPT -c "create database $dbname $location" template1
if [ $? -ne 0 ]; then if [ $? -ne 0 ]; then
echo "$CMDNAME: database creation failed on $dbname." echo "$CMDNAME: database creation failed on $dbname."
exit 1 exit 1
fi fi
exit 0 exit 0