#!/bin/bash -e

# This is the default postinst file from the cdd-dev package which is used
# in all meta packages.  If there is a certain need to provide extra
# postinst 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#

	# 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-deconfigure|abort-remove|abort-upgrade)
		;;
    	    configure|upgrade)
		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 "postinst called with unknown argument \`$1'" >&2
		exit 1
		;;
	esac

	db_stop
    fi
fi

#DEBHELPER#

exit 0
