#! /bin/sh
# postrm script for strongswan
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <postrm> `remove'
#        * <postrm> `purge'
#        * <old-postrm> `upgrade' <new-version>
#        * <new-postrm> `failed-upgrade' <old-version>
#        * <new-postrm> `abort-install'
#        * <new-postrm> `abort-install' <old-version>
#        * <new-postrm> `abort-upgrade' <old-version>
#        * <disappearer's-postrm> `disappear' <r>overwrit>r> <new-version>
# for details, see /usr/share/doc/packaging-manual/

case "$1" in
       purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)

                                # update the menu system
#        if [ -x /usr/bin/update-menus ]; then update-menus; fi

        ;;

    *)
        echo "postrm called with unknown argument \`$1'" >&2
        exit 0

esac

if [ "$1" = "purge" ] ; then
        update-rc.d ipsec remove >/dev/null
        if getent passwd strongswan>/dev/null; then
                if [ -x /usr/sbin/deluser ]; then
                        deluser --system strongswan
                fi
        fi

        rm -rf /etc/ipsec.d/
        rm -rf /var/run/pluto/
        rm -rf /var/lib/strongswan/
fi

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

# Automatically added by dh_systemd_start/12.1.1
if [ -d /run/systemd/system ]; then
	systemctl --system daemon-reload >/dev/null || true
fi
# End automatically added section
# Automatically added by dh_systemd_enable/12.1.1
if [ "$1" = "remove" ]; then
	if [ -x "/usr/bin/deb-systemd-helper" ]; then
		deb-systemd-helper mask 'strongswan.service' >/dev/null || true
	fi
fi

if [ "$1" = "purge" ]; then
	if [ -x "/usr/bin/deb-systemd-helper" ]; then
		deb-systemd-helper purge 'strongswan.service' >/dev/null || true
		deb-systemd-helper unmask 'strongswan.service' >/dev/null || true
	fi
fi
# End automatically added section
# Automatically added by dh_installdebconf/12.1.1
if [ "$1" = purge ] && [ -e /usr/share/debconf/confmodule ]; then
	. /usr/share/debconf/confmodule
	db_purge
fi
# End automatically added section
# Automatically added by dh_apparmor/2.13.2-10
if [ "$1" = "purge" ] && ! [ -e "/etc/apparmor.d/usr.lib.ipsec.stroke" ] ; then
    rm -f "/etc/apparmor.d/disable/usr.lib.ipsec.stroke" || true
    rm -f "/etc/apparmor.d/force-complain/usr.lib.ipsec.stroke" || true
    rm -f "/etc/apparmor.d/local/usr.lib.ipsec.stroke" || true
    rmdir /etc/apparmor.d/disable 2>/dev/null || true
    rmdir /etc/apparmor.d/local   2>/dev/null || true
    rmdir /etc/apparmor.d         2>/dev/null || true
fi
# End automatically added section



