#!/bin/sh

set -e

#
# Skip, if we are not in "remove" or "purge" state
# 
if [ "$1" != "remove" ] && [ "$1" != "purge" ]; then
    exit 0
fi

## Source debconf library
. /usr/share/debconf/confmodule
db_version 2.0

# update the webserver, if needed
# apache2
if [ -e /etc/apache2/conf.d/colplot.conf -o -e /etc/apache2/conf-enabled/colplot.conf ]; then
#   Sniplet adjusted from http://wiki.debian.org/Apache/PackagingFor24
    if [ -e /usr/share/apache2/apache2-maintscript-helper ] ; then
	. /usr/share/apache2/apache2-maintscript-helper
	apache2_invoke disconf colplot
    elif  dpkg-query -f '${Version}'  -W 'apache2.2-common' > /dev/null 2>&1 ; then
	[ -h /etc/apache2/conf.d/colplot.conf ] && rm /etc/apache2/conf.d/colplot.conf
	invoke-rc.d apache2 reload || true
    fi
fi
# lighttpd
if which lighty-disable-mod >/dev/null 2>&1 ; then
    lighty-disable-mod colplot || true
#   We need to take care: bug #446324
    invoke-rc.d lighttpd reload 3>/dev/null || true
fi

#
# remove or purge the whole package
#
case "$1" in
    purge)
	# get rid of configuration files and ucf entries
	for config_file in \
	    /etc/apache2/conf-available/colplot.conf \
	    /etc/lighttpd/conf-available/colplot.conf \
	    /etc/lighttpd/conf-available/20-colplot.conf
	do
	    if which ucf >/dev/null 2>&1; then
		ucf --purge $config_file
	    fi
            if [ -x "`which ucfr 2>/dev/null`" ]; then
		ucfr --purge colplot $config_file
            fi
            for ext in .ucf-new .ucf-old .ucf-dist ""; do
		rm -f "$config_file$ext"
            done
	done
	;;

    remove)
	;;

esac

#DEBHELPER#
exit 0

