#!/bin/bash

#VERSION=4
#CHANGES:added evaluation of udhcp-parameter

PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/bin/X11:/usr/local/bin:/usr/local/sbin:/usr/fallback
ntp_bin="/usr/local/bin/rdate"
ntp_opt="-ns"

beroconf=/usr/fallback/beroconf

if [ ! -x "${ntp_bin}" ]; then
	echo "${ntp_bin} not installed!"
	exit 1
fi

use_udhcp=$(${beroconf} get root use-dhcp-settings | grep -v failed)
if [ "${use_udhcp}" = "1" ] || [ "${use_udhcp}" = "yes" ]; then
	ntp_host=$(${beroconf} get root dhcp-ntp-host | grep -v failed)
else
	ntp_host=$(${beroconf} get root ntphost | grep -v failed)
fi
if [ -z "${ntp_host}" ]; then
	echo "no ntp-host defined"
	exit 1
fi

${ntp_bin} ${ntp_opt} ${ntp_host} &> /dev/null
