diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 17:35:01 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 17:35:01 +0000 |
commit | 763b5e2c4bed507e0fa34ca2b7cb4f15a136cb82 (patch) | |
tree | 829cb7231c945c8e1e7d8ad62e94c4cb0f902ec6 /examples/chrony.nm-dispatcher.dhcp | |
parent | Initial commit. (diff) | |
download | chrony-upstream/4.0.tar.xz chrony-upstream/4.0.zip |
Adding upstream version 4.0.upstream/4.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'examples/chrony.nm-dispatcher.dhcp')
-rw-r--r-- | examples/chrony.nm-dispatcher.dhcp | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/examples/chrony.nm-dispatcher.dhcp b/examples/chrony.nm-dispatcher.dhcp new file mode 100644 index 0000000..6ea4c37 --- /dev/null +++ b/examples/chrony.nm-dispatcher.dhcp @@ -0,0 +1,43 @@ +#!/bin/sh +# This is a NetworkManager dispatcher script for chronyd to update +# its NTP sources passed from DHCP options. Note that this script is +# specific to NetworkManager-dispatcher due to use of the +# DHCP4_NTP_SERVERS environment variable. + +export LC_ALL=C + +interface=$1 +action=$2 + +chronyc=/usr/bin/chronyc +default_server_options=iburst +server_dir=/var/run/chrony-dhcp + +dhcp_server_file=$server_dir/$interface.sources +# DHCP4_NTP_SERVERS is passed from DHCP options by NetworkManager. +nm_dhcp_servers=$DHCP4_NTP_SERVERS + +add_servers_from_dhcp() { + rm -f "$dhcp_server_file" + for server in $nm_dhcp_servers; do + echo "server $server $default_server_options" >> "$dhcp_server_file" + done + $chronyc reload sources > /dev/null 2>&1 || : +} + +clear_servers_from_dhcp() { + if [ -f "$dhcp_server_file" ]; then + rm -f "$dhcp_server_file" + $chronyc reload sources > /dev/null 2>&1 || : + fi +} + +mkdir -p $server_dir + +if [ "$action" = "up" ] || [ "$action" = "dhcp4-change" ]; then + add_servers_from_dhcp +elif [ "$action" = "down" ]; then + clear_servers_from_dhcp +fi + +exit 0 |