#!/bin/sh
#
# This script is executed within the debian-installer environment when
# finish-install.d is executed, which is executed at the end of the
# installation after the cfengine-debian-edu script has executed

set -e

. /usr/share/debconf/confmodule

log() {
    logger -t debian-edu-config-finish-install "$@"
}

# Register changes before gosa is installed
edu-etcvcs commit

#for arg in $(cat /proc/cmdline) ; do
#    case "$arg" in
#        # Make it easier to test Gosa
#	install-gosa)
	    if grep Main-Server /target/etc/debian-edu/config ; then
		# Can not use apt-install, as it refuses to remove
		# packages, and gosa depend on php5-gd which depend on
		# libgd2-xpm, which conflict with the already
		# installed libgd2-noxdm.
		in-target apt-get install -y gosa gosa-plugin-samba \
		    gosa-plugin-sudo gosa-plugin-ldapmanager \
		    gosa-plugin-dns gosa-plugin-dhcp \
		    || true
	    fi
#	    ;;
#    esac
#done

# Register changes before and after cfengine is executed, to make it
# easier to track our changes
edu-etcvcs commit

# Make the installation look more like a finished system, to make sure
# debconf-get-selections --installer work.
. /usr/lib/finish-install.d/94save-logs

# Update configuration for everything that could not be preseeded
in-target cfengine-debian-edu -D installation || true

edu-etcvcs commit

# Make sure the root password is gone from debconf after the
# installation, in case the kerberos-init-kdc script failed when
# cfengine was executed.
db_set debian-edu-config/kdc-password ''
db_set debian-edu-config/kdc-password-again ''
log "info: Ensuring kerberos kdc-passwords are cleared from debconf database"

# In case etcinsvk was not initialized in pre-pkgsel (ie
# non-debug install), do it here.  This is part of the workaround for
# bug #507742.
edu-etcvcs init
