Files
packages/net/adblock/files/adblock.init
T
Dirk Brenken 157bd82ac0 adblock: release 4.5.5-1
* added an separate adblock rundir (/var/run/adblock)
* refine the cpu/core detection
* behaviour change: allowlist domains now also removes subdomains from the blocklist
* flock/serialize the etag writing in the f_etag function
* code clean-up/linting

Signed-off-by: Dirk Brenken <dev@brenken.org>
2026-04-17 09:57:55 +02:00

122 lines
2.8 KiB
Bash
Executable File

#!/bin/sh /etc/rc.common
# Copyright (c) 2015-2026 Dirk Brenken (dev@brenken.org)
# This is free software, licensed under the GNU General Public License v3.
# (s)hellcheck exceptions
# shellcheck disable=all
START=30
USE_PROCD=1
extra_command "suspend" "Suspend adblock processing"
extra_command "resume" "Resume adblock processing"
extra_command "search" "<domain> Search active blocklists and backups for a specific domain"
extra_command "report" "[<cli>|<mail>|<gen>|<json>] Print DNS statistics"
adb_init="/etc/init.d/adblock"
adb_script="/usr/bin/adblock.sh"
adb_rundir="/var/run/adblock"
adb_pidfile="/var/run/adblock/adblock.pid"
if [ -z "${IPKG_INSTROOT}" ]; then
[ ! -d "${adb_rundir}" ] && mkdir -p "${adb_rundir}"
case "${action}" in
"boot")
"${adb_init}" running && exit 0
;;
esac
if [ -s "${adb_pidfile}" ]; then
case "${action}" in
"start" | "stop" | "restart" | "reload" | "report" | "suspend" | "resume" | "search")
exit 1
;;
esac
fi
fi
boot() {
: >"${adb_pidfile}"
rc_procd start_service boot
}
start_service() {
if "${adb_init}" enabled; then
if [ "${action}" = "boot" ]; then
[ -n "$(uci_get adblock global adb_trigger)" ] && return 0
fi
procd_open_instance "adblock"
procd_set_param command "${adb_script}" "${@:-"${action}"}"
procd_set_param pidfile "${adb_pidfile}"
procd_set_param nice "$(uci_get adblock global adb_nicelimit "0")"
procd_set_param stdout 0
procd_set_param stderr 1
procd_close_instance
fi
}
restart() {
stop_service "restart"
rc_procd start_service restart
}
reload_service() {
rc_procd start_service reload
}
stop_service() {
[ -z "${1}" ] && rc_procd "${adb_script}" stop
}
suspend() {
rc_procd start_service suspend
}
resume() {
rc_procd start_service resume
}
search() {
rc_procd "${adb_script}" search "${1}"
}
report() {
rc_procd "${adb_script}" report "${1:-"cli"}" "${2}" "${3}" "${4}"
}
status() {
status_service
}
status_service() {
local key keylist value values
json_init
json_load_file "/var/run/adblock/adblock.runtime.json" >/dev/null 2>&1
json_get_keys keylist
if [ -n "${keylist}" ]; then
printf '%s\n' "::: adblock runtime information"
for key in ${keylist}; do
json_get_var value "${key}" >/dev/null 2>&1
if [ "${key}" = "active_feeds" ]; then
json_get_values values "${key}" >/dev/null 2>&1
value="${values}"
fi
printf ' + %-15s : %s\n' "${key}" "${value:-"-"}"
done
else
printf '%s\n' "::: no adblock runtime information available"
fi
}
service_triggers() {
local iface delay trigger
delay="$(uci_get adblock global adb_triggerdelay "5")"
trigger="$(uci_get adblock global adb_trigger)"
PROCD_RELOAD_DELAY="$((delay * 1000))"
for iface in ${trigger}; do
procd_add_interface_trigger "interface.*.up" "${iface}" "${adb_init}" start
done
}