#!/bin/sh -e
#
# Test if the NTP configuration is correct.

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

# Only networked profiles use NTP
if echo "$PROFILE" | egrep -q 'Main-Server|Workstation|Roaming-Workstation|Thin-Client-Server|Minimal' ; then
    :
else
    exit 0
fi

if dash -n /etc/default/ntpdate ; then
    :
else
    echo error: script error in /etc/default/ntpdate.
fi

if [ ! -x /usr/bin/ntpq ] ; then
    echo "error: $0: The ntpq binary is missing."
    exit 1
fi

# Test if NTP server is reachable
if ping -c1 ntp > /dev/null 2>&1 ; then
    echo "success: $0: Host 'ntp' is pingable."
else
    echo "error: $0: Host 'ntp' is not pingable."
    RESULT=1
fi

curservers=`ntpq -c lpeers | tail -n +3 | awk '{print $1}' |tr "\n" " "`

echo "info: $0: Current NTP servers: '$curservers'."

##
## with r73294 and r73295 Debian Edu main server uses 
## Debian's default values for NTP servers in ntpd.conf 
## again, so dropping this test
##
#
#if echo $PROFILE | grep -q 'Main-Server' ; then
#    if echo $curservers | grep -q 'LOCAL(0)' ; then
#	echo "success: $0: Found local NTP clock on server."
#    else
#	echo "error: $0: Missing local NTP clock on server."
#    fi
#fi
