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

set -e

get_ntp_signd_group() {
    if getent group _chrony >/dev/null; then
        echo _chrony
    elif getent group chrony >/dev/null; then
        echo chrony
    elif getent group ntpsec >/dev/null; then
        echo ntpsec
    else
        echo ntp
    fi
}

# 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 https://www.debian.org/doc/debian-policy/ or
# the debian-policy package

case "$1" in
    configure)
        if [ -f /etc/apt/sources.list.d/seth-samba.list ]; then
            rm -f /etc/apt/sources.list.d/seth-samba.list
        fi
        if [ ! -e /var/lib/samba/ntp_signd ]; then
            /usr/bin/mkdir -p /var/lib/samba/ntp_signd
        fi
        /usr/bin/chown root:$(get_ntp_signd_group) /var/lib/samba/ntp_signd
        /usr/bin/chmod 0750 /var/lib/samba/ntp_signd
    ;;

    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
