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

# remove the debianfreespace logical volume
if [ -e /dev/vg_system/debianedufreespace ] ; then
    if mount | grep -q /debianedufreespace ; then
        umount /target/debianedufreespace
    fi
    lvremove -f /dev/vg_system/debianedufreespace
    grep -v /debianedufreespace /target/etc/fstab > /target/etc/fstab.new && \
      mv /target/etc/fstab.new /target/etc/fstab

    rmdir /target/debianedufreespace
fi

# Register changes before and after cfengine is executed, to make it
# easier to track our changes
[ -x /target/usr/sbin/debian-edu-etc-svk ] && \
  in-target /usr/sbin/debian-edu-etc-svk update || true

# libnss-ldap seem to remove this while when it is installed.  Reinsert it to
# make cfengine can do its stuff without hanging.
touch /target/var/lib/nss-ldap/bind_policy_soft

in-target cfengine-debian-edu -D installation || true

# Workaround for usplash bug #431560, skolelinux bug #1164
if [ -x /target/etc/rc1.d/K01usplash ] ; then
  mv /target/etc/rc1.d/K01usplash /target/etc/rc1.d/S80usplash
fi

# Register changes before and after cfengine is executed, to make it
# easier to track our changes
[ -x /target/usr/sbin/debian-edu-etc-svk ] && \
  in-target /usr/sbin/debian-edu-etc-svk update || true

exit 0
