#! /bin/sh
set -e

# We cannot use dh_installdeb and debian/maintscript for this, because the
# conffile must be renamed before dh_apache2's generated postinst fragment
# tries to reload the server.
dpkg-maintscript-helper mv_conffile /etc/apache2/mods-available/mod-spamhaus.conf /etc/apache2/mods-available/spamhaus.conf 0.7-1.1~ -- "$@"
dpkg-maintscript-helper mv_conffile /etc/apache2/mods-available/mod-spamhaus.load /etc/apache2/mods-available/spamhaus.load 0.7-1.1~ -- "$@"

#DEBHELPER#

if [ "$1" = configure ] && [ "$2" ] && \
   dpkg --compare-versions "$2" le-nl 0.7-1.1~ && \
   [ -e /etc/apache2/mods-enabled/mod-spamhaus.load.dpkg-was-disabled ]; then
	# We're upgrading, and the old name was disabled, so it must
	# have been disabled by the site administrator.  Preserve
	# this.
	rm -f /etc/apache2/mods-enabled/mod-spamhaus.load.dpkg-was-disabled
	if [ -e /usr/share/apache2/apache2-maintscript-helper ]; then
		echo "Disabling spamhaus again to reflect previous mod-spamhaus configuration."
		. /usr/share/apache2/apache2-maintscript-helper
		a2dismod -f -q spamhaus
		apache2_reload restart
	fi
fi

exit 0
