#!/bin/sh

# Only run once
[ -n "${POST_UPGRADE_CACHE}" ] && touch "${POST_UPGRADE_CACHE}/`basename $0`"

NTP_CF="/etc/ntp.conf.local"
[ -r "${NTP_CF}" ] || exit 0
echo " * Testing NTP configuration file ${NTP_CF} for 'noquery' restriction"

if grep -q "^restrict default" "${NTP_CF}"
then
	:
else
	echo " *** no 'restrict default' line found; perhaps use the web"
	echo " *** interface to re-create the timing configuration."
	exit 0
fi

if grep -q "^restrict default.*noquery" "${NTP_CF}"
then
	echo "   - already present"
	exit 0
fi

echo "   - not found; adding it"

NTP_CF_TMP="`mktemp "${NTP_CF}.XXXXXX"`"
sed -e 's/^restrict default\(.*\)$/restrict default \1 noquery/' \
	< "${NTP_CF}" \
	> "${NTP_CF_TMP}"

if [ $? -ne 0 ] 
then
	rm -f "${NTP_CF_TMP}"
	exit 1
fi

mv "${NTP_CF_TMP}" "${NTP_CF}"
