diff options
author | Bruce Momjian <bruce@momjian.us> | 1999-12-07 22:41:44 +0000 |
---|---|---|
committer | Bruce Momjian <bruce@momjian.us> | 1999-12-07 22:41:44 +0000 |
commit | a0aab48fcd86e3a167c5bd16bb8a16b8a85e9332 (patch) | |
tree | 5020cec37ddbef4dcd594f069e1c71fc4b1d6e94 /src | |
parent | 54847b25d4fe268cd46d9a9a166dbe6e971e5373 (diff) |
Okay, that should put us back in sync. These two patches (src & doc) are
against the sources from one hour ago and contain all the portable and
up
to date stuff.
A few other CVS "householding" things you might want to take care of:
* Remove the src/bin/cleardbdir directory
* Remove the file src/bin/psql/sql_help.h from the repository, as it is
a derived file and is build by the release_prep.
Peter Eisentraut
Diffstat (limited to 'src')
-rw-r--r-- | src/bin/scripts/createdb | 71 | ||||
-rw-r--r-- | src/bin/scripts/createlang.sh | 2 | ||||
-rw-r--r-- | src/bin/scripts/createuser | 71 | ||||
-rw-r--r-- | src/bin/scripts/dropdb | 30 | ||||
-rw-r--r-- | src/bin/scripts/droplang | 13 | ||||
-rw-r--r-- | src/bin/scripts/dropuser | 49 | ||||
-rw-r--r-- | src/bin/scripts/vacuumdb | 50 |
7 files changed, 230 insertions, 56 deletions
diff --git a/src/bin/scripts/createdb b/src/bin/scripts/createdb index 43533a30ff4..bed7c3bec7d 100644 --- a/src/bin/scripts/createdb +++ b/src/bin/scripts/createdb @@ -1,7 +1,7 @@ #!/bin/sh #------------------------------------------------------------------------- # -# createdb.sh-- +# createdb-- # create a postgres database # # This program runs psql with the "-c" option to create @@ -11,7 +11,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.1 1999/12/04 04:53:21 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createdb,v 1.2 1999/12/07 22:41:44 momjian Exp $ # #------------------------------------------------------------------------- @@ -21,6 +21,7 @@ MB= PSQLOPT= dbname= dbcomment= +dbpath= while [ $# -gt 0 ] do @@ -33,12 +34,33 @@ do --host|-h) PSQLOPT="$PSQLOPT -h $2" shift;; + -h*) + PSQLOPT="$PSQLOPT $1" + ;; + --host=*) + PSQLOPT="$PSQLOPT -h "`echo $1 | sed 's/^--host=//'` + ;; --port|-p) PSQLOPT="$PSQLOPT -p $2" shift;; + -p*) + PSQLOPT="$PSQLOPT $1" + ;; + --port=*) + PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--port=//'` + ;; --user|--username|-U) - PSQLOPT="$PSQLOPT -U $2" + PSQLOPT="$PSQLOPT -U '$2'" shift;; + -U*) + PSQLOPT="$PSQLOPT $1" + ;; + --user=*) + PSQLOPT="$PSQLOPT -U "`echo $1 | sed 's/^--user=//'` + ;; + --username=*) + PSQLOPT="$PSQLOPT -U "`echo $1 | sed 's/^--username=//'` + ;; --password|-W) PSQLOPT="$PSQLOPT -W" ;; @@ -49,18 +71,24 @@ do PSQLOPT="$PSQLOPT -o /dev/null" ;; # options converted into SQL command - --dbpath|-D) + --location|-D) dbpath="$2" shift;; + -D*) + dbpath=`echo $1 | sed 's/^-D//'` + ;; + --location=*) + dbpath=`echo $1 | sed 's/^--location=//'` + ;; --encoding|-E) MB=$2 - shift - if [ -z `pg_encoding $MB` ]; then - echo "$CMDNAME: $MB is not a valid encoding name" - exit 1 - fi - ;; - + shift;; + -E*) + MB=`echo $1 | sed 's/^-E//'` + ;; + --encoding=*) + MB=`echo $1 | sed 's/^--encoding=//'` + ;; -*) echo "$CMDNAME: Unrecognized option: $1. Try -? for help." exit 1 @@ -78,17 +106,26 @@ done if [ "$usage" ]; then - echo "Usage: $CMDNAME [-h <server>] [-p <port>] [-D <path>] \\" - echo " [-E <encoding>] [-U <username>] [-W] dbname [description]" + echo "Usage: $CMDNAME [-h server] [-p port] [-D path] \\" + echo " [-E encoding] [-U username] dbname [description]" exit 0 fi + +if [ "$MB" -a -z "`pg_encoding '$MB'`" ]; then + echo "$CMDNAME: \"$MB\" is not a valid encoding name." + exit 1 +fi + if [ -z "$dbname" ]; then echo "$CMDNAME: Missing required argument database name. Try -? for help." exit 1 fi +dbpath=`echo $dbpath | sed "s/'/\\\\\'/g"` +dbname=`echo $dbname | sed 's/\"/\\\"/g'` + withstring= [ "$dbpath" ] && withstring="$withstring LOCATION = '$dbpath'" [ "$MB" ] && withstring="$withstring ENCODING = '$MB'" @@ -103,10 +140,12 @@ fi # Insert comment as well, if requested [ -z "$dbcomment" ] && exit 0 -psql $PSQLOPT -d template1 -c "COMMENT ON DATABASE \"$dbname\" IS \'$dbcomment\'" +dbcomment=`echo $dbcomment | sed "s/'/\\\\\'/g"` + +psql $PSQLOPT -d template1 -c "COMMENT ON DATABASE \"$dbname\" IS '$dbcomment'" if [ $? -ne 0 ]; then - echo "$CMDNAME: Comment creation failed." + echo "$CMDNAME: Comment creation failed. (Database was created.)" exit 1 fi -exit 0
\ No newline at end of file +exit 0 diff --git a/src/bin/scripts/createlang.sh b/src/bin/scripts/createlang.sh index 460bca1481e..2b39eaa7125 100644 --- a/src/bin/scripts/createlang.sh +++ b/src/bin/scripts/createlang.sh @@ -8,7 +8,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.1 1999/12/05 20:02:48 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createlang.sh,v 1.2 1999/12/07 22:41:44 momjian Exp $ # #------------------------------------------------------------------------- diff --git a/src/bin/scripts/createuser b/src/bin/scripts/createuser index c3d00d1ea71..8eb9d55456e 100644 --- a/src/bin/scripts/createuser +++ b/src/bin/scripts/createuser @@ -8,7 +8,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createuser,v 1.2 1999/12/05 20:52:54 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/createuser,v 1.3 1999/12/07 22:41:44 momjian Exp $ # # Note - this should NOT be setuid. # @@ -35,6 +35,7 @@ else ECHO_C='\c' fi + while [ $# -gt 0 ] do case "$1" in @@ -46,17 +47,38 @@ do --host|-h) PSQLOPT="$PSQLOPT -h $2" shift;; + -h*) + PSQLOPT="$PSQLOPT $1" + ;; + --host=*) + PSQLOPT="$PSQLOPT -h "`echo $1 | sed 's/^--host=//'` + ;; --port|-p) PSQLOPT="$PSQLOPT -p $2" shift;; -# Uncomment these lines if you need the -U and -W options. -# They are confusing in this context, however. -# --user|--username|-U) -# PSQLOPT="$PSQLOPT -U $2" -# shift;; -# --password|-W) -# PSQLOPT="$PSQLOPT -W" -# ;; + -p*) + PSQLOPT="$PSQLOPT $1" + ;; + --port=*) + PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--port=//'` + ;; +# Note: These two specify the user to connect as (like in psql), +# not the user you're creating. + --user|--username|-U) + PSQLOPT="$PSQLOPT -U '$2'" + shift;; + -U*) + PSQLOPT="$PSQLOPT $1" + ;; + --user=*) + PSQLOPT="$PSQLOPT -U "`echo $1 | sed 's/^--user=//'` + ;; + --username=*) + PSQLOPT="$PSQLOPT -U "`echo $1 | sed 's/^--username=//'` + ;; + --password|-W) + PSQLOPT="$PSQLOPT -W" + ;; --echo|-e) PSQLOPT="$PSQLOPT -e" ;; @@ -76,6 +98,15 @@ do --no-adduser|-A) CanAddUser=f ;; + --sysid|-i) + SysID=$2 + shift;; + --sysid=*) + SysID=`echo $1 | sed 's/^--sysid=//'` + ;; + -i*) + SysID=`echo $1 | sed 's/^-i//'` + ;; --pwprompt|--pw|-P) PwPrompt=t ;; @@ -94,11 +125,18 @@ done # Help if [ "$usage" ]; then - echo "Usage: $CMDNAME [-h <server>] [-p <port>] [-d|-D] [-a|-A] [-P] [username]" + echo "Usage: $CMDNAME [-h server] [-p port] [-d|-D] [-a|-A] [-P] [-i id] [username]" exit 0 fi +if [ "$SysID" ]; then + if [ "$SysID" != "`echo $SysID | sed 's/[^0-9]//g'`" ]; then + echo "$CMDNAME: User sysid must be a positive number." + exit 1 + fi +fi + # Get missing user attributes if [ -z "$NewUser" ]; then @@ -108,12 +146,12 @@ if [ -z "$NewUser" ]; then fi if [ "$PwPrompt" ]; then - $ECHO_N "Enter password for user $NewUser: "$ECHO_C + $ECHO_N "Enter password for user \"$NewUser\": "$ECHO_C read Password fi if [ -z "$CanCreateDb" ]; then - $ECHO_N "Is the new user allowed to create databases? (y/n) "$ECHO_C + $ECHO_N "Shall the new user be allowed to create databases? (y/n) "$ECHO_C read REPLY [ $? -ne 0 ] && exit 1 if [ $REPLY = "y" -o $REPLY = "Y" ]; then @@ -138,9 +176,16 @@ fi # # build SQL command # +NewUser=`echo $NewUser | sed 's/\"/\\\"/g'` +Password=`echo $Password | sed 's/\"/\\\"/g'` + QUERY="CREATE USER \"$NewUser\"" -[ "$Password" ] && QUERY="$QUERY WITH PASSWORD \"$Password\"" +SUBQUERY= +[ "$SysID" ] && SUBQUERY="$SUBQUERY SYSID $SysID" +[ "$Password" ] && SUBQUERY="$SUBQUERY PASSWORD \"$Password\"" +[ "$SUBQUERY" ] && QUERY="$QUERY WITH $SUBQUERY" + [ "$CanCreateDb" = t ] && QUERY="$QUERY CREATEDB" [ "$CanCreateDb" = f ] && QUERY="$QUERY NOCREATEDB" [ "$CanAddUser" = t ] && QUERY="$QUERY CREATEUSER" diff --git a/src/bin/scripts/dropdb b/src/bin/scripts/dropdb index 93727fd2525..8ef22fce84d 100644 --- a/src/bin/scripts/dropdb +++ b/src/bin/scripts/dropdb @@ -10,7 +10,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropdb,v 1.2 1999/12/05 20:52:54 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropdb,v 1.3 1999/12/07 22:41:44 momjian Exp $ # #------------------------------------------------------------------------- @@ -31,6 +31,7 @@ else ECHO_C='\c' fi + while [ $# -gt 0 ] do case "$1" in @@ -42,12 +43,33 @@ do --host|-h) PSQLOPT="$PSQLOPT -h $2" shift;; + -h*) + PSQLOPT="$PSQLOPT $1" + ;; + --host=*) + PSQLOPT="$PSQLOPT -h "`echo $1 | sed 's/^--host=//'` + ;; --port|-p) PSQLOPT="$PSQLOPT -p $2" shift;; + -p*) + PSQLOPT="$PSQLOPT $1" + ;; + --port=*) + PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--port=//'` + ;; --user|--username|-U) - PSQLOPT="$PSQLOPT -U $2" + PSQLOPT="$PSQLOPT -U '$2'" shift;; + -U*) + PSQLOPT="$PSQLOPT $1" + ;; + --user=*) + PSQLOPT="$PSQLOPT -U "`echo $1 | sed 's/^--user=//'` + ;; + --username=*) + PSQLOPT="$PSQLOPT -U "`echo $1 | sed 's/^--username=//'` + ;; --password|-W) PSQLOPT="$PSQLOPT -W" ;; @@ -74,7 +96,7 @@ done if [ "$usage" ]; then - echo "Usage: $CMDNAME [-h <server>] [-p <port>] [-U <username>] [-W] [-i] dbname" + echo "Usage: $CMDNAME [-h server] [-p port] [-U username] [-i] dbname" exit 0 fi @@ -94,6 +116,8 @@ if [ "$forcedel" = f ]; then fi +dbname=`echo $dbname | sed 's/\"/\\\"/g'` + psql $PSQLOPT -d template1 -c "DROP DATABASE \"$dbname\"" if [ $? -ne 0 ]; then echo "$CMDNAME: Database removal failed." diff --git a/src/bin/scripts/droplang b/src/bin/scripts/droplang index dffe7dc8877..2ff0ddf30ea 100644 --- a/src/bin/scripts/droplang +++ b/src/bin/scripts/droplang @@ -8,7 +8,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.2 1999/12/05 20:52:54 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/droplang,v 1.3 1999/12/07 22:41:44 momjian Exp $ # #------------------------------------------------------------------------- @@ -20,6 +20,17 @@ langname= echo= list= +# Check for echo -n vs echo \c + +if echo '\c' | grep -s c >/dev/null 2>&1 +then + ECHO_N="echo -n" + ECHO_C="" +else + ECHO_N="echo" + ECHO_C='\c' +fi + # ---------- # Get options, language name and dbname diff --git a/src/bin/scripts/dropuser b/src/bin/scripts/dropuser index 9b631d5c9b9..bec2d9bb218 100644 --- a/src/bin/scripts/dropuser +++ b/src/bin/scripts/dropuser @@ -2,13 +2,13 @@ #------------------------------------------------------------------------- # # dropuser-- -# Utility for remocing a user from the PostgreSQL database. +# Utility for removing a user from the PostgreSQL database. # # Copyright (c) 1994, Regents of the University of California # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropuser,v 1.2 1999/12/05 20:52:54 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/dropuser,v 1.3 1999/12/07 22:41:44 momjian Exp $ # # Note - this should NOT be setuid. # @@ -17,6 +17,7 @@ CMDNAME=`basename $0` PSQLOPT= forcedel=t +DelUser= # Check for echo -n vs echo \c @@ -29,6 +30,7 @@ else ECHO_C='\c' fi + while [ $# -gt 0 ] do case "$1" in @@ -40,17 +42,38 @@ do --host|-h) PSQLOPT="$PSQLOPT -h $2" shift;; + -h*) + PSQLOPT="$PSQLOPT $1" + ;; + --host=*) + PSQLOPT="$PSQLOPT -h "`echo $1 | sed 's/^--host=//'` + ;; --port|-p) PSQLOPT="$PSQLOPT -p $2" shift;; -# Uncomment these lines if you need the -U and -W options. -# They are confusing in this context, however. -# --user|--username|-U) -# PSQLOPT="$PSQLOPT -U $2" -# shift;; -# --password|-W) -# PSQLOPT="$PSQLOPT -W" -# ;; + -p*) + PSQLOPT="$PSQLOPT $1" + ;; + --port=*) + PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--port=//'` + ;; +# Note: These two specify the user to connect as (like in psql), +# not the user you're dropping. + --user|--username|-U) + PSQLOPT="$PSQLOPT -U '$2'" + shift;; + -U*) + PSQLOPT="$PSQLOPT $1" + ;; + --user=*) + PSQLOPT="$PSQLOPT -U "`echo $1 | sed 's/^--user=//'` + ;; + --username=*) + PSQLOPT="$PSQLOPT -U "`echo $1 | sed 's/^--username=//'` + ;; + --password|-W) + PSQLOPT="$PSQLOPT -W" + ;; --echo|-e) PSQLOPT="$PSQLOPT -e" ;; @@ -76,7 +99,7 @@ done # Help if [ "$usage" ]; then - echo "Usage: $CMDNAME [-h <server>] [-p <port>] [-i] [username]" + echo "Usage: $CMDNAME [-h server] [-p port] [-i] [username]" exit 0 fi @@ -84,7 +107,7 @@ fi if [ -z "$DelUser" ]; then $ECHO_N "Enter name of user to delete: "$ECHO_C - read NewUser + read DelUser [ $? -ne 0 ] && exit 1 fi @@ -99,6 +122,8 @@ if [ "$forcedel" = f ]; then fi +DelUser=`echo $DelUser | sed 's/\"/\\\"/g'` + psql $PSQLOPT -d template1 -c "DROP USER \"$DelUser\"" if [ $? -ne 0 ]; then diff --git a/src/bin/scripts/vacuumdb b/src/bin/scripts/vacuumdb index 6e9aa2f43a2..4998aa44cf0 100644 --- a/src/bin/scripts/vacuumdb +++ b/src/bin/scripts/vacuumdb @@ -11,7 +11,7 @@ # # # IDENTIFICATION -# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/vacuumdb,v 1.2 1999/12/05 20:02:49 momjian Exp $ +# $Header: /cvsroot/pgsql/src/bin/scripts/Attic/vacuumdb,v 1.3 1999/12/07 22:41:44 momjian Exp $ # #------------------------------------------------------------------------- @@ -21,6 +21,7 @@ PSQLOPT= verbose= analyze= table= +dbname= while [ $# -gt 0 ] do @@ -33,12 +34,33 @@ do --host|-h) PSQLOPT="$PSQLOPT -h $2" shift;; + -h*) + PSQLOPT="$PSQLOPT $1" + ;; + --host=*) + PSQLOPT="$PSQLOPT -h "`echo $1 | sed 's/^--host=//'` + ;; --port|-p) PSQLOPT="$PSQLOPT -p $2" shift;; + -p*) + PSQLOPT="$PSQLOPT $1" + ;; + --port=*) + PSQLOPT="$PSQLOPT -p "`echo $1 | sed 's/^--port=//'` + ;; --user|--username|-U) - PSQLOPT="$PSQLOPT -U $2" + PSQLOPT="$PSQLOPT -U '$2'" shift;; + -U*) + PSQLOPT="$PSQLOPT $1" + ;; + --user=*) + PSQLOPT="$PSQLOPT -U "`echo $1 | sed 's/^--user=//'` + ;; + --username=*) + PSQLOPT="$PSQLOPT -U "`echo $1 | sed 's/^--username=//'` + ;; --password|-W) PSQLOPT="$PSQLOPT -W" ;; @@ -48,6 +70,9 @@ do --quiet|-q) PSQLOPT="$PSQLOPT -o /dev/null" ;; + --dbname|--database|-d) + dbname="$2" + shift;; -d*) dbname=`echo $1 | sed 's/^-d//'` ;; @@ -59,21 +84,26 @@ do ;; # options converted into SQL command --analyze|-z) - analyze="analyze" + analyze="ANALYZE " ;; --table|-t) - table=$2 + table="$2" shift;; + -t*) + table=`echo $1 | sed 's/^-t//'` + ;; + --table=*) + table=`echo $1 | sed 's/^--table=//'` + ;; --verbose|-v) - verbose="verbose" + verbose="VERBOSE " ;; -*) echo "$CMDNAME: Unrecognized option: $1. Try -? for help." exit 1 ;; - - *) + *) dbname="$1" ;; esac @@ -82,7 +112,7 @@ done if [ "$usage" ]; then - echo "Usage: $CMDNAME [-h <server>] [-p <port>] [-U <username>] [-W] [-d <dbname>] \\" + echo "Usage: $CMDNAME [-h server] [-p port] [-U username] [-d dbname] \\" echo " [-z|--analyze] [-v|--verbose] [-t|--table 'table[(columns)]'] [dbname]" exit 0 fi @@ -92,10 +122,10 @@ if [ -z "$dbname" ]; then exit 1 fi -psql $PSQLOPT -d "$dbname" -c "VACUUM $verbose $analyze $table" +psql $PSQLOPT -d "$dbname" -c "VACUUM $verbose$analyze$table" if [ $? -ne 0 ]; then - echo "$CMDNAME: Database vacuum failed." + echo "$CMDNAME: Vacuum failed." exit 1 fi |