#!/bin/bash -e

# This is the default postrm file from the cdd-dev package which is used
# in all meta packages.  If there is a certain need to provide extra
# postrm files for some meta packages this template will be appended.  Thus
# it will be checked whether debconf was just initialized.
#
# You should not insert the _DEBHELPER_ template in the special postscript
# file because it is in the end of this template anyway.

###########################################################################
# If the user menus are not needed/wished for a CDD (like for instance
# Debian-Edu there is no need to install cdd-common package.  Thus we
# have to make sure that postinst does not try to include the menu stuff
if [ -d /etc/cdd -a -f /etc/cdd/cdd.conf ] ; then
    # Also verify that this CDD provides special configuration
    # If not there is no need to execute the user menu code
    if [ -d /etc/cdd/#CDD# -a -f /etc/cdd/#CDD#/#CDD#.conf ] ; then

	test -x /usr/sbin/cdd-update-menus && /usr/sbin/cdd-update-menus -d #CDD# 

	test -s /etc/cdd/cdd.conf         && . /etc/cdd/cdd.conf
	test -s /etc/cdd/#CDD#/#CDD#.conf && . /etc/cdd/#CDD#/#CDD#.conf

	if [ -x /usr/sbin/cdd-update-usermenus ] ; then
	    # Initialize debconf if not yet done
	    if [ _"$DEBCONF_REDIR" = _"" ]; then
    		. /usr/share/debconf/confmodule
    		db_version 2.0
	    fi

	    . /etc/cdd/cdd.conf
	    if [ -s /etc/cdd/#CDD#/#CDD#.conf ] ; then . /etc/cdd/#CDD#/#CDD#.conf ; fi

	    case "$1" in
		abort-install|abort-upgrade|failed-upgrade|upgrade)
		    ;;
		remove|purge)
		    db_get "shared/#CDD#-config/usermenus" || true
		    case "$RET" in
			"Each package installation")
			    /usr/sbin/cdd-update-usermenus #CDD#
			;;
			"End of installation")
			    touch /var/run/#CDD#-config.usermenu
			;;
		    esac
		    ;;
		*)
		    echo "postrm called with unknown argument \`$1'" >&2
		    exit 1
		    ;;
	    esac
	fi
    fi
fi

#DEBHELPER#
