adblock: release 3.0
[feed/packages.git] / net / adblock / files / adblock.init
index 59b987f90ce5142c0b08438d368e006863730636..d49c6ea2de38f2ae4baccb7491bfc30a0eb8d09a 100755 (executable)
@@ -1,43 +1,37 @@
 #!/bin/sh /etc/rc.common
 #
 
-START=90
+START=30
 USE_PROCD=1
 
-EXTRA_COMMANDS="suspend resume query"
+EXTRA_COMMANDS="suspend resume query status"
 EXTRA_HELP="   suspend Suspend adblock processing
        resume  Resume adblock processing
-       query   <DOMAIN> Query active blocklists for specific domain"
+       query   <DOMAIN> Query active blocklists for specific domains
+       status  Print runtime information"
 
+adb_init="/etc/init.d/adblock"
 adb_script="/usr/bin/adblock.sh"
 
 boot()
 {
-    local wanif4 wanif6 cnt=0
-
-    . "/lib/functions/network.sh"
-    while [ ${cnt} -le 30 ]
-    do
-        network_find_wan wanif4
-        network_find_wan6 wanif6
-        if [ -n "${wanif4}" ] || [ -n "${wanif6}" ] || [ ${cnt} -eq 30 ]
-        then
-            rc_procd start_service
-            return 0
-        else
-            sleep 1
-            cnt=$((cnt+1))
-            network_flush_cache
-        fi
-    done
+    adb_boot=1
+    rc_procd start_service
 }
 
 start_service()
 {
-    if [ $(/etc/init.d/adblock enabled; printf ${?}) -eq 0 ]
+    if [ $("${adb_init}" enabled; printf "%u" ${?}) -eq 0 ]
     then
+        if [ -n "${adb_boot}" ]
+        then
+            local trigger="$(uci_get adblock.global.adb_trigger)"
+            if [ "${trigger}" != "timed" ]
+            then
+                return 0
+            fi
+        fi
         procd_open_instance "adblock"
-        procd_set_param env adb_procd="true"
         procd_set_param command "${adb_script}" "${@}"
         procd_set_param stdout 1
         procd_set_param stderr 1
@@ -52,8 +46,8 @@ reload_service()
 
 stop_service()
 {
-    export adb_procd="true"
     rc_procd "${adb_script}" stop
+    rc_procd start_service
 }
 
 restart()
@@ -63,33 +57,33 @@ restart()
 
 suspend()
 {
-    rc_procd start_service suspend
+    rc_procd "${adb_script}" suspend
 }
 
 resume()
 {
-    rc_procd start_service resume
+    rc_procd "${adb_script}" resume
 }
 
 query()
 {
-    export adb_procd="true"
     rc_procd "${adb_script}" query "${1}"
 }
 
+status()
+{
+    rc_procd "${adb_script}" status
+}
+
 service_triggers()
 {
-    local iface="$(uci -q get adblock.global.adb_iface)"
+    local trigger="$(uci_get adblock.global.adb_trigger)"
+    local delay="$(uci_get adblock.global.adb_triggerdelay)"
 
-    if [ -z "${iface}" ]
+    if [ "${trigger}" != "none" ] && [ "${trigger}" != "timed" ]
     then
-        procd_add_raw_trigger "interface.*.up" 1000 /etc/init.d/adblock start
-    else
-        for name in ${iface}
-        do
-            procd_add_interface_trigger "interface.*.up" "${name}" /etc/init.d/adblock start
-        done
+        PROCD_RELOAD_DELAY=$((${delay:=1} * 1000))
+        procd_add_interface_trigger "interface.*.up" "${trigger}" "${adb_init}" start
     fi
-
-    procd_add_config_trigger "config.change" "adblock" /etc/init.d/adblock start
+    procd_add_reload_trigger "adblock"
 }