#!/bin/sh
set -e

if [ "$1" = "abort-upgrade" ]; then exit 0; fi

# Move configuration files from old locations
if [ -r /etc/sysconfig/pcmcia-scripts ] ; then
    mv /etc/sysconfig/pcmcia-scripts /etc/pcmcia
fi

if [ -r /etc/sysconfig/pcmcia ] ; then
    mv /etc/sysconfig/pcmcia /etc/pcmcia.conf
fi

# Need to stop cardmgr to upgrade pcmcia-cs
if [ "$1" = "upgrade" ]
then
    if start-stop-daemon --stop --quiet --signal 0 \
	--pidfile /var/run/cardmgr.pid --exec /sbin/cardmgr
    then
    	cat <<EOF

PCMCIA Card Serivces is about to be upgraded.  Your PCMCIA kernel
modules also will need to be upgraded.  If you have compiled your own
kernel, you will most likely need to also recompile the PCMCIA modules.
The pcmcia-source package has been provided to help Debian users recompile
the PCMCIA modules to work with their kernels' configurations.  (It also
is possible to rebuild these modules using the Debian source files for
the pcmcia-cs package.)

To upgrade PCMCIA Card Services, cardmgr, the PCMCIA device manager,
must be stopped, and it is currently running.  When cardmgr is stopped,
the system will lose access to all PCMCIA devices.

EOF
    	echo -n "May I stop PCMCIA support? (y/n) [y] "
    	read input
	echo
	if [ "$input" = "n" ]
	then
	    cat <<EOF

Cardmgr will not be stopped.  The upgrade of pcmcia-cs is incomplete;
you must finish it later, when you are ready to allow PCMCIA support to
be interupted.

EOF
    	    exit 1
	else
	    set +e
	    . /etc/init.d/pcmcia stop
	fi
    fi # cardmgr running
fi # upgrade
