#!/bin/sh
#
# postrm -- clamsmtp post-remove maintainer script
#
set -e

if [ "$1" = "purge" ]; then
	if [ -f /usr/share/debconf/confmodule ]; then
		. /usr/share/debconf/confmodule
		# Purge the clamsmtp spool directory?
		db_get clamsmtp/purge || true
		if [ "${RET:-false}" = "true" -a -d /var/spool/clamsmtp ] ; then
			rm -rf /var/spool/clamsmtp || true
		elif [ -d /var/spool/clamsmtp ] ; then
			rmdir /var/spool/clamsmtp 2>/dev/null || true
		fi
	fi

	if [ -d /var/run/clamsmtp ] ; then
		rm -rf /var/run/clamsmtp
	fi

	# Remove clamav from clamsmtp group
	if (getent group clamsmtp|grep clamav>/dev/null) ; then
		if which deluser >/dev/null; then
			deluser clamav clamsmtp || true
		fi
		if [ -x /etc/init.d/clamsmtp ]; then
			# Attempt to stop and start clamav-daemon, getting
			# cleaned group permissions.
			(invoke-rc.d clamav-daemon stop && \
			invoke-rc.d clamav-daemon start) || true
		fi
	fi
fi

#DEBHELPER#

if [ "$1" = "purge" ]; then
	db_stop || true
fi
