From: Peter Eisentraut Date: Fri, 1 Sep 2000 13:15:27 +0000 (+0000) Subject: Change initdb to not delete PGDATA directory unless it was created by X-Git-Url: http://waps.l3s.uni-hannover.de/gitweb/?a=commitdiff_plain;h=7bea4b4d6f3287b790573374fdfefd968cd20f27;p=users%2Fbernd%2Fpostgres.git Change initdb to not delete PGDATA directory unless it was created by initdb itself. Refuse to run on existing but non-empty PGDATA directory. --- diff --git a/src/bin/initdb/Makefile b/src/bin/initdb/Makefile index 459c5d4bf6..4ac5063798 100644 --- a/src/bin/initdb/Makefile +++ b/src/bin/initdb/Makefile @@ -15,11 +15,14 @@ include $(top_builddir)/src/Makefile.global all: initdb initdb: initdb.sh $(top_builddir)/src/Makefile.global - sed -e 's/__MULTIBYTE__/$(MULTIBYTE)/g' \ - -e 's/__VERSION__/$(VERSION)/g' \ - -e 's:__bindir__:$(bindir):g' \ - -e 's:__datadir__:$(datadir):g' \ - < $< > $@ + rm -f $@ $@.tmp + sed -e 's/@MULTIBYTE@/$(MULTIBYTE)/g' \ + -e 's/@VERSION@/$(VERSION)/g' \ + -e 's,@bindir@,$(bindir),g' \ + -e 's,@datadir@,$(datadir),g' \ + $< >$@.tmp + chmod a+x $@.tmp + mv $@.tmp $@ install: all installdirs $(INSTALL_SCRIPT) initdb $(bindir)/initdb diff --git a/src/bin/initdb/initdb.sh b/src/bin/initdb/initdb.sh index a1816e44a2..4fd542c221 100644 --- a/src/bin/initdb/initdb.sh +++ b/src/bin/initdb/initdb.sh @@ -37,8 +37,10 @@ exit_nicely(){ echo echo "$CMDNAME failed." if [ "$noclean" != yes ]; then - echo "Removing $PGDATA." - rm -rf "$PGDATA" || echo "Failed." + if [ "$template_only" != yes ] && [ "$made_new_pgdata" = yes ]; then + echo "Removing $PGDATA." + rm -rf "$PGDATA" || echo "Failed." + fi echo "Removing temp file $TEMPFILE." rm -rf "$TEMPFILE" || echo "Failed." else @@ -51,13 +53,13 @@ exit_nicely(){ CMDNAME=`basename $0` # Placed here during build -VERSION=__VERSION__ -bindir='__bindir__' +VERSION='@VERSION@' +bindir='@bindir@' # Note that "datadir" is not the directory we're initializing, it's # merely how Autoconf names PREFIX/share. -datadir='__datadir__' +datadir='@datadir@' # as set by configure --enable-multibyte[=XXX]. -MULTIBYTE=__MULTIBYTE__ +MULTIBYTE='@MULTIBYTE@' if [ "$TMPDIR" ]; then TEMPFILE="$TMPDIR/initdb.$$" @@ -107,7 +109,7 @@ for prog in postgres pg_id do if [ ! -x "$PGPATH/$prog" ] then - echo "The program $prog needed by $CMDNAME could not be found. It was" + echo "The program \`$prog' needed by $CMDNAME could not be found. It was" echo "expected at:" echo " $PGPATH/$prog" echo "If this is not the correct directory, please start $CMDNAME" @@ -368,24 +370,23 @@ echo # umask must disallow access to group, other for files and dirs umask 077 -if [ -f "$PGDATA"/PG_VERSION ] +# find out if directory is empty +pgdata_contents=`ls -A "$PGDATA" 2>/dev/null` +if [ x"$pgdata_contents" != x ] then if [ "$template_only" != yes ] then - echo "$CMDNAME: The file $PGDATA/PG_VERSION already exists." - echo "This probably means initdb has already been run and the" - echo "database system already exists." - echo - echo "If you want to create a new database system, either remove" - echo "the directory $PGDATA or run initdb with a --pgdata argument" + echo "$CMDNAME: The directory $PGDATA is exists but is not empty." + echo "If you want to create a new database system, either remove or empty" + echo "the directory $PGDATA or run initdb with an argument" echo "other than $PGDATA." exit 1 fi else - if [ ! -d "$PGDATA" ] - then + if [ ! -d "$PGDATA" ]; then echo "Creating directory $PGDATA" mkdir "$PGDATA" || exit_nicely + made_new_pgdata=yes else echo "Fixing permissions on existing directory $PGDATA" chmod go-rwx "$PGDATA" || exit_nicely