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.

40 lines
1.1 KiB

  1. #!/bin/sh
  2. # ubus monitor to trace dns backend events and conditionally restart adblock
  3. # Copyright (c) 2015-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,2010,2016,2034,2039,2059,2086,2091,2129,2143,2154,2181,2183,2188
  7. LC_ALL=C
  8. PATH="/usr/sbin:/usr/bin:/sbin:/bin"
  9. if [ -r "/lib/functions.sh" ]
  10. then
  11. . "/lib/functions.sh"
  12. adb_dns="$(uci_get adblock global adb_dns)"
  13. fi
  14. adb_ver="${1}"
  15. adb_ubus="$(command -v ubus)"
  16. adb_logger="$(command -v logger)"
  17. f_log()
  18. {
  19. local class="${1}" log_msg="${2}"
  20. if [ -x "${adb_logger}" ]
  21. then
  22. "${adb_logger}" -p "${class}" -t "adblock-${adb_ver}[${$}]" "${log_msg}"
  23. else
  24. printf "%s %s %s\\n" "${class}" "adblock-${adb_ver}[${$}]" "${log_msg}"
  25. fi
  26. }
  27. if [ -x "${adb_ubus}" ] && [ -n "${adb_dns}" ]
  28. then
  29. f_log "info" "ubus/adblock monitor started"
  30. "${adb_ubus}" -S -M r -m invoke monitor | \
  31. { grep -qE "\"method\":\"(set|signal)\",\"data\":\{\"name\":\"${adb_dns}\""; [ $? -eq 0 ] && /etc/init.d/adblock start; }
  32. else
  33. f_log "err" "can't start ubus/adblock monitor"
  34. fi