# Sample dhcpcd hook script for NTP
# It will configure either one of NTP, OpenNTP or Chrony (in that order)
# and will default to NTP if no default config is found.
# Like our resolv.conf hook script, we store a database of ntp.conf files
# and merge into /etc/ntp.conf
# You can set the env var NTP_CONF to override the derived default on
# systems with >1 NTP client installed.
# Here is an example for OpenNTP
# dhcpcd -e NTP_CONF=/usr/pkg/etc/ntpd.conf
# or by adding this to /etc/dhcpcd.conf
# env NTP_CONF=/usr/pkg/etc/ntpd.conf
# or by adding this to /etc/dhcpcd.enter-hook
# NTP_CONF=/usr/pkg/etc/ntpd.conf
# To use Chrony instead, simply change ntpd.conf to chrony.conf in the
# above examples.
# If NTP_CONF is not set, work out a good default
if [ -z "$NTP_CONF" ]; then
for d in ${ntp_conf_dirs}; do
for f in ${ntp_confs}; do
if [ -e "$d/$f" ]; then
NTP_CONF="$d/$f"
break 2
fi
done
done
[ -e "$NTP_CONF" ] || NTP_CONF=/etc/ntp.conf
fi
# Derive service name from configuration
if [ -z "$ntp_service" ]; then
case "$NTP_CONF" in
*chrony.conf) ntp_service=chronyd;;
*) ntp_service=ntpd;;
esac
fi
# Debian has a separate file for DHCP config to avoid stamping on
# the master.
if [ "$ntp_service" = ntpd ] && command -v invoke-rc.d >/dev/null 2>&1; then
[ -e /var/lib/ntp ] || mkdir /var/lib/ntp
: ${ntp_service:=ntp}
: ${NTP_DHCP_CONF:=/var/lib/ntp/ntp.conf.dhcp}
fi
# Build a list of interfaces
interfaces=$(list_interfaces "$ntp_conf_dir")
header=
servers=
if [ -n "$interfaces" ]; then
# Build the header
for x in ${interfaces}; do
header="$header${header:+, }$x"
done
# Build a server list
srvs=$(cd "$ntp_conf_dir";
key_get_value "server " $interfaces)
if [ -n "$srvs" ]; then
for x in $(uniqify $srvs); do
servers="${servers}server $x$NL"
done
fi
fi