#!/bin/sh
# vim: syntax=sh ts=4 sw=4 sts=4 sr noet
# prerm script for arno-iptables-firewall
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <prerm> `remove'
#        * <old-prerm> `upgrade' <new-version>
#        * <new-prerm> `failed-upgrade' <old-version>
#        * <conflictor's-prerm> `remove' `in-favour' <package> <new-version>
#        * <deconfigured's-prerm> `deconfigure' `in-favour'
#          <package-being-installed> <version> `removing'
#          <conflicting-package> <version>
# for details, see https://www.debian.org/doc/debian-policy/ or
# the debian-policy package


# start up debconf here. 
# why? see https://manpages.debian.org/testing/debconf-doc/debconf-devel.7.en.html, paragraph HACKS. 
# plus automatically inserted code may be using debconf
# (in fact it does, and loads confmodule a little bit late IMHO)
. /usr/share/debconf/confmodule
db_version 2.0

case "$1" in
	remove|deconfigure)
		# Neither dh_installsystemd nor dh_installinit stops the service on
		# remove, so we do it ourselves.
		if [ -d /run/systemd/system ]; then
			deb-systemd-invoke stop arno-iptables-firewall.service >/dev/null || true
		else
			invoke-rc.d arno-iptables-firewall stop >/dev/null || true
		fi
	;;

	upgrade)
		# we don't stop on upgrades so that the firewall keeps operational.
		# this works since there's only a set of iptables rules, no real daemon.
	;;

	failed-upgrade)
	;;

	*)
		echo "prerm 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
