#! /bin/sh

set -e

case "$1" in
    upgrade)
	if dpkg --compare-versions "$2" lt-nl "1.28-6"; then
		# FIXME: I should really do this with debconf...
		echo "**********************************************"
		echo "* WARNING: pop-before-smtp path has changed: *"
		echo "*          Update /etc/postfix.main.cf!      *"
		echo "**********************************************"
		if [ -e /etc/postfix/pop-before-smtp.db ]; then
			echo "Removing old database..."
			rm /etc/postfix/pop-before-smtp.db
		fi
	elif dpkg --compare-versions "$2" lt-nl "1.36-1"; then
		# FIXME: I should really do this with debconf...
		echo "**********************************************"
		echo "* WARNING: pop-before-smtp path has changed: *"
		echo "*          /var/lib/pop-before-smtp/hosts    *"
		echo "*          needs to be updated to BDB4.2     *"
		echo "*          (or simply remove it at let it    *"
		echo "*          recreate itself)                  *"
		echo "**********************************************"
		# TODO: Ask first (but possibly default to yes)
		#if [ -e /var/lib/pop-before-smtp/hosts.db ]; then
		#	echo "Removing old database..."
		#	rm /var/lib/pop-before-smtp/hosts.db
		#fi
	fi
	;;
    install)
	echo "After starting pop-before-smtp, be sure that your MTA is setup to"
	echo "use the /var/lib/pop-before-smtp/hosts db file in its config."
	echo "(Read /usr/share/doc/pop-before-smtp/README.Debian for more info.)"
	;;
    abort-upgrade)
	;;
    *)
        echo "preinst called with unknown argument \`$1'" >&2
        exit 1
	;;
esac

#DEBHELPER#

exit 0
