#!/bin/sh -e
# Look to see if pcmcia is used, and if not, ask if pcmcia should be removed,
# and mark it for removal.
# TODO: should be in pcmcia-cs
. /usr/share/debconf/confmodule

db_title 'Debian System Configuration'

if [ -e /root/dbootstrap_settings ]; then
        . /root/dbootstrap_settings || true
else
	# Don't ask if this is not a new install.
	exit
fi

# If pcmcia was not set up in the instial install, it is safe to ask about
# removing it. If it was set up, keep it, and don't even ask. Also don't
# ask if it's not installed.
if [ "$PCMCIA" = no -o -z "$PCMCIA" ] && dpkg --status pcmcia-cs 2>/dev/null | grep -q '^Status:.* installed$'; then
	db_input medium base-config/remove-pcmcia || true
	db_go || true
	db_get base-config/remove-pcmcia
	if [ "$RET" = true ]; then
  	      echo pcmcia-cs purge | dpkg --set-selections
		echo pcmcia-modules-`uname -r` purge | dpkg --set-selections
		# In a sane world, I would not need to do this.
		# Welcome to my world.
		rm -rf /etc/pcmcia /lib/modules/`uname -r`/pcmcia
		depmod -a >/dev/null || true
		# Delete lines above if/when those files are registed with dpkg.
	fi
fi
