#!/bin/sh
#
# This is the preinst script for the Debian GNU/Linux apmd package
#
# Written by Dirk Eddelbuettel <edd@debian.org>   

#DEBHELPER#

set -e

case "$1" in
    install)
	;;
    upgrade)
	# Stop a running apmd from an older version
	if [ -f /usr/sbin/apmd ]
	then
	    start-stop-daemon --stop --quiet --oknodo  \
		    --pidfile /var/run/apmd.pid --exec /usr/sbin/apmd
	fi
	# Handle bug #4489: Old versions of apmd erroneously killed kerneld 
	# We test for these versions numbers, given by dpkg as $2, using an
	# expr(1) match, and if the 5 chars are matched, restart the kerneld
	if [ `expr match "$2" '2\.[124]-[01]$'` -eq 5 ]
	then 
	    /etc/init.d/kerneld start >/dev/null
	fi
	;;
    abort-upgrade)
	;;
    *)
	echo "preinst called with unknown argument \`$1'" >&2
	exit 0
	;;
esac                  

exit 0
