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.

73 lines
1.7 KiB

  1. #!/bin/sh /etc/rc.common
  2. START=25
  3. USE_PROCD=1
  4. EXTRA_COMMANDS="status"
  5. EXTRA_HELP=" status Print runtime information"
  6. trm_init="/etc/init.d/travelmate"
  7. trm_script="/usr/bin/travelmate.sh"
  8. boot()
  9. {
  10. ubus -t 30 wait_for network.interface network.wireless 2>/dev/null
  11. rc_procd start_service
  12. }
  13. start_service()
  14. {
  15. if [ $("${trm_init}" enabled; printf "%u" ${?}) -eq 0 ]
  16. then
  17. procd_open_instance "travelmate"
  18. procd_set_param command "${trm_script}" "${@}"
  19. procd_set_param stdout 1
  20. procd_set_param stderr 1
  21. procd_close_instance
  22. fi
  23. }
  24. stop_service()
  25. {
  26. local rtfile="$(uci_get travelmate global trm_rtfile)"
  27. rtfile="${rtfile:-"/tmp/trm_runtime.json"}"
  28. > "${rtfile}"
  29. rc_procd start_service
  30. }
  31. status()
  32. {
  33. local key keylist value rtfile="$(uci_get travelmate global trm_rtfile)"
  34. rtfile="${rtfile:-"/tmp/trm_runtime.json"}"
  35. if [ -s "${rtfile}" ]
  36. then
  37. printf "%s\n" "::: travelmate runtime information"
  38. json_load "$(cat "${rtfile}" 2>/dev/null)"
  39. json_select data
  40. json_get_keys keylist
  41. for key in ${keylist}
  42. do
  43. json_get_var value "${key}"
  44. printf " + %-18s : %s\n" "${key}" "${value}"
  45. done
  46. else
  47. printf "%s\n" "::: no travelmate runtime information available"
  48. fi
  49. }
  50. service_triggers()
  51. {
  52. local auto="$(uci_get travelmate global trm_automatic)"
  53. if [ "${auto}" = "0" ]
  54. then
  55. local trigger="$(uci_get travelmate global trm_iface)"
  56. local delay="$(uci_get travelmate global trm_triggerdelay)"
  57. PROCD_RELOAD_DELAY=$((${delay:-2} * 1000))
  58. procd_add_interface_trigger "interface.*.down" "${trigger}" "${trm_init}" start
  59. fi
  60. procd_add_reload_trigger "travelmate"
  61. }