diff options
Diffstat (limited to 'dhcpcd-hooks/50-ntp.conf')
-rw-r--r-- | dhcpcd-hooks/50-ntp.conf | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/dhcpcd-hooks/50-ntp.conf b/dhcpcd-hooks/50-ntp.conf new file mode 100644 index 0000000..3772215 --- /dev/null +++ b/dhcpcd-hooks/50-ntp.conf @@ -0,0 +1,51 @@ +# 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 |