#!/bin/sh # Script to dispatch NetworkManager events # # Updates timesyncd configuration with NTP servers # See NetworkManager(8) for further documentation of the dispatcher events. # Note: # RootDistanceMaxSec is set to 15 to override the default that is sometimes too # low when talking to Windows Servers set -e [ -n "${CONNECTION_UUID}" ] || exit INTERFACE="${1}" ACTION="${2}" TIMESYNCCONF="/etc/systemd/timesyncd.conf.d/${CONNECTION_UUID}.conf" AUTOGEN_SIGNATURE="# File generated by $(basename $0)" # Exit if file is not autogenerated if [ -f "${TIMESYNCCONF}" ] && ! grep -q "${AUTOGEN_SIGNATURE}" "${TIMESYNCCONF}"; then exit 0 fi case "${ACTION}" in up | dhcp4-change | dhcp6-change) [ -n "${DHCP4_NTP_SERVERS}" ] || exit mkdir -p $(dirname ${TIMESYNCCONF}) cat< ${TIMESYNCCONF} ${AUTOGEN_SIGNATURE} [Time] NTP=${DHCP4_NTP_SERVERS} RootDistanceMaxSec=15 EOF systemctl restart systemd-timesyncd ;; down) rm -f "${TIMESYNCCONF}" systemctl restart systemd-timesyncd ;; esac