Skip to content

Commit c97f6fd

Browse files
author
Thomas G. Lockhart
committed
Add "-D location" to specify alternate database location.
1 parent 75d5ce2 commit c97f6fd

File tree

1 file changed

+45
-25
lines changed

1 file changed

+45
-25
lines changed

src/bin/createdb/createdb.sh

Lines changed: 45 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -11,60 +11,80 @@
1111
#
1212
#
1313
# IDENTIFICATION
14-
# $Header: /cvsroot/pgsql/src/bin/createdb/Attic/createdb.sh,v 1.6 1996/11/17 03:54:44 bryanh Exp $
14+
# $Header: /cvsroot/pgsql/src/bin/createdb/Attic/createdb.sh,v 1.7 1997/11/07 06:25:25 thomas Exp $
1515
#
1616
#-------------------------------------------------------------------------
1717

1818
CMDNAME=`basename $0`
1919

2020
if [ -z "$USER" ]; then
21-
if [ -z "$LOGNAME" ]; then
22-
if [ -z "`whoami`" ]; then
23-
echo "$CMDNAME: cannot determine user name"
24-
exit 1
21+
if [ -z "$LOGNAME" ]; then
22+
if [ -z "`whoami`" ]; then
23+
echo "$CMDNAME: cannot determine user name"
24+
exit 1
25+
fi
26+
else
27+
USER=$LOGNAME
28+
export USER
2529
fi
26-
else
27-
USER=$LOGNAME
28-
export USER
29-
fi
3030
fi
3131

3232
dbname=$USER
3333

3434
while test -n "$1"
3535
do
36-
case $1 in
37-
-a) AUTHSYS=$2; shift;;
38-
-h) PGHOST=$2; shift;;
39-
-p) PGPORT=$2; shift;;
40-
*) dbname=$1;;
41-
esac
42-
shift;
36+
case $1 in
37+
--help) usage=1;;
38+
39+
-a) AUTHSYS=$2; shift;;
40+
-h) PGHOST=$2; shift;;
41+
-p) PGPORT=$2; shift;;
42+
-D) dbpath=$2; shift;;
43+
-*) echo "$CMDNAME: unrecognized parameter $1"; usage=1;;
44+
*) dbname=$1;;
45+
esac
46+
shift;
4347
done
4448

49+
if [ "$usage" ]; then
50+
echo "Usage: $CMDNAME -a <authtype> -h <server> -p <portnumber> -D <location> [dbname]"
51+
exit 1
52+
fi
53+
4554
if [ -z "$AUTHSYS" ]; then
46-
AUTHOPT=""
55+
AUTHOPT=""
4756
else
48-
AUTHOPT="-a $AUTHSYS"
57+
AUTHOPT="-a $AUTHSYS"
4958
fi
5059

5160
if [ -z "$PGHOST" ]; then
52-
PGHOSTOPT=""
61+
PGHOSTOPT=""
5362
else
54-
PGHOSTOPT="-h $PGHOST"
63+
PGHOSTOPT="-h $PGHOST"
5564
fi
5665

5766
if [ -z "$PGPORT" ]; then
58-
PGPORTOPT=""
67+
PGPORTOPT=""
68+
else
69+
PGPORTOPT="-p $PGPORT"
70+
fi
71+
72+
if [ -z "$dbpath" ]; then
73+
location=""
5974
else
60-
PGPORTOPT="-p $PGPORT"
75+
# if [ ! -d "$dbpath"/base ]; then
76+
# echo "$CMDNAME: database creation failed on $dbname."
77+
# echo "directory $dbpath/base not found."
78+
# exit 1
79+
# fi
80+
location="with location = '$dbpath'"
6181
fi
6282

63-
psql -tq $AUTHOPT $PGHOSTOPT $PGPORTOPT -c "create database $dbname" template1
83+
psql -tq $AUTHOPT $PGHOSTOPT $PGPORTOPT -c "create database $dbname $location" template1
6484

6585
if [ $? -ne 0 ]; then
66-
echo "$CMDNAME: database creation failed on $dbname."
67-
exit 1
86+
echo "$CMDNAME: database creation failed on $dbname."
87+
exit 1
6888
fi
6989

7090
exit 0

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy