1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105
|
#! /bin/bash
set -e
# Load the debconf library - this must come FIRST; do not insert any other
# commands before this
. /usr/share/debconf/confmodule
if [ "$1" = install -o "$1" = upgrade ]
then
#include <genscript.warning>
# Make sure the administrative user exists
getent group postgres >/dev/null 2>&1 || addgroup --system postgres
getent passwd postgres >/dev/null 2>&1 ||
adduser --system --shell /bin/bash --home /var/lib/postgres --ingroup postgres --gecos "PostgreSQL administrator" postgres
#include <dumpall_loc.inc>
# Pre-installation script for postgresql debian package
#
# This package should conflict with any earlier incompatible version,
# but we check anyway, in case someone is trying to use --force- in
# ignorance. We also need to protect an existing Postgre{SQL,s95} user
# who is moving to Debian.
#include <savebin.inc>
current=%PG_VERSION%
SHELL=/bin/sh
# If this is an upgrade, make sure the previous version is at least
# 7.2 (Woody's version), which did many configuration file conversions
if [ "$1" = upgrade ] && dpkg --compare-versions $2 lt 7.2; then
db_get postgresql/very_old_version_warning
[ "$RET" = true ] && exit 1 || true
fi
# determine data location PGDATA
if [ -r /etc/postgresql/postmaster.conf ]
then
. /etc/postgresql/postmaster.conf
fi
PGDATA="${POSTGRES_DATA:=/var/lib/postgres/data}"
# From 7.4.2-5 on, all binaries and libraries are saved in the prerms. But
# versions before don't save libraries, so we have to additionaly do that here
# for a transition period (i. e. until the Sarge release).
if [ -d "$PGDATA" ] && [ -n "`ls \"$PGDATA\"`" ]
then
# found an existing database directory at $PGDATA with files in it
if [ -r "$PGDATA/PG_VERSION" ]
then
installed=`cat "${PGDATA}/PG_VERSION" 2>/dev/null || true`
lastinstall=`echo $2 | cut -d\- -f1 | cut -d. -f1-2`
if [ A${installed} != A${current} ]
then
# This is where we should end up for an existing Debian package that
# conflicts with this one and for a non-Debian installation that
# happens to be in our standard location
# make sure we don't overwrite executables with those from an
# intermediate package
if [ A${installed} = A${lastinstall} ]
then
PKGVERSION="$installed"
save_bin /usr/lib/postgresql/bin/postgres
save_bin /usr/lib/postgresql/bin/postmaster
for i in /etc/postgresql/{pg_hba,pg_ident,postgresql,postmaster}.conf
do
save_file $i
done
fi
fi
else
# There is a database directory in the right place, but it is
# incomplete. Heaven knows what is in here.
if [ -d "${PGDATA}/base" -o -f "${PGDATA}/pg_database" ]
then
MSG="Directory ${PGDATA}/base exists, but the version file, ${PGDATA}/PG_VERSION,
does not; it must be repaired before this installation can continue."
echo $MSG >&2
echo $MSG | mail -s "postgresql installation" root
exit 1
fi
fi
fi
if [ -n "`pidof postmaster`" ] && [ "$1" = upgrade ]
then
if [ -x /usr/sbin/invoke-rc.d ]
then
/usr/sbin/invoke-rc.d postgresql stop || true
else
[ -x /etc/init.d/postgresql ] && /etc/init.d/postgresql stop || true
fi
sleep 2
fi
fi # for 'if $1 = install|upgrade' at the top of file
#DEBHELPER#
exit 0
|