aboutsummaryrefslogtreecommitdiff
path: root/net/chrony/files/chrony.hotplug
blob: 208343916a0e737bbff0b7c5d2faff1683ac52d9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#!/bin/sh
# Set chronyd online/offline status, allow NTP access and add servers from DHCP

SOURCEFILE="/var/run/chrony-dhcp/$INTERFACE.sources"

run_command() {
	/usr/bin/chronyc -n "$*" > /dev/null 2>&1
}

run_command onoffline

if [ "$ACTION" = ifdown ] && [ -f "$SOURCEFILE" ]; then
	rm -f "$SOURCEFILE"
	run_command reload sources
fi

[ "$ACTION" = ifup ] || exit 0

. /lib/functions.sh
. /lib/functions/network.sh
. /etc/init.d/chronyd

config_load chrony

config_foreach handle_allow allow | while read command; do
	run_command "$command"
done

# Add servers from DHCP only if the config has a dhcp_ntp_server section
[ -z "$(config_foreach echo dhcp_ntp_server)" ] && exit 0

. /usr/share/libubox/jshn.sh

json_load "$(ifstatus "$INTERFACE")"
json_select data
json_get_var dhcp_ntp_servers ntpserver

[ -z "$dhcp_ntp_servers" ] && exit 0

mkdir -p "$(dirname "$SOURCEFILE")"

for NTP_SOURCE_HOSTNAME in $dhcp_ntp_servers; do
	config_foreach handle_source dhcp_ntp_server server
done > "$SOURCEFILE"

run_command reload sources