#! /bin/sh

set -e

# remove diversion of apparmor feature pinning file, see preinst
aa_feature_remove_diversion() {
  dpkg-divert --package lxc-pve --remove --rename \
      --divert /usr/share/apparmor-features/features.stock \
      /usr/share/apparmor-features/features
}

case "$1" in
  abort-upgrade)
    if dpkg --compare-versions "$2" 'lt' '2.1.1-3'; then
      aa_feature_remove_diversion
    fi
    ;;
  remove|abort-install|disappear)
    aa_feature_remove_diversion
    ;;
esac

# Automatically added by dh_installsystemd/13.11.4
if [ "$1" = remove ] && [ -d /run/systemd/system ] ; then
	systemctl --system daemon-reload >/dev/null || true
fi
# End automatically added section
# Automatically added by dh_installsystemd/13.11.4
if [ "$1" = "purge" ]; then
	if [ -x "/usr/bin/deb-systemd-helper" ]; then
		deb-systemd-helper purge 'lxc.service' >/dev/null || true
	fi
fi
# End automatically added section
# Automatically added by dh_installsystemd/13.11.4
if [ "$1" = remove ] && [ -d /run/systemd/system ] ; then
	systemctl --system daemon-reload >/dev/null || true
fi
# End automatically added section
# Automatically added by dh_installsystemd/13.11.4
if [ "$1" = "purge" ]; then
	if [ -x "/usr/bin/deb-systemd-helper" ]; then
		deb-systemd-helper purge 'lxc-monitord.service' 'lxc-net.service' >/dev/null || true
	fi
fi
# End automatically added section
# Automatically added by dh_apparmor/3.0.8-3
if [ "$1" = "purge" ] && ! [ -e "/etc/apparmor.d/lxc-containers" ] ; then
    rm -f "/etc/apparmor.d/disable/lxc-containers" || true
    rm -f "/etc/apparmor.d/force-complain/lxc-containers" || true
    rm -f "/etc/apparmor.d/local/lxc-containers" || true
    rm -f /var/cache/apparmor/*/"lxc-containers" || 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
# Automatically added by dh_apparmor/3.0.8-3
if [ "$1" = "purge" ] && ! [ -e "/etc/apparmor.d/usr.bin.lxc-start" ] ; then
    rm -f "/etc/apparmor.d/disable/usr.bin.lxc-start" || true
    rm -f "/etc/apparmor.d/force-complain/usr.bin.lxc-start" || true
    rm -f "/etc/apparmor.d/local/usr.bin.lxc-start" || true
    rm -f /var/cache/apparmor/*/"usr.bin.lxc-start" || 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


exit 0
