Files
operating-system/buildroot-external/rootfs-overlay/usr/lib/NetworkManager/dispatcher.d/10-ntp
redgryphon f62fee2ff7 Add support for NTP configuration via DHCP (fixes #689) (#1798)
* Add support for NTP configuration via DHCP.

* Default fallback NTP pool is the Cloudflare's one
2022-03-21 00:40:43 +01:00

42 lines
725 B
Bash

#!/bin/bash
#
TIMESYNCD_CONF=/run/systemd/timesyncd.conf.d/10-ntp.conf
timesyncd_dhcp_ntp_remove() {
if [ -e $TIMESYNCD_CONF ]; then
rm -f $TIMESYNCD_CONF
systemctl restart systemd-timesyncd.service
fi
}
timesyncd_dhcp_ntp_add() {
mkdir -p $(dirname $TIMESYNCD_CONF)
echo '[Time]' > ${TIMESYNCD_CONF}
echo "NTP=${DHCP4_NTP_SERVERS}" >> ${TIMESYNCD_CONF}
systemctl restart systemd-timesyncd.service
}
INTERFACE=${1}
ACTION=${2}
case ${ACTION} in
up|down|dhcp4-change)
if [ ! -z "${DHCP4_NTP_SERVERS}" ]
then
timesyncd_dhcp_ntp_add
RETURN_CODE=$?
else
timesyncd_dhcp_ntp_remove
RETURN_CODE=$?
fi
;;
*)
$RETURN_CODE=0
;;
esac
return $RETURN_CODE