You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

46 lines
1.0 KiB

  1. #!/bin/sh
  2. # Set chronyd online/offline status, allow NTP access and add servers from DHCP
  3. SOURCEFILE="/var/run/chrony-dhcp/$INTERFACE.sources"
  4. run_command() {
  5. /usr/bin/chronyc -n "$*" > /dev/null 2>&1
  6. }
  7. run_command onoffline
  8. if [ "$ACTION" = ifdown ] && [ -f "$SOURCEFILE" ]; then
  9. rm -f "$SOURCEFILE"
  10. run_command reload sources
  11. fi
  12. [ "$ACTION" = ifup ] || exit 0
  13. . /lib/functions.sh
  14. . /lib/functions/network.sh
  15. . /etc/init.d/chronyd
  16. config_load chrony
  17. config_foreach handle_allow allow | while read command; do
  18. run_command "$command"
  19. done
  20. # Add servers from DHCP only if the config has a dhcp_ntp_server section
  21. [ -z "$(config_foreach echo dhcp_ntp_server)" ] && exit 0
  22. . /usr/share/libubox/jshn.sh
  23. json_load "$(ifstatus "$INTERFACE")"
  24. json_select data
  25. json_get_var dhcp_ntp_servers ntpserver
  26. [ -z "$dhcp_ntp_servers" ] && exit 0
  27. mkdir -p "$(dirname "$SOURCEFILE")"
  28. for NTP_SOURCE_HOSTNAME in $dhcp_ntp_servers; do
  29. config_foreach handle_source dhcp_ntp_server server
  30. done > "$SOURCEFILE"
  31. run_command reload sources