#!/bin/sh
set -e

at_exit() {
    for m in $umount ; do
	echo info: umounting "$m"
	umount "$m"
    done
}

trap at_exit INT TERM EXIT

chroot_test() {
    cd $ADTTMP
    target=test-chroot
    suite=testing
    debootstrap testing $target
    printf "#!/bin/sh\nexit 101\n" > $target/usr/sbin/policy-rc.d
    chmod a+rx $target/usr/sbin/policy-rc.d
    mount -t proc proc $target/proc
    umount="$target/proc"
    mount -t sysfs sysfs $target/sys
    umount="$target/proc $target/sys"

    # The bless script is not yet part of any binary package
    apt-get source debian-edu-config 2>&1
    cp debian-edu-config-*/share/debian-edu-config/tools/debian-edu-bless \
	$target/root/.
    PROFILE=$PROFILE DESKTOP=$DESKTOP chroot $target \
	sh -x /root/debian-edu-bless 2>&1

    # List packages with problems in Debian
    chroot $target apt-get install -y how-can-i-help
    chroot $target how-can-i-help --old

    umount $target/proc
    umount="$target/sys"
    umount $target/sys
    umount=""
    rm -rf $target
}

# Use predictable language setting.
# FIXME should try several to check language specific setup
LC_ALL=C
export LC_ALL

echo "info: File system status (/proc/mounts):"
cat /proc/mounts
echo

# First a simple test
PROFILE=Minimal chroot_test

# Skip the rest until we get the basic test working
# FIXME Remove when the simple test is working.
exit 0

# Install profiles in chroots, first the non-desktop ones
for profile in Minimal Main-Server; do
    PROFILE="$profile" chroot_test
done

# Then the desktop ones
for profile in Workstation Roaming-Workstation Thin-Client-Server Standalone; do
    for desktop in kde gnome lxde xfce mate ; do
        DESKTOP="$desktop" PROFILE="$profile" chroot_test
    done
done
