#! /bin/sh

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' <overwriter>
#          <overwriter-version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package


case "$1" in
	purge)
		[ -f /var/log/mumble-server/mumble-server.log ] && rm -f /var/log/mumble-server/mumble-server.log*
		[ -d /var/lib/mumble-server ] && rm -rf /var/lib/mumble-server
		[ -f /var/run/mumble-server/mumble-server.pid ] && rm -f /var/run/mumble-server/mumble-server.pid
		[ -d /var/run/mumble-server ] && rmdir --ignore-fail-on-non-empty /var/run/mumble-server

		if [ -x "$(command -v deluser)" ] ; then
			if getent passwd|grep -q ^mumble-server: ; then
				deluser --quiet --system mumble-server > /dev/null || true
			fi
			if getent group|grep -q ^mumble-server: ; then
				deluser --quiet --system --group --only-if-empty mumble-server > /dev/null || true
			fi
		else
			echo >&2 "not removing 'mumble-server' system account because deluser command was not found."
			[ -d /var/lib/mumble-server ] && rmdir /var/lib/mumble-server
		fi
	;;

	remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
	;;

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

#DEBHELPER#

exit 0
