lede-packages-rs

git clone git://archive.git.mtrnord.blog/MTRNord/lede-packages-rs.git
Log | Files | Refs | README | LICENSE

chrony.hotplug (1091B)


      1 #!/bin/sh
      2 # Set chronyd online/offline status, allow NTP access and add servers from DHCP
      3 
      4 [ "$ACTION" = ifup -o "$ACTION" = ifdown ] || exit 0
      5 
      6 run_command() {
      7 	/usr/bin/chronyc -n "$*" > /dev/null 2>&1
      8 }
      9 
     10 run_command tracking || exit 0
     11 
     12 . /lib/functions/network.sh
     13 
     14 network_find_wan iface4
     15 network_find_wan6 iface6
     16 run_command $([ -n "$iface4" ] && echo online || echo offline) 0.0.0.0/0.0.0.0
     17 run_command $([ -n "$iface6" ] && echo online || echo offline) ::/0
     18 
     19 [ "$ACTION" = ifup ] || exit 0
     20 
     21 . /lib/functions.sh
     22 . /etc/init.d/chronyd
     23 
     24 config_load chrony
     25 
     26 config_foreach handle_allow allow | while read command; do
     27 	run_command "$command"
     28 done
     29 
     30 # Add servers from DHCP only if the config has a dhcp_ntp_server section
     31 [ -z "$(config_foreach echo dhcp_ntp_server)" ] && exit 0
     32 
     33 . /usr/share/libubox/jshn.sh
     34 
     35 for iface in $iface4 $iface6; do
     36 	json_load "$(ifstatus $iface)"
     37 	json_select data
     38 	json_get_var dhcp_ntp_servers ntpserver
     39 
     40 	for server in $dhcp_ntp_servers; do
     41 		run_command add $(NTP_SOURCE_HOSTNAME=$server config_foreach \
     42 				handle_source dhcp_ntp_server server)
     43 	done
     44 done