Change initdb to not delete PGDATA directory unless it was created by
initdb itself. Refuse to run on existing but non-empty PGDATA directory.
This commit is contained in:
parent
424f0edcb8
commit
4bfb75aece
|
@ -4,7 +4,7 @@
|
|||
#
|
||||
# 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
|
|||
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
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
#
|
||||
# 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(){
|
|||
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
|
||||
|
|
Loading…
Reference in New Issue