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.

87 lines
1.6 KiB

  1. #!/bin/sh /etc/rc.common
  2. #
  3. START=50
  4. USE_PROCD=1
  5. EXTRA_COMMANDS="suspend resume query status"
  6. EXTRA_HELP=" suspend Suspend adblock processing
  7. resume Resume adblock processing
  8. query <DOMAIN> Query active blocklists for specific domains
  9. status Print runtime information"
  10. adb_init="/etc/init.d/adblock"
  11. adb_script="/usr/bin/adblock.sh"
  12. boot()
  13. {
  14. adb_boot=1
  15. ubus -t 30 wait_for network.interface 2>/dev/null
  16. rc_procd start_service
  17. }
  18. start_service()
  19. {
  20. if [ $("${adb_init}" enabled; printf "%u" ${?}) -eq 0 ]
  21. then
  22. if [ -n "${adb_boot}" ]
  23. then
  24. return 0
  25. fi
  26. procd_open_instance "adblock"
  27. procd_set_param command "${adb_script}" "${@}"
  28. procd_set_param stdout 1
  29. procd_set_param stderr 1
  30. procd_close_instance
  31. fi
  32. }
  33. reload_service()
  34. {
  35. rc_procd start_service reload
  36. }
  37. stop_service()
  38. {
  39. rc_procd "${adb_script}" stop
  40. rc_procd start_service
  41. }
  42. restart()
  43. {
  44. rc_procd start_service restart
  45. }
  46. suspend()
  47. {
  48. rc_procd "${adb_script}" suspend
  49. }
  50. resume()
  51. {
  52. rc_procd "${adb_script}" resume
  53. }
  54. query()
  55. {
  56. rc_procd "${adb_script}" query "${1}"
  57. }
  58. status()
  59. {
  60. rc_procd "${adb_script}" status
  61. }
  62. service_triggers()
  63. {
  64. local iface="$(uci -q get adblock.global.adb_iface)"
  65. local delay="$(uci -q get adblock.global.adb_triggerdelay)"
  66. PROCD_RELOAD_DELAY=$((${delay:=2} * 1000))
  67. for name in ${iface}
  68. do
  69. procd_add_interface_trigger "interface.*.up" "${name}" "${adb_init}" start
  70. done
  71. PROCD_RELOAD_DELAY=1000
  72. procd_add_config_trigger "config.change" "adblock" "${adb_init}" start
  73. }