Commit 4bfb75ae authored by Peter Eisentraut's avatar Peter Eisentraut

Change initdb to not delete PGDATA directory unless it was created by

initdb itself. Refuse to run on existing but non-empty PGDATA directory.
parent 424f0edc
...@@ -4,7 +4,7 @@ ...@@ -4,7 +4,7 @@
# #
# Copyright (c) 1994, Regents of the University of California # Copyright (c) 1994, Regents of the University of California
# #
# $Header: /cvsroot/pgsql/src/bin/initdb/Makefile,v 1.21 2000/08/31 16:11:06 petere Exp $ # $Header: /cvsroot/pgsql/src/bin/initdb/Makefile,v 1.22 2000/09/01 13:15:27 petere Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -15,11 +15,14 @@ include $(top_builddir)/src/Makefile.global ...@@ -15,11 +15,14 @@ include $(top_builddir)/src/Makefile.global
all: initdb all: initdb
initdb: initdb.sh $(top_builddir)/src/Makefile.global initdb: initdb.sh $(top_builddir)/src/Makefile.global
sed -e 's/__MULTIBYTE__/$(MULTIBYTE)/g' \ rm -f $@ $@.tmp
-e 's/__VERSION__/$(VERSION)/g' \ sed -e 's/@MULTIBYTE@/$(MULTIBYTE)/g' \
-e 's:__bindir__:$(bindir):g' \ -e 's/@VERSION@/$(VERSION)/g' \
-e 's:__datadir__:$(datadir):g' \ -e 's,@bindir@,$(bindir),g' \
< $< > $@ -e 's,@datadir@,$(datadir),g' \
$< >$@.tmp
chmod a+x $@.tmp
mv $@.tmp $@
install: all installdirs install: all installdirs
$(INSTALL_SCRIPT) initdb $(bindir)/initdb $(INSTALL_SCRIPT) initdb $(bindir)/initdb
......
...@@ -23,7 +23,7 @@ ...@@ -23,7 +23,7 @@
# #
# Copyright (c) 1994, Regents of the University of California # Copyright (c) 1994, Regents of the University of California
# #
# $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.102 2000/08/06 04:39:22 tgl Exp $ # $Header: /cvsroot/pgsql/src/bin/initdb/Attic/initdb.sh,v 1.103 2000/09/01 13:15:27 petere Exp $
# #
#------------------------------------------------------------------------- #-------------------------------------------------------------------------
...@@ -37,8 +37,10 @@ exit_nicely(){ ...@@ -37,8 +37,10 @@ exit_nicely(){
echo echo
echo "$CMDNAME failed." echo "$CMDNAME failed."
if [ "$noclean" != yes ]; then if [ "$noclean" != yes ]; then
echo "Removing $PGDATA." if [ "$template_only" != yes ] && [ "$made_new_pgdata" = yes ]; then
rm -rf "$PGDATA" || echo "Failed." echo "Removing $PGDATA."
rm -rf "$PGDATA" || echo "Failed."
fi
echo "Removing temp file $TEMPFILE." echo "Removing temp file $TEMPFILE."
rm -rf "$TEMPFILE" || echo "Failed." rm -rf "$TEMPFILE" || echo "Failed."
else else
...@@ -51,13 +53,13 @@ exit_nicely(){ ...@@ -51,13 +53,13 @@ exit_nicely(){
CMDNAME=`basename $0` CMDNAME=`basename $0`
# Placed here during build # Placed here during build
VERSION=__VERSION__ VERSION='@VERSION@'
bindir='__bindir__' bindir='@bindir@'
# Note that "datadir" is not the directory we're initializing, it's # Note that "datadir" is not the directory we're initializing, it's
# merely how Autoconf names PREFIX/share. # merely how Autoconf names PREFIX/share.
datadir='__datadir__' datadir='@datadir@'
# as set by configure --enable-multibyte[=XXX]. # as set by configure --enable-multibyte[=XXX].
MULTIBYTE=__MULTIBYTE__ MULTIBYTE='@MULTIBYTE@'
if [ "$TMPDIR" ]; then if [ "$TMPDIR" ]; then
TEMPFILE="$TMPDIR/initdb.$$" TEMPFILE="$TMPDIR/initdb.$$"
...@@ -107,7 +109,7 @@ for prog in postgres pg_id ...@@ -107,7 +109,7 @@ for prog in postgres pg_id
do do
if [ ! -x "$PGPATH/$prog" ] if [ ! -x "$PGPATH/$prog" ]
then 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 "expected at:"
echo " $PGPATH/$prog" echo " $PGPATH/$prog"
echo "If this is not the correct directory, please start $CMDNAME" echo "If this is not the correct directory, please start $CMDNAME"
...@@ -368,24 +370,23 @@ echo ...@@ -368,24 +370,23 @@ echo
# umask must disallow access to group, other for files and dirs # umask must disallow access to group, other for files and dirs
umask 077 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 then
if [ "$template_only" != yes ] if [ "$template_only" != yes ]
then then
echo "$CMDNAME: The file $PGDATA/PG_VERSION already exists." echo "$CMDNAME: The directory $PGDATA is exists but is not empty."
echo "This probably means initdb has already been run and the" echo "If you want to create a new database system, either remove or empty"
echo "database system already exists." echo "the directory $PGDATA or run initdb with an argument"
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 "other than $PGDATA." echo "other than $PGDATA."
exit 1 exit 1
fi fi
else else
if [ ! -d "$PGDATA" ] if [ ! -d "$PGDATA" ]; then
then
echo "Creating directory $PGDATA" echo "Creating directory $PGDATA"
mkdir "$PGDATA" || exit_nicely mkdir "$PGDATA" || exit_nicely
made_new_pgdata=yes
else else
echo "Fixing permissions on existing directory $PGDATA" echo "Fixing permissions on existing directory $PGDATA"
chmod go-rwx "$PGDATA" || exit_nicely chmod go-rwx "$PGDATA" || exit_nicely
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment