#!/bin/sh
# prerm script for packetfence-redis-cache
#
# see: dh_installdeb(1)

set -e

# summary of how this script can be called:
#        * <prerm> `remove'
#        * <old-prerm> `upgrade' <new-version>
#        * <new-prerm> `failed-upgrade' <old-version>
#        * <conflictor's-prerm> `remove' `in-favour' <package> <new-version>
#        * <deconfigured's-prerm> `deconfigure' `in-favour'
#          <package-being-installed> <version> `removing'
#          <conflicting-package> <version>
# for details, see http://www.debian.org/doc/debian-policy/ or
# the debian-policy package

DIST=$(lsb_release -c -s)

case "$1" in
    upgrade|deconfigure)
    ;;

    remove)
        if [ ${DIST} = "wheezy" ] || [ ${DIST} = "precise" ]; then
            if [ -x "/etc/init.d/packetfence-redis-cache" ]; then
                if [ -x "`which invoke-rc.d 2>/dev/null`" ]; then
                    invoke-rc.d packetfence-redis-cache stop || exit $?
                else
                    /etc/init.d/packetfence-redis-cache stop || exit $?
                fi
            fi
        fi
        if [ ${DIST} = "jessie" ] || [ ${DIST} = "stretch" ] || [ ${DIST} = "bullseye" ]; then
            systemctl stop packetfence-redis-cache
        fi
    ;;

# End automatically added sectio
    failed-upgrade)
    ;;

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

exit 0
