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.

37 lines
1016 B

  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. LC_ALL=C
  6. PATH="/usr/sbin:/usr/bin:/sbin:/bin"
  7. if [ -r "/lib/functions.sh" ]
  8. then
  9. . "/lib/functions.sh"
  10. adb_dns="$(uci_get adblock global adb_dns)"
  11. fi
  12. adb_ver="${1}"
  13. adb_ubus="$(command -v ubus)"
  14. adb_logger="$(command -v logger)"
  15. f_log()
  16. {
  17. local class="${1}" log_msg="${2}"
  18. if [ -x "${adb_logger}" ]
  19. then
  20. "${adb_logger}" -p "${class}" -t "adblock-${adb_ver}[${$}]" "${log_msg}"
  21. else
  22. printf "%s %s %s\\n" "${class}" "adblock-${adb_ver}[${$}]" "${log_msg}"
  23. fi
  24. }
  25. if [ -x "${adb_ubus}" ] && [ -n "${adb_dns}" ]
  26. then
  27. f_log "info" "ubus/adblock monitor started"
  28. "${adb_ubus}" -S -M r -m invoke monitor | \
  29. { grep -qE "\"method\":\"(set|signal)\",\"data\":\{\"name\":\"${adb_dns}\""; [ $? -eq 0 ] && /etc/init.d/adblock start; }
  30. else
  31. f_log "err" "can't start ubus/adblock monitor"
  32. fi