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