#!/bin/sh -e
#
# Check the PXE setup.

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

# Only Main-Server should have the PXE boot setup
if echo "$PROFILE" | grep -q Main-Server ; then
    :
else
    exit 0
fi

file=/var/lib/tftpboot/pxelinux.0
if [ -f $file ] ; then
	echo "success: $0: PXE file $file is present"
else
	echo "error: $0: Unable to find PXE file $file"
fi

if egrep -q '^tftp.*/var/lib/tftpboot' /etc/inetd.conf ; then
	echo "success: $0: tftp entry in /etc/inetd.conf is using /var/lib/tftpboot"
else
	echo "error: $0: tftp entry in /etc/inetd.conf do not use /var/lib/tftpboot"
fi

# verify that tftp server is handing out pxelinux.0 and syslinux/ldlinux.c32
for file in pxelinux.0 syslinux/ldlinux.c32 ; do
    tmpfile=$(tempfile)
    if echo get /pxelinux.0 "$tmpfile" | tftp $(hostname) | grep -qi error || \
       [ ! -s "$tmpfile" ] ; then
        echo "error: $0: tftp server do not provide pxelinux.0!"
    else
        echo "success: $0: tftp server provide pxelinux.0."
    fi
    ls -l "$tmpfile"
    rm "$tmpfile"
done
