50-ntp.conf revision e95877ecfa1170d77b1ec1f66752725cdda01b64
1# Sample dhcpcd hook script for ntp 2 3# Detect OpenRC or BSD rc 4# Distributions may want to just have their command here instead of this 5if type rc-service >/dev/null 2>&1 && rc-service --exists ntpd; then 6 ntpd_restart_cmd="rc-service ntpd -- --ifstarted --quiet restart" 7elif [ -x /etc/rc.d/ntpd ]; then 8 ntpd_restart_cmd="/etc/rc.d/ntpd restart" 9elif [ -x /usr/local/etc/rc.d/ntpd ]; then 10 ntpd_restart_cmd="/usr/local/etc/rc.d/ntpd restart" 11fi 12 13make_ntp_conf() 14{ 15 [ -z "${new_ntp_servers}" ] && return 0 16 local cf=/etc/ntp.conf."${interface}" x= 17 echo "${signature}" > "${cf}" 18 echo "restrict default noquery notrust nomodify" >> "${cf}" 19 echo "restrict 127.0.0.1" >> "${cf}" 20 for x in ${new_ntp_servers}; do 21 echo "restrict ${x} nomodify notrap noquery" >> "${cf}" 22 echo "server ${x}" >> "${cf}" 23 done 24 if [ ! -e /etc/ntp.conf ]; then 25 false 26 elif type cmp >/dev/null 2>&1; then 27 cmp -s /etc/ntp.conf "${cf}" 28 elif type diff >/dev/null 2>&1; then 29 diff -q /etc/ntp.conf "${cf}" >/dev/null 30 else 31 false 32 fi 33 if [ $? = 0 ]; then 34 rm -f "${cf}" 35 else 36 save_conf /etc/ntp.conf 37 mv -f "${cf}" /etc/ntp.conf 38 [ -n "${ntpd_restart_cmd}" ] && ${ntpd_restart_cmd} 39 fi 40} 41 42restore_ntp_conf() 43{ 44 restore_conf /etc/ntp.conf || return 0 45 [ -n "${ntpd_restart_cmd}" ] && ${ntpd_restart_cmd} 46} 47 48case "${reason}" in 49BOUND|INFORM|REBIND|REBOOT|RENEW|TIMEOUT) make_ntp_conf;; 50EXPIRE|FAIL|IPV4LL|RELEASE|STOP) restore_ntp_conf;; 51esac 52