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.

35 lines
862 B

  1. #!/bin/sh
  2. # ntp hotplug script for travelmate
  3. # Copyright (c) 2020 Dirk Brenken (dev@brenken.org)
  4. # This is free software, licensed under the GNU General Public License v3.
  5. # set (s)hellcheck exceptions
  6. # shellcheck disable=1091,2016,2039,2059,2086,2143,2181,2188
  7. trm_init="/etc/init.d/travelmate"
  8. trm_ntpfile="/var/state/travelmate.ntp"
  9. trm_logger="$(command -v logger)"
  10. f_log()
  11. {
  12. local class="${1}" log_msg="${2}"
  13. if [ -x "${trm_logger}" ]
  14. then
  15. "${trm_logger}" -p "${class}" -t "trm-ntp [${$}]" "${log_msg}"
  16. else
  17. printf "%s %s %s\\n" "${class}" "trm-ntp [${$}]" "${log_msg}"
  18. fi
  19. }
  20. if [ "${ACTION}" = "stratum" ] && [ ! -f "${trm_ntpfile}" ] && [ "$("${trm_init}" enabled; printf "%u" ${?})" = "0" ]
  21. then
  22. {
  23. flock -xn 1001
  24. if [ "$?" = "0" ]
  25. then
  26. f_log "info" "get ntp time sync"
  27. "${trm_init}" restart
  28. fi
  29. } 1001>"${trm_ntpfile}"
  30. fi