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.

27 lines
936 B

  1. #!/bin/sh
  2. # ubus monitor to trace dns backend events and conditionally restart adblock
  3. # written by Dirk Brenken (dev@brenken.org)
  4. # This is free software, licensed under the GNU General Public License v3.
  5. # You should have received a copy of the GNU General Public License
  6. # along with this program. If not, see <http://www.gnu.org/licenses/>.
  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. if [ -x "${adb_ubus}" ] && [ -n "${adb_dns}" ]
  17. then
  18. logger -p "info" -t "adblock-${adb_ver}[${$}]" "ubus/adblock service started"
  19. "${adb_ubus}" -S -M r -m invoke monitor | \
  20. { grep -qE "\"method\":\"(set|signal)\",\"data\":\{\"name\":\"${adb_dns}\""; [ $? -eq 0 ] && /etc/init.d/adblock start; }
  21. else
  22. logger -p "err" -t "adblock-${adb_ver}[${$}]" "can't start ubus/adblock service"
  23. fi