#!/bin/sh
#
# Check the LTSP installation.

LTSPARCH=`dpkg --print-installation-architecture`

if [ amd64 = "$LTSPARCH" ] ; then
    LTSPARCH=i386
fi

PROFILE=
if test -r /etc/debian-edu/config ; then
    . /etc/debian-edu/config
fi

if echo "$PROFILE" | grep -q Thin-Client-Server ; then
    chroot="/opt/ltsp/$LTSPARCH"
    if [ -f $chroot/etc/ltsp_chroot ] ; then
	echo "success: Found LTSP chroot"
    else
	echo "error: LTSP chroot is missing in $chroot/"
    fi

    # Verify that the wanted packages are installed, first thin clients
    for pkg in $(tasksel --task-packages education-thin-client | sort) ; do
	if chroot $chroot dpkg -l $pkg > /dev/null 2>&1 ; then
	    echo "success: package $pkg is installed in LTSP chroot"
	else
	    echo "error: Package $pkg is not installed in LTSP chroot"
	fi
    done

    # and then diskless workstation
    for pkg in education-workstation ; do
	if chroot $chroot dpkg -l $pkg > /dev/null 2>&1 ; then
	    echo "success: package $pkg is installed in LTSP chroot"
	else
	    echo "error: Package $pkg is not installed in LTSP chroot"
	fi
    done

    # Ensure the profile file exist and is properly set for a diskless workstation
    if [ -f $chroot/etc/debian-edu/config ] ; then
        ( # In a subshell to avoid keeping the values in this script
            . $chroot/etc/debian-edu/config
            if [ Workstation != "$PROFILE" ] ; then
                echo "error: Missing PROFILE=Workstation in $chroot/etc/debian-edu/config."
            else
                echo "success: PROFILE=Workstation is set in $chroot/etc/debian-edu/config."
            fi
        )
    else
        echo "error: Missing $chroot/etc/debian-edu/config"
    fi

    for path in /etc/ldap/ssl/ldap-server-pubkey.pem \
	/etc/iceweasel/profile/cert_override.txt ; do
	if cmp $path  $chroot$path ; then
	    echo "success: $path is identical inside and outside LTSP"
	else
	    echo "error: $path differ inside and outside LTSP"
	fi
    done
fi
