77# Portions Copyright (c) 1996-2001, PostgreSQL Global Development Group
88# Portions Copyright (c) 1994, Regents of the University of California
99#
10- # $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.31 2001/09/30 22:17:51 momjian Exp $
10+ # $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.32 2002/01/03 05:30:04 momjian Exp $
1111#
1212# -------------------------------------------------------------------------
1313
@@ -125,7 +125,7 @@ if [ -n "$usage" ]; then
125125echo " $CMDNAME installs a procedural language into a PostgreSQL database."
126126echo
127127echo " Usage:"
128- echo " $CMDNAME [options][ langname] dbname"
128+ echo " $CMDNAME [options] langname [ dbname] "
129129echo
130130echo " Options:"
131131echo " -h, --host=HOSTNAME Database server host"
@@ -136,26 +136,23 @@ if [ -n "$usage" ]; then
136136echo " -L, --pglib=DIRECTORY Find language interpreter file in DIRECTORY"
137137echo " -l, --list Show a list of currently installed languages"
138138echo
139- echo " If 'langname' is not specified, you will be prompted interactively."
140- echo " A database name must be specified."
141- echo
142139echo " Report bugs to <pgsql-bugs@postgresql.org>."
143140exit 0
144141fi
145142
146143
147- # ----------
148- # Check that we have a database
149- # ----------
150144if [-z " $dbname " ]; then
151- echo " $CMDNAME : missing required argument database name" 1>&2
152- echo " Try '$CMDNAME --help' for help." 1>&2
153- exit 1
145+ if [" $PGUSER " ]; then
146+ dbname=" $PGUSER "
147+ else
148+ dbname=` ${PATHNAME} pg_id -u -n`
149+ fi
150+ [" $? " -ne 0 ]&& exit 1
154151fi
155152
156153
157154# ----------
158- # List option
155+ # List option, doesn't need langname
159156# ----------
160157if [" $list " ]; then
161158sqlcmd=" SELECT lanname as\" Name\" , lanpltrusted as\" Trusted?\" FROM pg_language WHERE lanispl = TRUE;"
168165
169166
170167# ----------
171- # Check that we have PGLIB
168+ # We can't go any farther without a langname
172169# ----------
173- if [-z " $PGLIB " ]; then
174- PGLIB=' $libdir'
170+ if [-z " $langname " ]; then
171+ echo " $CMDNAME : missing required argument language name" 1>&2
172+ echo " Try '$CMDNAME --help' for help." 1>&2
173+ exit 1
175174fi
176175
177176# ----------
178- # If not given on the command line, ask for the language
177+ # Check that we have PGLIB
179178# ----------
180- if [-z " $langname " ]; then
181- $ECHO_N " Language to install in database$dbname :" $ECHO_C
182- read langname
179+ if [-z " $PGLIB " ]; then
180+ PGLIB=' $libdir'
183181fi
184182
185183# ----------