#!/bin/sh
# postrm script for debathena-auto-update
#
# 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' <overwriter>
#          <overwriter-version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

if dpkg-maintscript-helper supports rm_conffile 2> /dev/null; then
    dpkg-maintscript-helper rm_conffile \
	/etc/cron.d/debathena-auto-update 1.22.2 -- "$@"
else
    # From http://wiki.debian.org/DpkgConffileHandling
    rm_conffile() {
	local PKGNAME="$1" # Unused
	local CONFFILE="$2"
	
	if [ -f "$CONFFILE".dpkg-del ]; then
            mv -f "$CONFFILE".dpkg-del "$CONFFILE"
	fi
    }
    # See policy 6.6, item 3 and 5
    case "$1" in
	abort-install|abort-upgrade)
	    if dpkg --compare-versions "$2" le-nl 1.22.2; then
		rm_conffile debathena-auto-update "/etc/cron.d/debathena-auto-update"
	    fi
    esac
fi

case "$1" in
    purge|remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
	if [ -z "$2" ]; then
	    # Cleanup status file
	    rm -f /var/lib/athena-update-status
	fi
    ;;

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

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

#DEBHELPER#

exit 0
