Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit a974522

Browse files
committed
Added single-letter options and case statement.
1 parent 2d456c4 commit a974522

File tree

1 file changed

+45
-29
lines changed

1 file changed

+45
-29
lines changed

src/bin/initdb/initdb.sh

Lines changed: 45 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
#
2727
#
2828
# IDENTIFICATION
29-
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.9 1996/10/04 20:07:10 scrappy Exp $
29+
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.10 1996/10/05 03:24:47 momjian Exp $
3030
#
3131
#-------------------------------------------------------------------------
3232

@@ -57,34 +57,50 @@ noclean=0
5757
template_only=0
5858
POSTGRES_SUPERUSERNAME=$USER
5959

60-
for ARG ; do
61-
# We would normally use e.g. ${ARG#--username=} to parse the options, but
62-
# there is a bug in some shells that makes that not work (BSD4.4 sh,
63-
# September 1996 -- supposed to be fixed in later release). So we bypass
64-
# the bug with this sed mess.
65-
66-
username_sed=`echo $ARG | sed s/^--username=//`
67-
pgdata_sed=`echo $ARG | sed s/^--pgdata=//`
68-
69-
if [ $ARG = "--debug" -o $ARG = "-d" ]; then
70-
debug=1
71-
echo "Running with debug mode on."
72-
elif [ $ARG = "--noclean" -o $ARG = "-n" ]; then
73-
noclean=1
74-
echo "Running with noclean mode on. Mistakes will not be cleaned up."
75-
elif [ $ARG = "--template" ]; then
76-
template_only=1
77-
echo "updating template1 database only."
78-
elif [ $username_sed. != $ARG. ]; then
79-
POSTGRES_SUPERUSERNAME=$username_sed
80-
elif [ $pgdata_sed. != $ARG. ]; then
81-
PGDATA=$pgdata_sed
82-
else
83-
echo "Unrecognized option '$ARG'. Syntax is:"
84-
echo "initdb [--template] [--debug] [--noclean]" \
85-
"[--username=SUPERUSER] [--pgdata=DATADIR]"
86-
exit 100
87-
fi
60+
while [ "$#" -gt 0 ]
61+
do
62+
# ${ARG#--username=} is not reliable or available on all platforms
63+
64+
case "$1" in
65+
--debug|-d)
66+
debug=1
67+
echo "Running with debug mode on."
68+
;;
69+
--noclean|-n)
70+
noclean=1
71+
echo "Running with noclean mode on. Mistakes will not be cleaned up."
72+
;;
73+
--template|-t)
74+
template_only=1
75+
echo "updating template1 database only."
76+
;;
77+
--username=*)
78+
POSTGRES_SUPERUSERNAME="`echo $1 | sed s/^--username=//`"
79+
;;
80+
-u)
81+
shift
82+
POSTGRES_SUPERUSERNAME="$1"
83+
;;
84+
-u*)
85+
POSTGRES_SUPERUSERNAME="`echo $1 | sed s/^-u//`"
86+
;;
87+
--pgdata=*)
88+
PGDATA="`echo $1 | sed s/^--pgdata=//`"
89+
;;
90+
-r)
91+
shift
92+
PGDATA="$1"
93+
;;
94+
-r*)
95+
PGDATA="`echo $1 | sed s/^-r//`"
96+
;;
97+
*)
98+
echo "Unrecognized option '$1'. Syntax is:"
99+
echo "initdb [-t | --template] [-d | --debug] [-n | --noclean]" \
100+
"[-u SUPSERUSER | --username=SUPERUSER] [-r DATADIR | --pgdata=DATADIR]"
101+
exit 100
102+
esac
103+
shift
88104
done
89105

90106
if [ "$debug" -eq 1 ]; then

0 commit comments

Comments
 (0)