diff options
| author | Stan Grishin <stangri@melmac.net> | 2020-09-20 00:17:04 +0000 |
|---|---|---|
| committer | Stan Grishin <stangri@melmac.net> | 2020-09-20 00:17:04 +0000 |
| commit | b7c198b3e90d474c3cdcbd9fa3afcf3687f94e85 (patch) | |
| tree | 9f0e3474f522748a3ef1ceb48c6987fdbd834892 /net/simple-adblock/files/simple-adblock.init | |
| parent | a359b1b3bdf5924040cf0155e016fa8e9ae1f278 (diff) | |
simple-adblock: add config auto-update feature
Signed-off-by: Stan Grishin <stangri@melmac.net>
Diffstat (limited to 'net/simple-adblock/files/simple-adblock.init')
| -rw-r--r-- | net/simple-adblock/files/simple-adblock.init | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/net/simple-adblock/files/simple-adblock.init b/net/simple-adblock/files/simple-adblock.init index 40e977ab0..6f0b41354 100644 --- a/net/simple-adblock/files/simple-adblock.init +++ b/net/simple-adblock/files/simple-adblock.init @@ -53,6 +53,7 @@ readonly _FAIL_='\033[0;31m\xe2\x9c\x97\033[0m' readonly __OK__='\033[0;32m[\xe2\x9c\x93]\033[0m' readonly __FAIL__='\033[0;31m[\xe2\x9c\x97]\033[0m' readonly _ERROR_='\033[0;31mERROR\033[0m' +readonly configUpdateURL='https://cdn.jsdelivr.net/gh/openwrt/packages/net/simple-adblock/files/simple-adblock.conf.update' getStatusText() { local _ret @@ -89,8 +90,10 @@ getErrorText() { errorOhSnap) _ret="failed to create block-list or restart DNS resolver";; errorStopping) _ret="failed to stop $serviceName";; errorDNSReload) _ret="failed to reload/restart DNS resolver";; + errorDownloadingConfigUpdate) _ret="failed to download Config Update file";; errorDownloadingList) _ret="failed to download";; errorParsingList) _ret="failed to parse";; + errorParsingConfigUpdate) _ret="failed to parse Config Update file";; esac printf "%b" "$_ret" } @@ -139,6 +142,7 @@ parallelDL=1 debug=0 compressedCache=0 ipv6Enabled=0 +configUpdateEnabled=0 bootDelay=120 dlTimeout=20 curlRetry=3 @@ -169,6 +173,7 @@ load_package_config() { config_get_bool debug 'config' 'debug' 0 config_get_bool compressedCache 'config' 'compressed_cache' 0 config_get_bool ipv6Enabled 'config' 'ipv6_enabled' 0 + config_get_bool configUpdateEnabled 'config' 'config_update_enabled' 0 config_get bootDelay 'config' 'boot_delay' '120' config_get dlTimeout 'config' 'download_timeout' '20' config_get curlRetry 'config' 'curl_retry' '3' @@ -722,6 +727,31 @@ process_url() { return 0 } +process_config_update() { + local label R_TMP + [ "$configUpdateEnabled" -eq 0 ] && return 0 + label="${1##*//}"; label="${label%%/*}"; + while [ -z "$R_TMP" ] || [ -e "$R_TMP" ]; do + R_TMP="$(mktemp -u -q -t ${packageName}_tmp.XXXXXXXX)" + done + if ! $dl_command "$1" $dl_flag "$R_TMP" 2>/dev/null || [ ! -s "$R_TMP" ]; then + output 1 "$_FAIL_" + output 2 "[DL] Config Update: $label $__FAIL__\\n" + tmpfs add error "errorDownloadingConfigUpdate" + else + if ! sed -f "$R_TMP" -i /etc/config/simple-adblock; then + output 1 "$_FAIL_" + output 2 "[DL] Config Update: $label $__FAIL__\\n" + tmpfs add error "errorParsingConfigUpdate" + else + output 1 "$_OK_" + output 2 "[DL] Config Update: $label $__OK__\\n" + fi + fi + rm -f "$R_TMP" + return 0 +} + download_lists() { local hf w_filter j=0 R_TMP @@ -739,6 +769,7 @@ download_lists() { fi touch $A_TMP; touch $B_TMP; output 1 'Downloading lists ' + process_config_update "$configUpdateURL" rm -f "$sharedMemoryError" if [ -n "$blocked_hosts_urls" ]; then for hf in ${blocked_hosts_urls}; do |
