#! /bin/sh
# postinst script for etoken-pro-aladdin
#

set -e

case "$1" in
    configure)

	if [ -x "`which update-reader.conf 2>/dev/null`" ] ; then
	    update-reader.conf || true
	fi
	if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
	    if [ -x "/etc/init.d/etsrvd" ]; then
		invoke-rc.d etsrvd stop || exit $?
	    fi
	    if [ -x "/etc/init.d/pcscd" ]; then
		invoke-rc.d  pcscd stop || exit $?
	    fi
	    if [ -x "/etc/init.d/etokend" ]; then
		invoke-rc.d  etokend stop   || exit $?
	    fi
	else
	    if [ -x "/etc/init.d/etsrvd" ]; then
		/etc/init.d/etsrvd stop || exit $?
	    fi
	    if [ -x "/etc/init.d/pcscd" ]; then
		/etc/init.d/pcscd stop || exit $?
	    fi
	    if [ -x "/etc/init.d/etokend" ]; then
		/etc/init.d/etokend stop || exit $?
	    fi
	    
	fi

	if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
	    if [ -x "/etc/init.d/etokend" ]; then
		invoke-rc.d  etokend start   || exit $?
	    fi
	    if [ -x "/etc/init.d/pcscd" ]; then
		invoke-rc.d  pcscd start || exit $?
	    fi
	    sleep 3
	    if [ -x "/etc/init.d/etsrvd" ]; then
		invoke-rc.d etsrvd start || exit $?
	    fi
	else
	    if [ -x "/etc/init.d/etokend" ]; then
		/etc/init.d/etokend start || exit $?
	    fi
	    if [ -x "/etc/init.d/pcscd" ]; then
		/etc/init.d/pcscd start || exit $?
	    fi
	    sleep 3
	    if [ -x "/etc/init.d/etsrvd" ]; then
		/etc/init.d/etsrvd start || exit $?
	    fi
	    
	fi

    ;;

    abort-upgrade|abort-remove|abort-deconfigure)

    ;;

    *)
        echo "postinst called with unknown argument \`$1'" >&2
        exit 1
    ;;
esac

exit 0


