#!/bin/sh

set -e

case "$1" in
    configure|reconfigure|abort-remove|abort-deconfigure)
        # Ensure that the default Kerberos realm is set properly.  We also set
        # this in FAI, but do it here too out of paranoia.  Use
        # debconf-set-selections so that we don't have to define a template.
        echo "krb5-config krb5-config/default_realm string stanford.edu" \
            | debconf-set-selections

        # On upgrade from older versions of stanford-server, preseed dash to
        # not be /bin/sh.  Don't do this every time we're installed so that
        # someone can still override this on individual systems if desired.
        # FAI will set this as the default.
        if [ -n "$2" ] && dpkg --compare-versions "$2" lt 80 ; then
            echo "dash dash/sh boolean false" | debconf-set-selections
        fi

        # Set the permissions for ksu and su appropriately.
        dpkg-statoverride --list /usr/bin/ksu > /dev/null 2>&1 \
            || dpkg-statoverride --update --add root root 4750 /usr/bin/ksu
        dpkg-statoverride --list /bin/su > /dev/null 2>&1 \
            || dpkg-statoverride --update --add root root 4750 /bin/su

        # If this system runs horsewatcher-feed, restart it since the script
        # may have changed.
        for d in /service/horsewatcher-* ; do
            if [ -x "${d}/run" ] ; then
                echo "Restarting $d"
                svc -t "$d"
            fi
        done
        ;;
esac

#DEBHELPER#

exit 0
