#!/bin/sh
# postinst script for eole-proxy-pkg
#
# see: dh_installdeb(1)

set -e

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

SERVICES_TO_MASK="e2guardian"

mask_services() {
    # Disable unwanted services
    for service in ${@}
    do
        # Unmask non disabled service
        if systemctl status ${service} > /dev/null 2>&1 \
           && [ "$(systemctl is-enabled ${service})" = 'masked' ]
        then
            systemctl unmask ${service}
        fi

        if systemctl is-enabled ${service} > /dev/null 2>&1
        then
            systemctl stop ${service} > /dev/null 2>&1 || true
            systemctl disable ${service}
            systemctl mask ${service} || true
        fi
    done
}

case "$1" in
    configure)
        mask_services ${SERVICES_TO_MASK}
    ;;

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

    *)
        echo "postinst 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
