2323#
2424# Copyright (c) 1994, Regents of the University of California
2525#
26- # $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.102 2000/08/06 04:39:22 tgl Exp $
26+ # $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.103 2000/09/01 13:15:27 petere Exp $
2727#
2828# -------------------------------------------------------------------------
2929
@@ -37,8 +37,10 @@ exit_nicely(){
3737echo
3838echo " $CMDNAME failed."
3939if [" $noclean " != yes ]; then
40- echo " Removing$PGDATA ."
41- rm -rf" $PGDATA " || echo " Failed."
40+ if [" $template_only " != yes ]&& [" $made_new_pgdata " = yes ]; then
41+ echo " Removing$PGDATA ."
42+ rm -rf" $PGDATA " || echo " Failed."
43+ fi
4244echo " Removing temp file$TEMPFILE ."
4345 rm -rf" $TEMPFILE " || echo " Failed."
4446else
@@ -51,13 +53,13 @@ exit_nicely(){
5153CMDNAME=` basename$0 `
5254
5355# Placed here during build
54- VERSION=__VERSION__
55- bindir=' __bindir__ '
56+ VERSION=' @VERSION@ '
57+ bindir=' @bindir@ '
5658# Note that "datadir" is not the directory we're initializing, it's
5759# merely how Autoconf names PREFIX/share.
58- datadir=' __datadir__ '
60+ datadir=' @datadir@ '
5961# as set by configure --enable-multibyte[=XXX].
60- MULTIBYTE=__MULTIBYTE__
62+ MULTIBYTE=' @MULTIBYTE@ '
6163
6264if [" $TMPDIR " ]; then
6365 TEMPFILE=" $TMPDIR /initdb.$$ "
@@ -107,7 +109,7 @@ for prog in postgres pg_id
107109do
108110if [! -x " $PGPATH /$prog " ]
109111then
110- echo " The program$prog needed by$CMDNAME could not be found. It was"
112+ echo " The program\` $prog ' needed by$CMDNAME could not be found. It was"
111113echo " expected at:"
112114echo " $PGPATH /$prog "
113115echo " If this is not the correct directory, please start$CMDNAME "
@@ -368,24 +370,23 @@ echo
368370# umask must disallow access to group, other for files and dirs
369371umask 077
370372
371- if [-f " $PGDATA " /PG_VERSION ]
373+ # find out if directory is empty
374+ pgdata_contents=` ls -A" $PGDATA " 2> /dev/null`
375+ if [ x" $pgdata_contents " != x ]
372376then
373377if [" $template_only " != yes ]
374378then
375- echo " $CMDNAME : The file$PGDATA /PG_VERSION already exists."
376- echo " This probably means initdb has already been run and the"
377- echo " database system already exists."
378- echo
379- echo " If you want to create a new database system, either remove"
380- echo " the directory$PGDATA or run initdb with a --pgdata argument"
379+ echo " $CMDNAME : The directory$PGDATA is exists but is not empty."
380+ echo " If you want to create a new database system, either remove or empty"
381+ echo " the directory$PGDATA or run initdb with an argument"
381382echo " other than$PGDATA ."
382383exit 1
383384fi
384385else
385- if [! -d " $PGDATA " ]
386- then
386+ if [! -d " $PGDATA " ]; then
387387echo " Creating directory$PGDATA "
388388 mkdir" $PGDATA " || exit_nicely
389+ made_new_pgdata=yes
389390else
390391echo " Fixing permissions on existing directory$PGDATA "
391392chmod go-rwx" $PGDATA " || exit_nicely