#!/bin/bash

# This wrapper script is not needed anymore, but needs to stay
# because the %postun scripts of old postgresql packages might
# still try to call it.
exit 0

# The rest of the file is kept for now as a reference.

shopt -s nullglob

if test "$#" -ne 1; then
	echo "usage: $0 pgversion" 1>&2
	exit 1
fi

PRIO=$1
case "$PRIO" in
  postgresql*)
    PRIO="${PRIO##postgresql}"
  ;;
esac

PGBASEDIR=/usr/lib/postgresql$PRIO
if [ $PRIO -lt 80 ] ; then
  PRIO="${PRIO}0"
fi

PGBINDIR=$PGBASEDIR/bin

for FILE in $PGBINDIR/*; do
    NAME=$(basename $FILE)
    DIR=/usr/bin
    SLAVES="$SLAVES --slave $DIR/$NAME $NAME $FILE"
done

if test -n "$SLAVES"; then
    update-alternatives --quiet --install \
        /usr/lib/postgresql postgresql $PGBASEDIR $PRIO \
        $SLAVES
else
    update-alternatives --remove postgresql $PGBASEDIR
fi
