#!/bin/sh -e

# Remove a no-longer used conffile
rm_conffile() {
    PKGNAME="$1"
    CONFFILE="$2"

    if [ -e "$CONFFILE" ]; then
        md5sum="`md5sum \"$CONFFILE\" | sed -e \"s/ .*//\"`"
        old_md5sum="`dpkg-query -W -f='${Conffiles}' $PKGNAME | grep \"^ $CONFFILE \" | cut -d' ' -f3`"
        if [ "$md5sum" != "$old_md5sum" ]; then
            echo "Obsolete conffile $CONFFILE has been modified by you."
            echo "Saving as $CONFFILE.dpkg-bak ..."
            mv -f "$CONFFILE" "$CONFFILE".dpkg-bak
        else
            echo "Removing obsolete conffile $CONFFILE ..."
            rm -f "$CONFFILE"
        fi
    fi
}

if [ "$1" = configure ] && dpkg --compare-versions "$2" lt "1:0"; then
	rm_conffile pcmcia-cs /etc/init.d/pcmcia
	update-rc.d -f pcmcia remove >/dev/null

	for i in 3CCFEM556.dat 3CXEM556.dat COMpad2.dat COMpad4.dat \
		DP83903.dat E-CARD.dat LA-PCM.dat MT5634ZLX.dat \
		NE2K.dat PCMLM28.dat PE-200.dat PE520.dat RS-COM-2P.dat \
		tamarack.dat; do
	    rm_conffile pcmcia-cs /etc/pcmcia/cis/$i
	done

	if [ -d /etc/pcmcia/cis ]; then
		rmdir /etc/pcmcia/cis || true
	fi

	for i in config ftl ftl.opts ide \
		ide.opts ieee1394 ieee1394.opts memory memory.opts \
		network network.opts parport parport.opts scsi \
		scsi.opts serial serial.opts shared wireless \
		wireless.opts; do
	    rm_conffile pcmcia-cs /etc/pcmcia/$i
	done
fi

#DEBHELPER#
