#!/bin/sh
# prerm script for xCAT-server
#
# see: dh_installdeb(1)

set -e

xcatd_init_compat=/opt/xcat/share/xcat/scripts/xcatd-init-compat

# 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


case "$1" in
    remove)
       if [ -f "/proc/cmdline" ]; then   # prevent running it during install into chroot image
            if "$xcatd_init_compat" can-use-systemctl; then
                systemctl stop xcatd.service
            elif ! "$xcatd_init_compat" uses-systemd --explicit-target && [ -x /etc/init.d/xcatd ]; then
                /etc/init.d/xcatd stop
            fi
       fi
       if "$xcatd_init_compat" uses-systemd --explicit-target; then
           if command -v systemctl >/dev/null 2>&1; then
               systemctl disable xcatd.service
           fi
       else
           if command -v update-rc.d >/dev/null 2>&1; then
               update-rc.d -f xcatd remove
           fi
       fi
    ;;
    upgrade|deconfigure)
    ;;

    failed-upgrade)
    ;;

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

# dh_installdeb will replace this with shell code automatically
# generated by other debhelper scripts.

#DEBHELPER#

exit 0
