27aa74
#!/bin/sh
27aa74
27aa74
# This script verifies that the postgresql data directory has been correctly
27aa74
# initialized.  We do not want to automatically initdb it, because that has
27aa74
# a risk of catastrophic failure (ie, overwriting a valuable database) in
27aa74
# corner cases, such as a remotely mounted database on a volume that's a
27aa74
# bit slow to mount.  But we can at least emit a message advising newbies
27aa74
# what to do.
27aa74
27aa74
PGDATA="$1"
27aa74
27aa74
if [ -z "$PGDATA" ]
27aa74
then
27aa74
    echo "Usage: $0 database-path"
27aa74
    exit 1
27aa74
fi
27aa74
27aa74
# PGVERSION is the full package version, e.g., 9.1.2
27aa74
# Note: the specfile inserts the correct value during package build
27aa74
PGVERSION=xxxx
27aa74
# PGMAJORVERSION is major version, e.g., 9.1 (this should match PG_VERSION)
27aa74
PGMAJORVERSION=`echo "$PGVERSION" | sed 's/^\([0-9]*\.[0-9]*\).*$/\1/'`
27aa74
# PREVMAJORVERSION is the previous major version, e.g., 8.4, for upgrades
27aa74
# Note: the specfile inserts the correct value during package build
27aa74
PREVMAJORVERSION=xxxx
27aa74
# PGDOCDIR is the directory containing the package's documentation
27aa74
# Note: the specfile inserts the correct value during package build
27aa74
PGDOCDIR=xxxx
27aa74
27aa74
# Check for the PGDATA structure
27aa74
if [ -f "$PGDATA/PG_VERSION" ] && [ -d "$PGDATA/base" ]
27aa74
then
27aa74
    # Check version of existing PGDATA
27aa74
    if [ x`cat "$PGDATA/PG_VERSION"` = x"$PGMAJORVERSION" ]
27aa74
    then
27aa74
        : A-OK
27aa74
    elif [ x`cat "$PGDATA/PG_VERSION"` = x"$PREVMAJORVERSION" ]
27aa74
    then
27aa74
        echo $"An old version of the database format was found."
27aa74
        echo $"Use \"postgresql-setup upgrade\" to upgrade to version $PGMAJORVERSION."
27aa74
        echo $"See $PGDOCDIR/README.rpm-dist for more information."
27aa74
        exit 1
27aa74
    else
27aa74
        echo $"An old version of the database format was found."
27aa74
        echo $"You need to dump and reload before using PostgreSQL $PGMAJORVERSION."
27aa74
        echo $"See $PGDOCDIR/README.rpm-dist for more information."
27aa74
        exit 1
27aa74
    fi
27aa74
else
27aa74
    # No existing PGDATA! Warn the user to initdb it.
27aa74
    echo $"\"$PGDATA\" is missing or empty."
27aa74
    echo $"Use \"postgresql-setup initdb\" to initialize the database cluster."
27aa74
    echo $"See $PGDOCDIR/README.rpm-dist for more information."
27aa74
    exit 1
27aa74
fi
27aa74
27aa74
exit 0