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

set -e

case "$1" in
	purge)
		rm -f /var/lib/mosquitto/mosquitto.db
		if [ -d /var/lib/mosquitto ]; then
			rmdir --ignore-fail-on-non-empty /var/lib/mosquitto
		fi
		rm -f /var/log/mosquitto/mosquitto.log*
		if [ -d /var/log/mosquitto ]; then
			rmdir --ignore-fail-on-non-empty /var/log/mosquitto
		fi
		rm -f /run/mosquitto/mosquitto.pid
		if [ -d /run/mosquitto ]; then
			rmdir --ignore-fail-on-non-empty /run/mosquitto
		fi
        APP_PROFILE="usr.sbin.mosquitto"
        rm -f /etc/apparmor.d/disable/$APP_PROFILE >/dev/null 2>&1 || true
	;;
	remove|abort-install|abort-upgrade|disappear)
	;;

	upgrade|failed-upgrade)
	;;

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


# Automatically added by dh_installinit/13.11.4
if [ "$1" = "remove" ] && [ -x "/etc/init.d/mosquitto" ] ; then
	chmod -x "/etc/init.d/mosquitto" >/dev/null || true
fi
if [ -z "${DPKG_ROOT:-}" ] && [ "$1" = "purge" ] ; then
	update-rc.d mosquitto remove >/dev/null
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 'mosquitto.service' >/dev/null || true
	fi
fi
# End automatically added section


exit 0
