#!/bin/sh
# postinst script for ca-certificates-schlittermann
#
# 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

CONF=/etc/ca-certificates.conf
DIR=/usr/share/ca-certificates
CRTS=$(cd $DIR && ls schlittermann/*.crt)

hash() { openssl x509 -noout -in "$1" -hash; }

case "$1" in
    configure)
	# aus der ca-certificates.conf entfernen
	echo "$CRTS" >> $CONF
	update-ca-certificates --fresh

	# find schlittermann certs that are used somewhere
	{
	    echo '/etc/ssl/certs/schlittermann-ca.pem' 
	    find /etc/ssl/certs \( \
		    -name '*ca*schlittermann*' \
		    -o  -name '*schlittermann*ca*' \
		\) -not -type l -type f -printf '%p\n'
	} | sort -u | while read FILE; do
		found=$(grep --exclude-dir '.hg' -rlF "$FILE" /etc) || continue
		{
		    echo "WARNING: \`$FILE' used in:"
		    echo "$found"
		    echo "Please replace this with \`$DIR/schlittermann/schlittermann-ca-bundle.pem'"
		} | sed 's/^/### /' >&2
	    done
    ;;

    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


