#!/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" | grep -Eq 'Main-Server|Workstation|Roaming-Workstation|LTSP-Server|Minimal' ; then
    :
else
    exit 0
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'."
