dhcpcd/dhcpcd-hooks/50-ntp.conf
2008-05-27 11:22:58 +00:00

52 lines
1.4 KiB
Plaintext

# Sample dhcpcd hook script for ntp
# Detect OpenRC or BSD rc
# Distributions may want to just have their command here instead of this
if type rc-service >/dev/null 2>&1 && rc-service --exists ntpd; then
ntpd_restart_cmd="rc-service ntpd -- --ifstarted --quiet restart"
elif [ -x /etc/rc.d/ntpd ]; then
ntpd_restart_cmd="/etc/rc.d/ntpd restart"
elif [ -x /usr/local/etc/rc.d/ntpd ]; then
ntpd_restart_cmd="/usr/local/etc/rc.d/ntpd restart"
fi
make_ntp_conf()
{
[ -z "${new_ntp_servers}" ] && return 0
local cf=/etc/ntp.conf."${interface}" x=
echo "${signature}" > "${cf}"
echo "restrict default noquery notrust nomodify" >> "${cf}"
echo "restrict 127.0.0.1" >> "${cf}"
for x in ${new_ntp_servers}; do
echo "restrict ${x} nomodify notrap noquery" >> "${cf}"
echo "server ${x}" >> "${cf}"
done
if [ ! -e /etc/ntp.conf ]; then
false
elif type cmp >/dev/null 2>&1; then
cmp -s /etc/ntp.conf "${cf}"
elif type diff >/dev/null 2>&1; then
diff -q /etc/ntp.conf "${cf}" >/dev/null
else
false
fi
if [ $? = 0 ]; then
rm -f "${cf}"
else
save_conf /etc/ntp.conf
mv -f "${cf}" /etc/ntp.conf
[ -n "${ntpd_restart_cmd}" ] && ${ntpd_restart_cmd}
fi
}
restore_ntp_conf()
{
restore_conf /etc/ntp.conf || return 0
[ -n "${ntpd_restart_cmd}" ] && ${ntpd_restart_cmd}
}
case "${reason}" in
BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) make_ntp_conf;;
EXPIRE|FAIL|IPV4LL|RELEASE|STOP) restore_ntp_conf;;
esac