#! /bin/sh -e
#
# Last finishing touch before rebooting into the installed system.

. /usr/share/debconf/confmodule

# Stop automatic lvm resize script
rm -f /target/debian-edu-extend-file-systems

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

error() {
    logger -t 10debian-edu-install "error: $@"
}

db_get mirror/protocol || true
PROTOCOL="$RET"
if [ "$PROTOCOL" = "http" ]; then
    db_get mirror/http/proxy
    http_proxy="$RET" || true
    if [ "$http_proxy" ]; then
	export http_proxy
    fi
fi

hook=/target/usr/share/debian-edu-config/d-i/finish-install
if [ -x $hook ] ; then
    log "Running debian-edu-config finish-install hook"
    $hook
else
    # Backwards compatibility with older debian-edu-config packages.
    # Should be removed when debian-edu-config package with hooks is
    # available from Debian/unstable.

    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
fi

# Clean up changes done to tasksel in post-base-installer and go back
# to the default behavior.
for test in desktop new-install ; do
    file=/usr/lib/tasksel/tests/$test
    if [ -x /target$file.edu ] ; then
	rm /target$file
	chroot /target dpkg-divert --package debian-edu-install \
	    --rename --quiet --remove $file
	rm /target$file.edu
    else
	error "Missing divert for $file."
    fi
done

exit 0
