adblock: release 4.2.5-1

* removed needless subshell calls
* add memory measurements:
   - size of the final blocklist in MB
   - free memory in MB (MemAvailable from /proc/meminfo)
   - script max. used RAM (VmHWM from /proc/$$/status)
* optimized restart logic
* cosmetics

Signed-off-by: Dirk Brenken <dev@brenken.org>
This commit is contained in:
Dirk Brenken
2025-02-17 21:58:24 +01:00
parent 7ff04e9e30
commit 162b1e693e
5 changed files with 94 additions and 85 deletions

View File

@@ -6,8 +6,8 @@
include $(TOPDIR)/rules.mk include $(TOPDIR)/rules.mk
PKG_NAME:=adblock PKG_NAME:=adblock
PKG_VERSION:=4.2.4 PKG_VERSION:=4.2.5
PKG_RELEASE:=2 PKG_RELEASE:=1
PKG_LICENSE:=GPL-3.0-or-later PKG_LICENSE:=GPL-3.0-or-later
PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org> PKG_MAINTAINER:=Dirk Brenken <dev@brenken.org>

View File

@@ -156,7 +156,7 @@ Available commands:
| adb_enabled | 1, enabled | set to 0 to disable the adblock service | | adb_enabled | 1, enabled | set to 0 to disable the adblock service |
| adb_srcarc | -, /etc/adblock/adblock.sources.gz | full path to the used adblock source archive | | adb_srcarc | -, /etc/adblock/adblock.sources.gz | full path to the used adblock source archive |
| adb_srcfile | -, /tmp/adb_sources.json | full path to the used adblock source file, which has a higher precedence than the archive file | | adb_srcfile | -, /tmp/adb_sources.json | full path to the used adblock source file, which has a higher precedence than the archive file |
| adb_dns | -, auto-detected | 'dnsmasq', 'unbound', 'named', 'kresd' or 'raw' | | adb_dns | -, auto-detected | 'dnsmasq', 'unbound', 'named', 'kresd', 'smartdns' or 'raw' |
| adb_fetchutil | -, auto-detected | 'uclient-fetch', 'wget', 'curl' or 'aria2c' | | adb_fetchutil | -, auto-detected | 'uclient-fetch', 'wget', 'curl' or 'aria2c' |
| adb_fetchparm | -, auto-detected | manually override the config options for the selected download utility | | adb_fetchparm | -, auto-detected | manually override the config options for the selected download utility |
| adb_fetchinsecure | 0, disabled | don't check SSL server certificates during download | | adb_fetchinsecure | 0, disabled | don't check SSL server certificates during download |

View File

@@ -51,6 +51,7 @@ stop_service() {
} }
restart() { restart() {
rc_procd "${adb_script}" stop
rc_procd start_service restart rc_procd start_service restart
} }

View File

@@ -1,6 +1,6 @@
#!/bin/sh #!/bin/sh
# send mail script for adblock notifications # send mail script for adblock notifications
# Copyright (c) 2015-2024 Dirk Brenken (dev@brenken.org) # Copyright (c) 2015-2025 Dirk Brenken (dev@brenken.org)
# This is free software, licensed under the GNU General Public License v3. # This is free software, licensed under the GNU General Public License v3.
# Please note: you have to manually install and configure the package 'msmtp' before using this script # Please note: you have to manually install and configure the package 'msmtp' before using this script

View File

@@ -27,6 +27,7 @@ adb_mailcnt="0"
adb_jail="0" adb_jail="0"
adb_tld="1" adb_tld="1"
adb_dns="" adb_dns=""
adb_dnspid=""
adb_dnsprefix="adb_list" adb_dnsprefix="adb_list"
adb_locallist="blacklist whitelist iplist" adb_locallist="blacklist whitelist iplist"
adb_tmpbase="/tmp" adb_tmpbase="/tmp"
@@ -82,7 +83,8 @@ f_load() {
adb_packages="$("${adb_ubuscmd}" -S call rpc-sys packagelist '{ "all": true }' 2>/dev/null)" adb_packages="$("${adb_ubuscmd}" -S call rpc-sys packagelist '{ "all": true }' 2>/dev/null)"
adb_ver="$(printf "%s" "${adb_packages}" | "${adb_jsoncmd}" -ql1 -e '@.packages.adblock')" adb_ver="$(printf "%s" "${adb_packages}" | "${adb_jsoncmd}" -ql1 -e '@.packages.adblock')"
adb_sysver="$("${adb_ubuscmd}" -S call system board 2>/dev/null | "${adb_jsoncmd}" -ql1 -e '@.model' -e '@.release.target' -e '@.release.distribution' -e '@.release.version' -e '@.release.revision' | adb_sysver="$("${adb_ubuscmd}" -S call system board 2>/dev/null |
"${adb_jsoncmd}" -ql1 -e '@.model' -e '@.release.target' -e '@.release.distribution' -e '@.release.version' -e '@.release.revision' |
"${adb_awkcmd}" 'BEGIN{RS="";FS="\n"}{printf "%s, %s, %s %s %s %s",$1,$2,$3,$4,$5,$6}')" "${adb_awkcmd}" 'BEGIN{RS="";FS="\n"}{printf "%s, %s, %s %s %s %s",$1,$2,$3,$4,$5,$6}')"
f_conf f_conf
@@ -113,7 +115,7 @@ f_load() {
f_log "info" "Please install the package 'tcpdump' or 'tcpdump-mini' to use the reporting feature" f_log "info" "Please install the package 'tcpdump' or 'tcpdump-mini' to use the reporting feature"
elif [ -x "${adb_dumpcmd}" ]; then elif [ -x "${adb_dumpcmd}" ]; then
bg_pid="$("${adb_pgrepcmd}" -f "^${adb_dumpcmd}.*adb_report\\.pcap$" | "${adb_awkcmd}" '{ORS=" "; print $1}')" bg_pid="$("${adb_pgrepcmd}" -f "^${adb_dumpcmd}.*adb_report\\.pcap$" | "${adb_awkcmd}" '{ORS=" "; print $1}')"
if [ "${adb_report}" = "0" ] || { [ -n "${bg_pid}" ] && { [ "${adb_action}" = "stop" ] || [ "${adb_action}" = "restart" ]; }; }; then if [ "${adb_report}" = "0" ] || { [ -n "${bg_pid}" ] && [ "${adb_action}" = "stop" ]; }; then
if [ -n "${bg_pid}" ]; then if [ -n "${bg_pid}" ]; then
kill -HUP "${bg_pid}" 2>/dev/null kill -HUP "${bg_pid}" 2>/dev/null
while kill -0 "${bg_pid}" 2>/dev/null; do while kill -0 "${bg_pid}" 2>/dev/null; do
@@ -445,16 +447,16 @@ f_temp() {
f_rmtemp() { f_rmtemp() {
rm -rf "${adb_tmpdir}" "${adb_srcfile}" rm -rf "${adb_tmpdir}" "${adb_srcfile}"
: >"${adb_pidfile}" : >"${adb_pidfile}"
if [ "${adb_backup}" = "0" ]; then
rm -f "${adb_backupdir}/${adb_dnsprefix}".*.gz
fi
} }
# remove dns related files # remove dns related files
# #
f_rmdns() { f_rmdns() {
if "${adb_ubuscmd}" -S call service list '{"name":"adblock"}' | "${adb_jsoncmd}" -ql1 -e '@["adblock"].instances.*.running' >/dev/null; then if "${adb_ubuscmd}" -S call service list 2>/dev/null | "${adb_jsoncmd}" -ql1 -e '@["adblock"].instances.*.running' >/dev/null; then
: >"${adb_rtfile}" : >"${adb_rtfile}"
if [ "${adb_backup}" = "0" ] || [ "${adb_action}" = "stop" ]; then
rm -f "${adb_backupdir}/${adb_dnsprefix}".*.gz
fi
printf "%b" "${adb_dnsheader}" >"${adb_dnsdir}/${adb_dnsfile}" printf "%b" "${adb_dnsheader}" >"${adb_dnsdir}/${adb_dnsfile}"
f_dnsup 4 f_dnsup 4
fi fi
@@ -589,7 +591,7 @@ f_extconf() {
# restart dns backend # restart dns backend
# #
f_dnsup() { f_dnsup() {
local rset dns_service dns_up dns_pid restart_rc cnt="0" out_rc="4" in_rc="${1:-0}" local rset dns_service dns_up restart_rc cnt="0" out_rc="4" in_rc="${1:-0}"
if [ "${adb_dns}" = "raw" ] || [ -z "${adb_dns}" ]; then if [ "${adb_dns}" = "raw" ] || [ -z "${adb_dns}" ]; then
out_rc="0" out_rc="0"
@@ -624,21 +626,21 @@ f_dnsup() {
restart_rc="${?}" restart_rc="${?}"
fi fi
fi fi
if [ "${restart_rc}" = "0" ]; then if [ "${restart_rc}" = "0" ] && [ "${in_rc}" = "0" ]; then
rset="/^(([[:alnum:]_-]{1,63}\\.)+[[:alnum:]-]+|[[:alnum:]-]+)([[:space:]]|$)/{print tolower(\$1)}" rset="/^(([[:alnum:]_-]{1,63}\\.)+[[:alnum:]-]+|[[:alnum:]-]+)([[:space:]]|$)/{print tolower(\$1)}"
while [ "${cnt}" -le "${adb_dnstimeout}" ]; do while [ "${cnt}" -le "${adb_dnstimeout}" ]; do
dns_service="$("${adb_ubuscmd}" -S call service list "{\"name\":\"${adb_dns}\"}")" dns_service="$("${adb_ubuscmd}" -S call service list 2>/dev/null)"
dns_up="$(printf "%s" "${dns_service}" | "${adb_jsoncmd}" -l1 -e "@[\"${adb_dns}\"].instances.*.running")" dns_up="$(printf "%s" "${dns_service}" | "${adb_jsoncmd}" -l1 -e "@[\"${adb_dns}\"].instances.*.running")"
dns_pid="$(printf "%s" "${dns_service}" | "${adb_jsoncmd}" -l1 -e "@[\"${adb_dns}\"].instances.*.pid")" adb_dnspid="$(printf "%s" "${dns_service}" | "${adb_jsoncmd}" -l1 -e "@[\"${adb_dns}\"].instances.*.pid")"
if [ "${dns_up}" = "true" ] && [ -n "${dns_pid}" ] && ! ls "/proc/${dns_pid}/fd/${adb_dnsdir}/${adb_dnsfile}" >/dev/null 2>&1; then if [ "${dns_up}" = "true" ] && [ -n "${adb_dnspid}" ] && ! ls "/proc/${adb_dnspid}/fd/${adb_dnsdir}/${adb_dnsfile}" >/dev/null 2>&1; then
if [ -x "${adb_lookupcmd}" ] && [ "${adb_lookupdomain}" != "false" ] && [ -n "$(printf "%s" "${adb_lookupdomain}" | "${adb_awkcmd}" "${rset}")" ]; then if [ -x "${adb_lookupcmd}" ] && [ "${adb_lookupdomain}" != "false" ] && [ -n "$(printf "%s" "${adb_lookupdomain}" | "${adb_awkcmd}" "${rset}")" ]; then
if "${adb_lookupcmd}" "${adb_lookupdomain}" >/dev/null 2>&1; then if "${adb_lookupcmd}" "${adb_lookupdomain}" >/dev/null 2>&1; then
out_rc="0" out_rc="0"
break break
fi fi
else else
sleep ${adb_dnstimeout} sleep "${adb_dnstimeout}"
cnt=${adb_dnstimeout} cnt="${adb_dnstimeout}"
out_rc="0" out_rc="0"
break break
fi fi
@@ -654,14 +656,14 @@ f_dnsup() {
fi fi
fi fi
f_log "debug" "f_dnsup ::: dns: ${adb_dns}, cache_cmd: ${adb_dnscachecmd:-"-"}, lookup_cmd: ${adb_lookupcmd:-"-"}, lookup_domain: ${adb_lookupdomain:-"-"}, restart_rc: ${restart_rc:-"-"}, dns_flush: ${adb_dnsflush}, dns_timeout: ${adb_dnstimeout}, dns_cnt: ${cnt}, in_rc: ${in_rc}, out_rc: ${out_rc}" f_log "debug" "f_dnsup ::: dns: ${adb_dns}, cache_cmd: ${adb_dnscachecmd:-"-"}, lookup_cmd: ${adb_lookupcmd:-"-"}, lookup_domain: ${adb_lookupdomain:-"-"}, restart_rc: ${restart_rc:-"-"}, dns_flush: ${adb_dnsflush}, dns_timeout: ${adb_dnstimeout}, dns_pid: ${adb_dnspid}, dns_cnt: ${cnt}, in_rc: ${in_rc}, out_rc: ${out_rc}"
return "${out_rc}" return "${out_rc}"
} }
# backup/restore/remove blocklists # backup/restore/remove blocklists
# #
f_list() { f_list() {
local hold file rset item array safe_url safe_ips safe_cname safe_domains ip out_rc file_name cnt mode="${1}" src_name="${2:-"${src_name}"}" in_rc="${src_rc:-0}" use_cname="0" ffiles="-maxdepth 1 -name ${adb_dnsprefix}.*.gz" local file rset item array safe_url safe_ips safe_cname safe_domains ip out_rc file_name mode="${1}" src_name="${2:-"${src_name}"}" in_rc="${src_rc:-0}" use_cname="0" ffiles="-maxdepth 1 -name ${adb_dnsprefix}.*.gz"
case "${mode}" in case "${mode}" in
"iplist") "iplist")
@@ -690,39 +692,41 @@ f_list() {
;; ;;
"blacklist" | "whitelist") "blacklist" | "whitelist")
src_name="${mode}" src_name="${mode}"
if [ "${src_name}" = "blacklist" ] && [ -f "${adb_blacklist}" ]; then rset="/^(([[:alnum:]_-]{1,63}\\.)+[[:alnum:]-]+|[[:alnum:]-]+)([[:space:]]|$)/{print tolower(\$1)}"
file_name="${adb_tmpfile}.${src_name}" case "${src_name}" in
rset="/^(([[:alnum:]_-]{1,63}\\.)+[[:alnum:]-]+|[[:alnum:]-]+)([[:space:]]|$)/{print tolower(\$1)}" "blacklist")
"${adb_awkcmd}" "${rset}" "${adb_blacklist}" >"${adb_tmpdir}/tmp.raw.${src_name}" if [ -f "${adb_blacklist}" ]; then
if [ -s "${adb_whitelist}" ]; then file_name="${adb_tmpfile}.${src_name}"
"${adb_awkcmd}" 'NR==FNR{member[$1];next}!($1 in member)' "${adb_whitelist}" "${adb_tmpdir}/tmp.raw.${src_name}" >"${adb_tmpdir}/tmp.deduplicate.${src_name}" "${adb_awkcmd}" "${rset}" "${adb_blacklist}" >"${adb_tmpdir}/tmp.raw.${src_name}"
else if [ -s "${adb_whitelist}" ]; then
"${adb_catcmd}" "${adb_tmpdir}/tmp.raw.${src_name}" >"${adb_tmpdir}/tmp.deduplicate.${src_name}" "${adb_awkcmd}" 'NR==FNR{member[$1];next}!($1 in member)' "${adb_whitelist}" "${adb_tmpdir}/tmp.raw.${src_name}" >"${adb_tmpdir}/tmp.deduplicate.${src_name}"
fi else
"${adb_awkcmd}" 'BEGIN{FS="."}{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' "${adb_tmpdir}/tmp.deduplicate.${src_name}" >"${adb_tmpdir}/tmp.raw.${src_name}" "${adb_catcmd}" "${adb_tmpdir}/tmp.raw.${src_name}" >"${adb_tmpdir}/tmp.deduplicate.${src_name}"
"${adb_sortcmd}" ${adb_srtopts} -u "${adb_tmpdir}/tmp.raw.${src_name}" 2>/dev/null >"${file_name}" fi
out_rc="${?}" "${adb_awkcmd}" 'BEGIN{FS="."}{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' "${adb_tmpdir}/tmp.deduplicate.${src_name}" >"${adb_tmpdir}/tmp.raw.${src_name}"
elif [ "${src_name}" = "whitelist" ] && [ -f "${adb_whitelist}" ]; then "${adb_sortcmd}" ${adb_srtopts} -u "${adb_tmpdir}/tmp.raw.${src_name}" 2>/dev/null >"${file_name}"
file_name="${adb_tmpdir}/tmp.raw.${src_name}"
[ "${adb_lookupdomain}" != "false" ] && printf "%s\n" "${adb_lookupdomain}" | "${adb_awkcmd}" "${rset}" >"${file_name}"
rset="/^(([[:alnum:]_-]{1,63}\\.)+[[:alnum:]-]+|[[:alnum:]-]+)([[:space:]]|$)/{print tolower(\$1)}"
"${adb_awkcmd}" "${rset}" "${adb_whitelist}" >>"${file_name}"
out_rc="${?}"
if [ "${out_rc}" = "0" ]; then
"${adb_awkcmd}" "${rset}" "${adb_tmpdir}/tmp.raw.${src_name}" >"${adb_tmpdir}/tmp.rem.${src_name}"
out_rc="${?}"
if [ "${out_rc}" = "0" ] && [ "${adb_dnsallow}" != "1" ]; then
eval "${adb_dnsallow}" "${adb_tmpdir}/tmp.raw.${src_name}" >"${adb_tmpdir}/tmp.add.${src_name}"
out_rc="${?}" out_rc="${?}"
if [ "${out_rc}" = "0" ] && [ "${adb_jail}" = "1" ] && [ "${adb_dnsstop}" != "0" ]; then fi
rm -f "${adb_jaildir}/${adb_dnsjail}" ;;
[ -n "${adb_dnsheader}" ] && printf "%b" "${adb_dnsheader}" >>"${adb_jaildir}/${adb_dnsjail}" "whitelist")
"${adb_catcmd}" "${adb_tmpdir}/tmp.add.${src_name}" >>"${adb_jaildir}/${adb_dnsjail}" if [ -f "${adb_whitelist}" ]; then
printf "%b\n" "${adb_dnsstop}" >>"${adb_jaildir}/${adb_dnsjail}" file_name="${adb_tmpdir}/tmp.raw.${src_name}"
[ "${adb_lookupdomain}" != "false" ] && printf "%s\n" "${adb_lookupdomain}" | "${adb_awkcmd}" "${rset}" >"${file_name}"
"${adb_awkcmd}" "${rset}" "${adb_whitelist}" >>"${file_name}"
"${adb_awkcmd}" "${rset}" "${adb_tmpdir}/tmp.raw.${src_name}" >"${adb_tmpdir}/tmp.rem.${src_name}"
out_rc="${?}"
if [ "${adb_dnsallow}" != "1" ]; then
eval "${adb_dnsallow}" "${adb_tmpdir}/tmp.raw.${src_name}" >"${adb_tmpdir}/tmp.add.${src_name}"
if [ "${adb_jail}" = "1" ] && [ "${adb_dnsstop}" != "0" ]; then
rm -f "${adb_jaildir}/${adb_dnsjail}"
[ -n "${adb_dnsheader}" ] && printf "%b" "${adb_dnsheader}" >>"${adb_jaildir}/${adb_dnsjail}"
"${adb_catcmd}" "${adb_tmpdir}/tmp.add.${src_name}" >>"${adb_jaildir}/${adb_dnsjail}"
printf "%b\n" "${adb_dnsstop}" >>"${adb_jaildir}/${adb_dnsjail}"
fi
fi fi
fi fi
fi ;;
fi esac
;; ;;
"safesearch") "safesearch")
file_name="${adb_tmpdir}/tmp.safesearch.${src_name}" file_name="${adb_tmpdir}/tmp.safesearch.${src_name}"
@@ -804,25 +808,19 @@ f_list() {
"${adb_zcatcmd}" "${adb_backupdir}/${adb_dnsprefix}.${src_name}.gz" >"${src_tmpfile}" "${adb_zcatcmd}" "${adb_backupdir}/${adb_dnsprefix}.${src_name}.gz" >"${src_tmpfile}"
out_rc="${?}" out_rc="${?}"
elif [ -z "${src_name}" ]; then elif [ -z "${src_name}" ]; then
cnt="1"
for file in "${adb_backupdir}/${adb_dnsprefix}".*.gz; do for file in "${adb_backupdir}/${adb_dnsprefix}".*.gz; do
if [ -r "${file}" ]; then if [ -r "${file}" ]; then
name="${file##*/}" name="${file##*/}"
name="${name%.*}" name="${name%.*}"
"${adb_zcatcmd}" "${file}" >"${adb_tmpfile}.${name}" & "${adb_zcatcmd}" "${file}" >"${adb_tmpfile}.${name}"
hold="$((cnt % adb_cores))" out_rc="${?}"
if [ "${hold}" = "0" ]; then [ "${out_rc}" != "0" ] && break
wait
fi
cnt="$((cnt + 1))"
fi fi
done done
wait
out_rc="${?}"
else else
out_rc=4 out_rc=4
fi fi
if [ "${adb_action}" != "start" ] && [ "${adb_action}" != "resume" ] && [ -n "${src_name}" ] && [ "${out_rc}" != "0" ]; then if [ "${adb_action}" != "start" ] && [ "${adb_action}" != "restart" ] && [ "${adb_action}" != "resume" ] && [ -n "${src_name}" ] && [ "${out_rc}" != "0" ]; then
adb_sources="${adb_sources/${src_name}}" adb_sources="${adb_sources/${src_name}}"
fi fi
;; ;;
@@ -854,13 +852,13 @@ f_list() {
[ -n "${adb_dnsheader}" ] && printf "%b" "${adb_dnsheader}" >>"${file_name}" [ -n "${adb_dnsheader}" ] && printf "%b" "${adb_dnsheader}" >>"${file_name}"
[ -s "${adb_tmpdir}/tmp.add.iplist" ] && "${adb_catcmd}" "${adb_tmpdir}/tmp.add.iplist" >>"${file_name}" [ -s "${adb_tmpdir}/tmp.add.iplist" ] && "${adb_catcmd}" "${adb_tmpdir}/tmp.add.iplist" >>"${file_name}"
[ -s "${adb_tmpdir}/tmp.add.whitelist" ] && "${adb_catcmd}" "${adb_tmpdir}/tmp.add.whitelist" >>"${file_name}" [ -s "${adb_tmpdir}/tmp.add.whitelist" ] && "${adb_catcmd}" "${adb_tmpdir}/tmp.add.whitelist" >>"${file_name}"
"${adb_catcmd}" "${adb_tmpdir}/tmp.safesearch".* 2>/dev/null >>"${file_name}" [ "${adb_safesearch}" = "1" ] && "${adb_catcmd}" "${adb_tmpdir}/tmp.safesearch."* 2>/dev/null >>"${file_name}"
if [ "${adb_dnsdeny}" != "0" ]; then if [ "${adb_dnsdeny}" != "0" ]; then
eval "${adb_dnsdeny}" "${adb_tmpdir}/${adb_dnsfile}" >>"${file_name}" eval "${adb_dnsdeny}" "${adb_tmpdir}/${adb_dnsfile}" >>"${file_name}"
else else
"${adb_catcmd}" "${adb_tmpdir}/${adb_dnsfile}" >>"${file_name}" "${adb_catcmd}" "${adb_tmpdir}/${adb_dnsfile}" >>"${file_name}"
fi fi
out_rc="${?}" out_rc="0"
;; ;;
esac esac
[ "${adb_debug}" = "1" ] || [ "${mode}" = "final" ] && f_count "${mode}" "${file_name}" [ "${adb_debug}" = "1" ] || [ "${mode}" = "final" ] && f_count "${mode}" "${file_name}"
@@ -873,7 +871,7 @@ f_list() {
# top level domain compression # top level domain compression
# #
f_tld() { f_tld() {
local cnt cnt_tld cnt_rem source="${1}" temp_tld="${1}.tld" local cnt_tld cnt_rem source="${1}" temp_tld="${1}.tld"
if "${adb_awkcmd}" '{if(NR==1){tld=$NF};while(getline){if(index($NF,tld".")==0){print tld;tld=$NF}}print tld}' "${source}" | if "${adb_awkcmd}" '{if(NR==1){tld=$NF};while(getline){if(index($NF,tld".")==0){print tld;tld=$NF}}print tld}' "${source}" |
"${adb_awkcmd}" 'BEGIN{FS="."}{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' >"${temp_tld}"; then "${adb_awkcmd}" 'BEGIN{FS="."}{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' >"${temp_tld}"; then
@@ -1002,18 +1000,26 @@ f_query() {
# update runtime information # update runtime information
# #
f_jsnup() { f_jsnup() {
local object sources runtime utils mem_free mem_max status="${1:-"enabled"}" local pids object sources runtime utils mem_dns mem_free mem_max status="${1:-"enabled"}"
mem_free="$("${adb_awkcmd}" '/^MemAvailable/{printf "%s",int($2/1024)}' "/proc/meminfo" 2>/dev/null)" if [ -n "${adb_dnspid}" ]; then
mem_max="$("${adb_awkcmd}" '/^VmHWM/{printf "%s",int($2)}' /proc/${$}/status 2>/dev/null)" pids="$("${adb_pgrepcmd}" -P "${adb_dnspid}" 2>/dev/null)"
for pid in ${adb_dnspid} ${pids}; do
mem_dns="$((mem_dns + $("${adb_awkcmd}" '/^VmSize/{printf "%s", $2}' "/proc/${pid}/status" 2>/dev/null)))"
done
mem_dns="$("${adb_awkcmd}" -v mem="${mem_dns}" 'BEGIN{printf "%.2f", mem/1024}' 2>/dev/null)"
fi
mem_free="$("${adb_awkcmd}" '/^MemAvailable/{printf "%.2f", $2/1024}' "/proc/meminfo" 2>/dev/null)"
mem_max="$("${adb_awkcmd}" '/^VmHWM/{printf "%.2f", $2/1024}' "/proc/${$}/status" 2>/dev/null)"
adb_cnt="$("${adb_awkcmd}" -v cnt="${adb_cnt}" 'BEGIN{res="";pos=0;for(i=length(cnt);i>0;i--){res=substr(cnt,i,1)res;pos++;if(pos==3&&i>1){res="."res;pos=0;}}; printf"%s",res}')"
case "${status}" in case "${status}" in
"enabled" | "error") "enabled" | "error")
adb_endtime="$(date "+%s")" adb_endtime="$(date "+%s")"
if [ "$(((adb_endtime - adb_starttime) / 60))" -lt 60 ]; then if [ "$(((adb_endtime - adb_starttime) / 60))" -lt 60 ]; then
runtime="${adb_action}, $(((adb_endtime - adb_starttime) / 60))m $(((adb_endtime - adb_starttime) % 60))s, ${mem_free:-0} MB available, ${mem_max:-0} KB max. used, $(date -Iseconds)" runtime="${adb_action}, $(((adb_endtime - adb_starttime) / 60))m $(((adb_endtime - adb_starttime) % 60))s, ${mem_free:-0} MB available, ${mem_max:-0} MB max. used, $(date -Iseconds)"
else else
runtime="${adb_action}, n/a, ${mem_free:-0} MB available, ${mem_max:-0} KB max. used, $(date -Iseconds)" runtime="${adb_action}, n/a, ${mem_free:-0} MB available, ${mem_max:-0} MB max. used, $(date -Iseconds)"
fi fi
[ "${status}" = "error" ] && adb_cnt="0" [ "${status}" = "error" ] && adb_cnt="0"
;; ;;
@@ -1042,13 +1048,13 @@ f_jsnup() {
json_load_file "${adb_rtfile}" >/dev/null 2>&1 json_load_file "${adb_rtfile}" >/dev/null 2>&1
json_add_string "adblock_status" "${status:-"enabled"}" json_add_string "adblock_status" "${status:-"enabled"}"
json_add_string "adblock_version" "${adb_ver}" json_add_string "adblock_version" "${adb_ver}"
json_add_string "blocked_domains" "${adb_cnt:-0}" json_add_string "blocked_domains" "${adb_cnt:-"0"}"
json_add_array "active_sources" json_add_array "active_sources"
for object in ${sources:-"-"}; do for object in ${sources:-"-"}; do
json_add_string "${object}" "${object}" json_add_string "${object}" "${object}"
done done
json_close_array json_close_array
json_add_string "dns_backend" "${adb_dns:-"-"} (${adb_dnscachecmd##*/}), ${adb_dnsdir:-"-"}" json_add_string "dns_backend" "${adb_dns:-"-"} (${adb_dnscachecmd##*/}), ${adb_dnsdir:-"-"}, ${mem_dns:-"0"} MB"
json_add_string "run_utils" "${utils:-"-"}" json_add_string "run_utils" "${utils:-"-"}"
json_add_string "run_ifaces" "trigger: ${adb_trigger:-"-"}, report: ${adb_repiface:-"-"}" json_add_string "run_ifaces" "trigger: ${adb_trigger:-"-"}, report: ${adb_repiface:-"-"}"
json_add_string "run_directories" "base: ${adb_tmpbase}, backup: ${adb_backupdir}, report: ${adb_reportdir}, jail: ${adb_jaildir}" json_add_string "run_directories" "base: ${adb_tmpbase}, backup: ${adb_backupdir}, report: ${adb_reportdir}, jail: ${adb_jaildir}"
@@ -1082,13 +1088,20 @@ f_log() {
# main function for blocklist processing # main function for blocklist processing
# #
f_main() { f_main() {
local src_tmpload src_tmpfile src_name src_rset src_url src_log src_arc src_cat src_item src_list src_entries src_suffix src_rc entry cnt local src_tmpload src_tmpfile src_name src_rset src_url src_arc src_cat src_item src_list src_entries src_suffix src_rc entry cnt
# white- and blacklist preparation # white- and blacklist preparation
# #
cnt="1"
for entry in ${adb_locallist}; do for entry in ${adb_locallist}; do
(f_list "${entry}" "${entry}") & (
f_list "${entry}" "${entry}"
) &
hold="$((cnt % adb_cores))"
[ "${hold}" = "0" ] && wait
cnt="$((cnt + 1))"
done done
wait
if [ "${adb_dns}" != "raw" ] && [ "${adb_jail}" = "1" ] && [ "${adb_jaildir}" = "${adb_dnsdir}" ]; then if [ "${adb_dns}" != "raw" ] && [ "${adb_jail}" = "1" ] && [ "${adb_jaildir}" = "${adb_dnsdir}" ]; then
printf "%b" "${adb_dnsheader}" >"${adb_dnsdir}/${adb_dnsfile}" printf "%b" "${adb_dnsheader}" >"${adb_dnsdir}/${adb_dnsfile}"
@@ -1114,7 +1127,9 @@ f_main() {
[ -z "${adb_safesearchlist}" ] && adb_safesearchlist="google bing duckduckgo pixabay yandex youtube" [ -z "${adb_safesearchlist}" ] && adb_safesearchlist="google bing duckduckgo pixabay yandex youtube"
cnt="1" cnt="1"
for entry in ${adb_safesearchlist}; do for entry in ${adb_safesearchlist}; do
(f_list safesearch "${entry}") & (
f_list safesearch "${entry}"
) &
hold="$((cnt % adb_cores))" hold="$((cnt % adb_cores))"
[ "${hold}" = "0" ] && wait [ "${hold}" = "0" ] && wait
cnt="$((cnt + 1))" cnt="$((cnt + 1))"
@@ -1161,7 +1176,7 @@ f_main() {
if [ -n "${src_cat}" ]; then if [ -n "${src_cat}" ]; then
( (
src_arc="${adb_tmpdir}/${src_url##*/}" src_arc="${adb_tmpdir}/${src_url##*/}"
src_log="$("${adb_fetchutil}" ${adb_fetchparm} "${src_arc}" "${src_url}" 2>&1)" "${adb_fetchutil}" ${adb_fetchparm} "${src_arc}" "${src_url}" >/dev/null 2>&1
src_rc="${?}" src_rc="${?}"
if [ "${src_rc}" = "0" ] && [ -s "${src_arc}" ]; then if [ "${src_rc}" = "0" ] && [ -s "${src_arc}" ]; then
src_suffix="$(eval printf "%s" \"\$\{adb_src_suffix_${src_name}:-\"domains\"\}\")" src_suffix="$(eval printf "%s" \"\$\{adb_src_suffix_${src_name}:-\"domains\"\}\")"
@@ -1175,8 +1190,7 @@ f_main() {
fi fi
: >"${src_arc}" : >"${src_arc}"
else else
src_log="$(printf "%s" "${src_log}" | "${adb_awkcmd}" '{ORS=" ";print $0}')" f_log "info" "download of '${src_name}' failed, url: ${src_url}, rule: ${src_rset:-"-"}, categories: ${src_cat:-"-"}, rc: ${src_rc}"
f_log "info" "download of '${src_name}' failed, url: ${src_url}, rule: ${src_rset:-"-"}, categories: ${src_cat:-"-"}, rc: ${src_rc}, log: ${src_log:-"-"}"
fi fi
if [ "${src_rc}" = "0" ] && [ -s "${src_tmpload}" ]; then if [ "${src_rc}" = "0" ] && [ -s "${src_tmpload}" ]; then
"${adb_awkcmd}" "${src_rset}" "${src_tmpload}" | "${adb_sedcmd}" "s/\r//g" | "${adb_awkcmd}" "${src_rset}" "${src_tmpload}" | "${adb_sedcmd}" "s/\r//g" |
@@ -1212,14 +1226,14 @@ f_main() {
( (
for suffix in ${src_cat:-${src_url}}; do for suffix in ${src_cat:-${src_url}}; do
if [ "${src_url}" != "${suffix}" ]; then if [ "${src_url}" != "${suffix}" ]; then
src_log="$("${adb_fetchutil}" ${adb_fetchparm} "${src_tmpcat}" "${src_url}${suffix}" 2>&1)" "${adb_fetchutil}" ${adb_fetchparm} "${src_tmpcat}" "${src_url}${suffix}" >/dev/null 2>&1
src_rc="${?}" src_rc="${?}"
if [ "${src_rc}" = "0" ] && [ -s "${src_tmpcat}" ]; then if [ "${src_rc}" = "0" ] && [ -s "${src_tmpcat}" ]; then
"${adb_catcmd}" "${src_tmpcat}" >>"${src_tmpload}" "${adb_catcmd}" "${src_tmpcat}" >>"${src_tmpload}"
: >"${src_tmpcat}" : >"${src_tmpcat}"
fi fi
else else
src_log="$("${adb_fetchutil}" ${adb_fetchparm} "${src_tmpload}" "${src_url}" 2>&1)" "${adb_fetchutil}" ${adb_fetchparm} "${src_tmpload}" "${src_url}" >/dev/null 2>&1
src_rc="${?}" src_rc="${?}"
fi fi
done done
@@ -1237,8 +1251,7 @@ f_main() {
: >"${src_tmpfile}" : >"${src_tmpfile}"
fi fi
else else
src_log="$(printf "%s" "${src_log}" | "${adb_awkcmd}" '{ORS=" ";print $0}')" f_log "info" "download of '${src_name}' failed, url: ${src_url}, rule: ${src_rset:-"-"}, categories: ${src_cat:-"-"}, rc: ${src_rc}"
f_log "info" "download of '${src_name}' failed, url: ${src_url}, rule: ${src_rset:-"-"}, categories: ${src_cat:-"-"}, rc: ${src_rc}, log: ${src_log:-"-"}"
[ "${adb_backup}" = "1" ] && [ "${adb_action}" != "start" ] && f_list restore [ "${adb_backup}" = "1" ] && [ "${adb_action}" != "start" ] && f_list restore
fi fi
) & ) &
@@ -1468,11 +1481,6 @@ case "${adb_action}" in
"stop") "stop")
f_rmdns f_rmdns
;; ;;
"restart")
f_rmdns
f_env
f_main
;;
"suspend") "suspend")
[ "${adb_dns}" != "raw" ] && f_switch suspend [ "${adb_dns}" != "raw" ] && f_switch suspend
;; ;;
@@ -1485,7 +1493,7 @@ case "${adb_action}" in
"query") "query")
f_query "${2}" f_query "${2}"
;; ;;
"start" | "reload") "start" | "reload" | "restart")
f_env f_env
f_main f_main
;; ;;