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

set -e
#set -x

# 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 [ -f /usr/share/debconf/confmodule ]; then
        . /usr/share/debconf/confmodule
fi
if [ -f /usr/share/dbconfig-common/dpkg/postrm ]; then
        . /usr/share/dbconfig-common/dpkg/postrm
        dbc_go moodle $@
fi

case "$1" in
    purge)
        rm -rf /usr/share/moodle


        for conf in '/etc/cron.d/moodle'; do
          for ext in '~' '%' .bak .ucf-new .ucf-old .ucf-dist;  do
            rm -f $conf$ext
          done
                          
          # remove the configuration file itself
          rm -f $conf
                                      
          # and finally clear it out from the ucf database
          if which ucf >/dev/null; then
            ucf --purge $conf
          fi
          if which ucfr >/dev/null; then
            ucfr --purge foo $conf
          fi
        done

        rm -rf /var/lib/moodle
        rm -f /etc/cron.d/moodle
        ;;
    remove|upgrade|failed-upgrade|abort-install|abort-upgrade|disappear)
    ;;

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

#DEBHELPER#

exit 0