Thread: Fix for defaults in createuser

Fix for defaults in createuser

From
Bruce Momjian
Date:
Turns out some of the environment variable tests weren't quoted, making
default answers return 'test' failures, i.e.:

!       if [ $REPLY = "y" -o $REPLY = "Y" ]; then

fixed to:

!       if [ "$REPLY" = "y" -o "$REPLY" = "Y" ]; then

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026
? config.log
? config.cache
? config.status
? GNUmakefile
? src/Makefile.custom
? src/GNUmakefile
? src/Makefile.global
? src/log
? src/crtags
? src/backend/postgres
? src/backend/catalog/global.bki
? src/backend/catalog/global.description
? src/backend/catalog/template1.bki
? src/backend/catalog/template1.description
? src/backend/port/Makefile
? src/bin/initdb/initdb
? src/bin/initlocation/initlocation
? src/bin/ipcclean/ipcclean
? src/bin/pg_config/pg_config
? src/bin/pg_ctl/pg_ctl
? src/bin/pg_dump/pg_dump
? src/bin/pg_dump/pg_restore
? src/bin/pg_dump/pg_dumpall
? src/bin/pg_id/pg_id
? src/bin/pg_passwd/pg_passwd
? src/bin/pgaccess/pgaccess
? src/bin/pgtclsh/Makefile.tkdefs
? src/bin/pgtclsh/Makefile.tcldefs
? src/bin/pgtclsh/pgtclsh
? src/bin/pgtclsh/pgtksh
? src/bin/psql/psql
? src/bin/scripts/createlang
? src/include/config.h
? src/include/stamp-h
? src/interfaces/ecpg/lib/libecpg.so.3.2.0
? src/interfaces/ecpg/preproc/ecpg
? src/interfaces/libpgeasy/libpgeasy.so.2.1
? src/interfaces/libpgtcl/libpgtcl.so.2.1
? src/interfaces/libpq/libpq.so.2.1
? src/interfaces/perl5/blib
? src/interfaces/perl5/Makefile
? src/interfaces/perl5/pm_to_blib
? src/interfaces/perl5/Pg.c
? src/interfaces/perl5/Pg.bs
? src/pl/plperl/blib
? src/pl/plperl/Makefile
? src/pl/plperl/pm_to_blib
? src/pl/plperl/SPI.c
? src/pl/plperl/plperl.bs
? src/pl/plpgsql/src/libplpgsql.so.1.0
? src/pl/tcl/Makefile.tcldefs
Index: src/bin/scripts/createdb
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/bin/scripts/createdb,v
retrieving revision 1.12
diff -c -r1.12 createdb
*** src/bin/scripts/createdb    2000/11/25 19:05:44    1.12
--- src/bin/scripts/createdb    2001/01/21 05:02:11
***************
*** 73,91 ****
          dbpath="$2"
          shift;;
          -D*)
!                 dbpath=`echo $1 | sed 's/^-D//'`
                  ;;
          --location=*)
!                 dbpath=`echo $1 | sed 's/^--location=//'`
                  ;;
      --encoding|-E)
!         MB=$2
          shift;;
          -E*)
!                 MB=`echo $1 | sed 's/^-E//'`
                  ;;
          --encoding=*)
!                 MB=`echo $1 | sed 's/^--encoding=//'`
                  ;;
      -*)
          echo "$CMDNAME: invalid option: $1" 1>&2
--- 73,91 ----
          dbpath="$2"
          shift;;
          -D*)
!                 dbpath=`echo "$1" | sed 's/^-D//'`
                  ;;
          --location=*)
!                 dbpath=`echo "$1" | sed 's/^--location=//'`
                  ;;
      --encoding|-E)
!         MB="$2"
          shift;;
          -E*)
!                 MB=`echo "$1" | sed 's/^-E//'`
                  ;;
          --encoding=*)
!                 MB=`echo "$1" | sed 's/^--encoding=//'`
                  ;;
      -*)
          echo "$CMDNAME: invalid option: $1" 1>&2
***************
*** 138,144 ****

  if [ -z "$dbname" ]; then
          if [ "$PGUSER" ]; then
!                 dbname=$PGUSER
          else
                  dbname=`${PATHNAME}pg_id -u -n`
          fi
--- 138,144 ----

  if [ -z "$dbname" ]; then
          if [ "$PGUSER" ]; then
!                 dbname="$PGUSER"
          else
                  dbname=`${PATHNAME}pg_id -u -n`
          fi
***************
*** 147,154 ****


  # escape the quotes
! dbpath=`echo $dbpath | sed "s/'/\\\\\'/g"`
! dbname=`echo $dbname | sed 's/\"/\\\"/g'`

  withstring=
  [ "$dbpath" ] &&     withstring="$withstring LOCATION = '$dbpath'"
--- 147,154 ----


  # escape the quotes
! dbpath=`echo "$dbpath" | sed "s/'/\\\\\'/g"`
! dbname=`echo "$dbname" | sed 's/\"/\\\"/g'`

  withstring=
  [ "$dbpath" ] &&     withstring="$withstring LOCATION = '$dbpath'"
***************
*** 164,170 ****
  # Insert comment as well, if requested
  [ -z "$dbcomment" ] && exit 0

! dbcomment=`echo $dbcomment | sed "s/'/\\\\\'/g"`

  ${PATHNAME}psql $PSQLOPT -d template1 -c "COMMENT ON DATABASE \"$dbname\" IS '$dbcomment'"
  if [ $? -ne 0 ]; then
--- 164,170 ----
  # Insert comment as well, if requested
  [ -z "$dbcomment" ] && exit 0

! dbcomment=`echo "$dbcomment" | sed "s/'/\\\\\'/g"`

  ${PATHNAME}psql $PSQLOPT -d template1 -c "COMMENT ON DATABASE \"$dbname\" IS '$dbcomment'"
  if [ $? -ne 0 ]; then
Index: src/bin/scripts/createlang.sh
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/bin/scripts/createlang.sh,v
retrieving revision 1.21
diff -c -r1.21 createlang.sh
*** src/bin/scripts/createlang.sh    2000/11/25 19:05:44    1.21
--- src/bin/scripts/createlang.sh    2001/01/21 05:02:11
***************
*** 81,100 ****
          dbname="$2"
          shift;;
          -d*)
!                 dbname=`echo $1 | sed 's/^-d//'`
                  ;;
          --dbname=*)
!                 dbname=`echo $1 | sed 's/^--dbname=//'`
                  ;;
  # misc options
      --pglib|-L)
                  PGLIB="$2"
                  shift;;
          -L*)
!                 PGLIB=`echo $1 | sed 's/^-L//'`
                  ;;
          --pglib=*)
!                 PGLIB=`echo $1 | sed 's/^--pglib=//'`
                  ;;

      -*)
--- 81,100 ----
          dbname="$2"
          shift;;
          -d*)
!                 dbname=`echo "$1" | sed 's/^-d//'`
                  ;;
          --dbname=*)
!                 dbname=`echo "$1" | sed 's/^--dbname=//'`
                  ;;
  # misc options
      --pglib|-L)
                  PGLIB="$2"
                  shift;;
          -L*)
!                 PGLIB=`echo "$1" | sed 's/^-L//'`
                  ;;
          --pglib=*)
!                 PGLIB=`echo "$1" | sed 's/^--pglib=//'`
                  ;;

      -*)
Index: src/bin/scripts/createuser
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/bin/scripts/createuser,v
retrieving revision 1.15
diff -c -r1.15 createuser
*** src/bin/scripts/createuser    2000/11/25 19:05:44    1.15
--- src/bin/scripts/createuser    2001/01/21 05:02:11
***************
*** 97,109 ****
          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
--- 97,109 ----
          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
***************
*** 114,120 ****
          exit 1
          ;;
           *)
!         NewUser=$1
          ;;
      esac
      shift;
--- 114,120 ----
          exit 1
          ;;
           *)
!         NewUser="$1"
          ;;
      esac
      shift;
***************
*** 182,195 ****
              echo "Passwords didn't match." 1>&2
              exit 1
          fi
!     Password=$FirstPw
  fi

  if [ -z "$CanCreateDb" ]; then
      $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
          CanCreateDb=t
      else
          CanCreateDb=f
--- 182,195 ----
              echo "Passwords didn't match." 1>&2
              exit 1
          fi
!     Password="$FirstPw"
  fi

  if [ -z "$CanCreateDb" ]; then
      $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
          CanCreateDb=t
      else
          CanCreateDb=f
***************
*** 200,206 ****
      $ECHO_N "Shall the new user be allowed to create more new users? (y/n) "$ECHO_C
      read REPLY
      [ $? -ne 0 ] && exit 1
!     if [ $REPLY = "y" -o $REPLY = "Y" ]; then
          CanAddUser=t
      else
          CanAddUser=f
--- 200,206 ----
      $ECHO_N "Shall the new user be allowed to create more new users? (y/n) "$ECHO_C
      read REPLY
      [ $? -ne 0 ] && exit 1
!     if [ "$REPLY" = "y" -o "$REPLY" = "Y" ]; then
          CanAddUser=t
      else
          CanAddUser=f
***************
*** 211,218 ****
  #
  # build SQL command
  #
! NewUser=`echo $NewUser | sed 's/\"/\\\"/g'`
! Password=`echo $Password | sed 's/\"/\\\"/g'`

  QUERY="CREATE USER \"$NewUser\""

--- 211,218 ----
  #
  # build SQL command
  #
! NewUser=`echo "$NewUser" | sed 's/\"/\\\"/g'`
! Password=`echo "$Password" | sed 's/\"/\\\"/g'`

  QUERY="CREATE USER \"$NewUser\""

Index: src/bin/scripts/droplang
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/bin/scripts/droplang,v
retrieving revision 1.11
diff -c -r1.11 droplang
*** src/bin/scripts/droplang    2000/11/25 19:05:44    1.11
--- src/bin/scripts/droplang    2001/01/21 05:02:11
***************
*** 81,90 ****
          dbname="$2"
          shift;;
          -d*)
!                 dbname=`echo $1 | sed 's/^-d//'`
                  ;;
          --dbname=*)
!                 dbname=`echo $1 | sed 's/^--dbname=//'`
                  ;;

      -*)
--- 81,90 ----
          dbname="$2"
          shift;;
          -d*)
!                 dbname=`echo "$1" | sed 's/^-d//'`
                  ;;
          --dbname=*)
!                 dbname=`echo "$1" | sed 's/^--dbname=//'`
                  ;;

      -*)
***************
*** 203,209 ****
      echo "$CMDNAME: external error" 1>&2
      exit 1
  fi
! if [ $res -ne 0 ]; then
      echo "$CMDNAME: There are $res functions/trigger procedures declared in language" 1>&2
          echo "$lancomp. Language not removed." 1>&2
      exit 1
--- 203,209 ----
      echo "$CMDNAME: external error" 1>&2
      exit 1
  fi
! if [ "$res" -ne 0 ]; then
      echo "$CMDNAME: There are $res functions/trigger procedures declared in language" 1>&2
          echo "$lancomp. Language not removed." 1>&2
      exit 1
Index: src/bin/scripts/dropuser
===================================================================
RCS file: /home/projects/pgsql/cvsroot/pgsql/src/bin/scripts/dropuser,v
retrieving revision 1.10
diff -c -r1.10 dropuser
*** src/bin/scripts/dropuser    2000/11/25 19:05:44    1.10
--- src/bin/scripts/dropuser    2001/01/21 05:02:11
***************
*** 134,140 ****
  fi


! DelUser=`echo $DelUser | sed 's/\"/\\\"/g'`

  ${PATHNAME}psql $PSQLOPT -d template1 -c "DROP USER \"$DelUser\""

--- 134,140 ----
  fi


! DelUser=`echo "$DelUser" | sed 's/\"/\\\"/g'`

  ${PATHNAME}psql $PSQLOPT -d template1 -c "DROP USER \"$DelUser\""


Re: Fix for defaults in createuser

From
Peter Eisentraut
Date:
Bruce Momjian writes:

> !       if [ $REPLY = "y" -o $REPLY = "Y" ]; then
>
> fixed to:
>
> !       if [ "$REPLY" = "y" -o "$REPLY" = "Y" ]; then

Good.

FYI, it's never necessary to quote the right side of a shell variable
assignment.

FOO=$BAR

always works, as does

case $foo in ...

But it doesn't hurt of course.

--
Peter Eisentraut      peter_e@gmx.net       http://yi.org/peter-e/


Re: Fix for defaults in createuser

From
Bruce Momjian
Date:
> Bruce Momjian writes:
>
> > !       if [ $REPLY = "y" -o $REPLY = "Y" ]; then
> >
> > fixed to:
> >
> > !       if [ "$REPLY" = "y" -o "$REPLY" = "Y" ]; then
>
> Good.
>
> FYI, it's never necessary to quote the right side of a shell variable
> assignment.
>
> FOO=$BAR
>
> always works, as does
>
> case $foo in ...
>
> But it doesn't hurt of course.

I see:

    $ X="a b"
    $ Y=$X

I never realized that.  Now I am confused why 'test' needs it, but
assignment doesn't.

--
  Bruce Momjian                        |  http://candle.pha.pa.us
  pgman@candle.pha.pa.us               |  (610) 853-3000
  +  If your life is a hard drive,     |  830 Blythe Avenue
  +  Christ can be your backup.        |  Drexel Hill, Pennsylvania 19026