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.

45 lines
1006 B

  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. . /etc/init.d/chronyd
  15. config_load chrony
  16. config_foreach handle_allow allow | while read command; do
  17. run_command "$command"
  18. done
  19. # Add servers from DHCP only if the config has a dhcp_ntp_server section
  20. [ -z "$(config_foreach echo dhcp_ntp_server)" ] && exit 0
  21. . /usr/share/libubox/jshn.sh
  22. json_load "$(ifstatus "$INTERFACE")"
  23. json_select data
  24. json_get_var dhcp_ntp_servers ntpserver
  25. [ -z "$dhcp_ntp_servers" ] && exit 0
  26. mkdir -p "$(dirname "$SOURCEFILE")"
  27. for NTP_SOURCE_HOSTNAME in $dhcp_ntp_servers; do
  28. config_foreach handle_source dhcp_ntp_server server
  29. done > "$SOURCEFILE"
  30. run_command reload sources