#!/bin/sh
#
# Postinst script for authentic2-supann
#

add_supann_in_default() {
	cat << EODEFAULT >> /etc/default/authentic2
if [ -r /etc/authentic2/supann.conf ]; then
	. /etc/authentic2/supann.conf
fi
EODEFAULT
}

case "$1" in
    configure|reconfigure)
	if [ ! -f /etc/default/authentic2 ]; then
		add_supann_in_default
	elif ! grep -q supann.conf /etc/default/authentic2 2> /dev/null; then
		add_supann_in_default
	fi
        if [ ! -f /etc/authentic2/edu_person_targeted_id.salt ]; then
		< /dev/urandom tr -dc [:print:] | head -c70 > /etc/authentic2/edu_person_targeted_id.salt
		chown authentic2:authentic2 /etc/authentic2/edu_person_targeted_id.salt
		chmod 0400 /etc/authentic2/edu_person_targeted_id.salt
	fi
	if [ -d /var/log/authentic2-supann ]; then
		chown -R authentic2:adm /var/log/authentic2-supann
		chmod 750 /var/log/authentic2-supann
	fi
	invoke-rc.d authentic2 restart
	;;
    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

