adblock: update 1.0.1 2546/head
authorDirk Brenken <dirk@brenken.org>
Wed, 23 Mar 2016 20:02:45 +0000 (21:02 +0100)
committerDirk Brenken <dirk@brenken.org>
Wed, 23 Mar 2016 20:02:45 +0000 (21:02 +0100)
* optimize list sort
* simplified block list removal

Signed-off-by: Dirk Brenken <openwrt@brenken.org>
net/adblock/Makefile
net/adblock/files/adblock-helper.sh
net/adblock/files/adblock-update.sh

index b11a62ceecbb0b8d40da2d5a66f8f2a260b39453..cffa23d3759a079689206e3ce7fe70e4d5d45818 100644 (file)
@@ -7,7 +7,7 @@
 include $(TOPDIR)/rules.mk
 
 PKG_NAME:=adblock
-PKG_VERSION:=1.0.0
+PKG_VERSION:=1.0.1
 PKG_RELEASE:=1
 PKG_LICENSE:=GPL-3.0+
 PKG_MAINTAINER:=Dirk Brenken <openwrt@brenken.org>
index 5bcb81ad87270451d92c3bfb0fce68dea7973d5d..7f9ea55448f86f74bd67a5e1c6797441cb2fc091 100644 (file)
@@ -304,6 +304,8 @@ f_envcheck()
     then
         mem_ok="false"
         f_log "not enough free memory, overall sort processing will be disabled (total: ${mem_total}, free: ${mem_free}, swap: ${mem_swap})"
+    else
+        mem_ok="true"
     fi
 
     # check backup configuration
index 71878e87b8e5321e8d3446506c99df3d3bb705a1..56ea4a0fe82222dd5fdcf326b7d51e60f2cdbc36 100755 (executable)
@@ -36,7 +36,7 @@ fi
 # get current directory, script- and openwrt version
 #
 adb_scriptdir="${0%/*}"
-adb_scriptver="1.0.0"
+adb_scriptver="1.0.1"
 openwrt_version="$(cat /etc/openwrt_version)"
 
 # source in adblock function library
@@ -276,51 +276,36 @@ if [ -n "${adb_srclist}" ]
 then
     rm_done="$(find "${adb_dnsdir}" -maxdepth 1 -type f -name "${adb_dnsprefix}.*" \( ${adb_srclist} \) -print -exec rm -f "{}" \;)"
     rc=${?}
-    if [ $((rc)) -eq 0 ] && [ -n "${rm_done}" ]
-    then
-        f_log "disabled adblock lists removed"
-        if [ "${backup_ok}" = "true" ]
-        then
-            rm_done="$(find "${adb_backupdir}" -maxdepth 1 -type f -name "${adb_dnsprefix}.*" \( ${adb_srclist} \) -print -exec rm -f "{}" \;)"
-            rc=${?}
-            if  [ $((rc)) -eq 0 ] && [ -n "${rm_done}" ]
-            then
-                f_log "disabled adblock list backups removed"
-            elif [ $((rc)) -ne 0 ]
-            then
-                f_log "error during removal of disabled adblock list backups" "${rc}"
-                f_exit
-            fi
-        fi
-    elif [ $((rc)) -ne 0 ]
-    then
-        f_log "error during removal of disabled adblock lists" "${rc}"
-        f_exit
-    fi
 else
     rm_done="$(find "${adb_dnsdir}" -maxdepth 1 -type f -name "${adb_dnsprefix}.*" -print -exec rm -f "{}" \;)"
     rc=${?}
-    if [ $((rc)) -eq 0 ] && [ -n "${rm_done}" ]
+fi
+if [ $((rc)) -eq 0 ] && [ -n "${rm_done}" ]
+then
+    f_log "disabled adblock lists removed"
+    if [ "${backup_ok}" = "true" ]
     then
-        f_log "all adblock lists removed"
-        if [ "${backup_ok}" = "true" ]
+        if [ -n "${adb_srclist}" ]
         then
+            rm_done="$(find "${adb_backupdir}" -maxdepth 1 -type f -name "${adb_dnsprefix}.*" \( ${adb_srclist} \) -print -exec rm -f "{}" \;)"
+            rc=${?}
+        else
             rm_done="$(find "${adb_backupdir}" -maxdepth 1 -type f -name "${adb_dnsprefix}.*" -print -exec rm -f "{}" \;)"
             rc=${?}
-            if [ $((rc)) -eq 0 ] && [ -n "${rm_done}" ]
-            then
-                f_log "all adblock list backups removed"
-            elif [ $((rc)) -ne 0 ]
-            then
-                f_log "error during removal of all adblock list backups" "${rc}"
-                f_exit
-            fi
         fi
-    elif [ $((rc)) -ne 0 ]
-    then
-        f_log "error during removal of all adblock lists" "${rc}"
-        f_exit
+        if  [ $((rc)) -eq 0 ] && [ -n "${rm_done}" ]
+        then
+            f_log "disabled adblock list backups removed"
+        elif [ $((rc)) -ne 0 ]
+        then
+            f_log "error during removal of disabled adblock list backups" "${rc}"
+            f_exit
+        fi
     fi
+elif [ $((rc)) -ne 0 ]
+then
+    f_log "error during removal of disabled adblock lists" "${rc}"
+    f_exit
 fi
 
 # partial restore of adblock lists in case of download errors
@@ -341,38 +326,35 @@ fi
 
 # make separate adblock lists entries unique
 #
-if [ "${mem_ok}" != "false" ]
+if [ "${mem_ok}" = "true" ] && [ -n "${adb_revsrclist}" ]
 then
-    if [ -n "${adb_revsrclist}" ]
-    then
-        f_log "remove duplicates in separate adblock lists"
+    f_log "remove duplicates in separate adblock lists"
 
-        # generate a temporary unique overall list
-        #
-        head -qn -3 "${adb_dnsdir}/${adb_dnsprefix}."* | sort -u > "${adb_dnsdir}/tmp.overall"
+    # generate a unique overall block list
+    #
+    head -qn -3 "${adb_dnsdir}/${adb_dnsprefix}."* | sort -u > "${adb_tmpdir}/blocklist.overall"
 
-        # loop through all separate lists, ordered by size (ascending)
+    # loop through all separate lists, ordered by size (ascending)
+    #
+    for list in $(ls -Sr "${adb_dnsdir}/${adb_dnsprefix}."*)
+    do
+        # check overall block list vs. separate block list,
+        # write only duplicate entries to a temporary separate list
         #
-        for list in $(ls -Sr "${adb_dnsdir}/${adb_dnsprefix}."*)
-        do
-            # check original separate list vs. temporary overall list,
-            # rewrite only duplicate entries back to temporary separate list
-            #
-            list="${list/*./}"
-            sort "${adb_dnsdir}/tmp.overall" "${adb_dnsdir}/${adb_dnsprefix}.${list}" | uniq -d > "${adb_dnsdir}/tmp.${list}"
+        list="${list/*./}"
+        sort "${adb_tmpdir}/blocklist.overall" "${adb_dnsdir}/${adb_dnsprefix}.${list}" | uniq -d > "${adb_tmpdir}/tmp.${list}"
 
-            # rewrite only unique entries back to temporary overall list
-            #
-            tmp_unique="$(sort "${adb_dnsdir}/tmp.overall" "${adb_dnsdir}/tmp.${list}" | uniq -u)"
-            printf "%s\n" "${tmp_unique}" > "${adb_dnsdir}/tmp.overall"
+        # write only unique entries back to overall block list
+        #
+        sort "${adb_tmpdir}/blocklist.overall" "${adb_tmpdir}/tmp.${list}" | uniq -u > "${adb_tmpdir}/tmp.overall"
+        mv -f "${adb_tmpdir}/tmp.overall" "${adb_tmpdir}/blocklist.overall"
 
-            # write unique result back to original separate list (with list footer)
-            #
-            tail -qn 3 "${adb_dnsdir}/$adb_dnsprefix.${list}" >> "${adb_dnsdir}/tmp.${list}"
-            mv -f "${adb_dnsdir}/tmp.${list}" "${adb_dnsdir}/${adb_dnsprefix}.${list}"
-        done
-        rm -f "${adb_dnsdir}/tmp.overall"
-    fi
+        # write unique result back to original separate list
+        #
+        tail -qn 3 "${adb_dnsdir}/${adb_dnsprefix}.${list}" >> "${adb_tmpdir}/tmp.${list}"
+        mv -f "${adb_tmpdir}/tmp.${list}" "${adb_dnsdir}/${adb_dnsprefix}.${list}"
+    done
+    rm -f "${adb_tmpdir}/blocklist.overall"
 fi
 
 # set separate list count & get overall count