#!/bin/sh
# postinst script for iplike-pgsql
#
# see: dh_installdeb(1)

set -e
. /usr/share/debconf/confmodule

# summary of how this script can be called:
#        * <postinst> `configure' <most-recently-configured-version>
#        * <old-postinst> `abort-upgrade' <new version>
#        * <conflictor's-postinst> `abort-remove' `in-favour' <package>
#          <new-version>
#        * <postinst> `abort-remove'
#        * <deconfigured's-postinst> `abort-deconfigure' `in-favour'
#          <failed-install-package> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

LOGFILE=/tmp/install_iplike.log
POSTGRESQL_VERSION="13"
PG_TYPE_VERSION="13"
PG_PLUGINDIR="/usr/lib/postgresql/13/lib"

case "$1" in
    configure)
    update-alternatives --install "/usr/sbin/install_iplike.sh"       "install_iplike.sh" "/usr/sbin/install_iplike-$PG_TYPE_VERSION.sh" $PG_TYPE_VERSION
    update-alternatives --install "/usr/share/java/opennms/iplike.so" "iplike.so"         "$PG_PLUGINDIR/iplike.so"                  $PG_TYPE_VERSION

    if [ -z "$SKIP_IPLIKE_INSTALL" ]; then
        FAILED=0
        /usr/sbin/install_iplike-$PG_TYPE_VERSION.sh -x /var/run/postgresql -s postgres -d opennms >${LOGFILE} 2>&1 || FAILED=1

        if [ $FAILED -eq 1 ]; then
            db_input high iplike/iplike-install-failed || true
            db_go || true
        fi
    fi
    ;;

    abort-upgrade|abort-remove|abort-deconfigure)
    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0


