ntpd_restart_cmd="/usr/local/etc/rc.d/ntpd restart"
fi
-make_ntp_conf()
+do_ntp_conf()
{
- [ -z "${new_ntp_servers}" ] && return 0
- local cf=/etc/ntp.conf."${interface}" x=
+ local cf=/etc/ntp.conf."${interface}" x= m1= m2=
+ local sig="# Generated by dhcpcd for interface"
+ local sig_end="# End of dhcpcd content for interface"
- grep -v "\(^[ \t]*server[ \t]*\|${signature}\)" /etc/ntp.conf > "${cf}"
- echo "# ${signature}" >> "${cf}"
- for x in ${new_ntp_servers}; do
- echo "server ${x}" >> "${cf}"
- done
- save_conf /etc/ntp.conf
- mv -f "${cf}" /etc/ntp.conf
- [ -n "${ntpd_restart_cmd}" ] && ${ntpd_restart_cmd}
-}
-
-restore_ntp_conf()
-{
- restore_conf /etc/ntp.conf || return 0
- [ -n "${ntpd_restart_cmd}" ] && ${ntpd_restart_cmd}
+ if [ -f /etc/ntp.conf ]; then
+ # Remove our old entry
+ m1="^${sig} ${interface}$"
+ m2="^${sig_end} ${interface}$"
+ sed "/${m1}/,/${m2}/d" /etc/ntp.conf > "${cf}"
+ # Remove stale entries
+ m1="^${sig} "
+ for x in $(sed -n "s/${m1}//p" "${cf}"); do
+ if [ ! -s /var/run/dhcpcd-${x}.pid ]; then
+ m1="^${sig} ${x}$"
+ m2="^${sig_end} ${x}$"
+ sed "/${m1}/,/${m2}/d" "${cf}" >"${cf}".tmp
+ mv -f "${cf}".tmp "${cf}"
+ fi
+ done
+ else
+ rm -f "${cf}"
+ fi
+ if [ "$1" = "add" -a -n "${new_ntp_servers}" ]; then
+ echo "${sig} ${interface}" >> "${cf}"
+ for x in ${new_ntp_servers}; do
+ echo "server ${x}" >> "${cf}"
+ done
+ echo "${sig_end} ${interface}" >> "${cf}"
+ fi
+ if [ -f "${cf}" ]; then
+ mv -f "${cf}" /etc/ntp.conf
+ [ -n "${ntpd_restart_cmd}" ] && ${ntpd_restart_cmd}
+ fi
}
case "${reason}" in
-BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) make_ntp_conf;;
-EXPIRE|FAIL|IPV4LL|RELEASE|STOP) restore_ntp_conf;;
+BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) do_ntp_conf add;;
+EXPIRE|FAIL|IPV4LL|RELEASE|STOP) do_ntp_conf del;;
esac
{
[ -z "${new_nis_domain}" -a -z "${new_nis_servers}" ] && return 0
local cf=/etc/yp.conf."${interface}" prefix= x= pid=
- echo "# ${signature}" > "${cf}"
+ echo "# Generated by dhcpcd for interface ${interface}" > "${cf}"
if [ -n "${new_nis_domain}" ]; then
domainname "${new_nis_domain}"
if [ -n "${new_nis_servers}" ]; then