• R/O
  • HTTP
  • SSH
  • HTTPS

packages: Commit

Community maintained packages for ImmortalWrt.


Commit MetaInfo

Revision8d2d6c46d61dee6e5b909add58859cfc5a5875a1 (tree)
Time2022-12-03 04:19:21
AuthorStan Grishin <stangri@melm...>
CommiterGitHub

Log Message

Merge pull request #19993 from stangri/master-simple-adblock

simple-adblock: localizable error/warning messages

Change Summary

Incremental Difference

--- a/net/simple-adblock/Makefile
+++ b/net/simple-adblock/Makefile
@@ -6,7 +6,7 @@ include $(TOPDIR)/rules.mk
66
77 PKG_NAME:=simple-adblock
88 PKG_VERSION:=1.9.3
9-PKG_RELEASE:=2
9+PKG_RELEASE:=3
1010 PKG_MAINTAINER:=Stan Grishin <stangri@melmac.ca>
1111 PKG_LICENSE:=GPL-3.0-or-later
1212
--- a/net/simple-adblock/files/simple-adblock.init
+++ b/net/simple-adblock/files/simple-adblock.init
@@ -100,49 +100,60 @@ uci_changes() {
100100 ipset() { "$ipset" "$@" >/dev/null 2>&1; }
101101 nft() { "$nft" "$@" >/dev/null 2>&1; }
102102
103-get_status_text() {
104- local _ret
103+get_text() {
104+ local r
105105 case "$1" in
106- statusNoInstall) _ret="$serviceName is not installed or not found";;
107- statusStopped) _ret="Stopped";;
108- statusStarting) _ret="Starting";;
109- statusRestarting) _ret="Restarting";;
110- statusForceReloading) _ret="Force Reloading";;
111- statusDownloading) _ret="Downloading";;
112- statusProcessing) _ret="Processing";;
113- statusError) _ret="Error";;
114- statusWarning) _ret="Warning";;
115- statusFail) _ret="Fail";;
116- statusSuccess) _ret="Success";;
117- esac
118- printf "%b" "$_ret"
119-}
120-get_error_text() {
121- local _ret
122- case "$1" in
123- errorOutputFileCreate) _ret="failed to create $outputFile file";;
124- errorFailDNSReload) _ret="failed to restart/reload DNS resolver";;
125- errorSharedMemory) _ret="failed to access shared memory";;
126- errorSorting) _ret="failed to sort data file";;
127- errorOptimization) _ret="failed to optimize data file";;
128- errorAllowListProcessing) _ret="failed to process allow-list";;
129- errorDataFileFormatting) _ret="failed to format data file";;
130- errorMovingDataFile) _ret="failed to move data file '${A_TMP}' to '${outputFile}'";;
131- errorCreatingCompressedCache) _ret="failed to create compressed cache";;
132- errorRemovingTempFiles) _ret="failed to remove temporary files";;
133- errorRestoreCompressedCache) _ret="failed to unpack compressed cache";;
134- errorRestoreCache) _ret="failed to move '$outputCache' to '$outputFile'";;
135- errorOhSnap) _ret="failed to create block-list or restart DNS resolver";;
136- errorStopping) _ret="failed to stop $serviceName";;
137- errorDNSReload) _ret="failed to reload/restart DNS resolver";;
138- errorDownloadingConfigUpdate) _ret="failed to download Config Update file";;
139- errorDownloadingList) _ret="failed to download";;
140- errorParsingConfigUpdate) _ret="failed to parse Config Update file";;
141- errorParsingList) _ret="failed to parse";;
142- errorNoSSLSupport) _ret="no HTTPS/SSL support on device";;
143- errorCreatingDirectory) _ret="failed to create output/cache/gzip file directory";;
106+ errorConfigValidationFail) r="$packageName config validation failed";;
107+ errorServiceDisabled) r="$packageName is currently disabled";;
108+ errorNoDnsmasqIpset)
109+ r="dnsmasq ipset support is enabled in $packageName, but dnsmasq is either not installed or installed dnsmasq does not support ipset";;
110+ errorNoIpset)
111+ r="dnsmasq ipset support is enabled in $packageName, but ipset is either not installed or installed ipset does not support 'hash:net' type";;
112+ errorNoDnsmasqNftset)
113+ r="dnsmasq nft set support is enabled in $packageName, but dnsmasq is either not installed or installed dnsmasq does not support nft set";;
114+ errorNoNft) r="dnsmasq nft sets support is enabled in $packageName, but nft is not installed";;
115+ errorMkdirFail) r="Unable to create directory for";;
116+ errorNoWanGateway) r="The ${serviceName} service failed to discover WAN gateway!";;
117+ errorOutputDirCreate) r="failed to create directory for %s file";;
118+ errorOutputFileCreate) r="failed to create $outputFile file";;
119+ errorFailDNSReload) r="failed to restart/reload DNS resolver";;
120+ errorSharedMemory) r="failed to access shared memory";;
121+ errorSorting) r="failed to sort data file";;
122+ errorOptimization) r="failed to optimize data file";;
123+ errorAllowListProcessing) r="failed to process allow-list";;
124+ errorDataFileFormatting) r="failed to format data file";;
125+ errorMovingDataFile) r="failed to move data file '${A_TMP}' to '${outputFile}'";;
126+ errorCreatingCompressedCache) r="failed to create compressed cache";;
127+ errorRemovingTempFiles) r="failed to remove temporary files";;
128+ errorRestoreCompressedCache) r="failed to unpack compressed cache";;
129+ errorRestoreCache) r="failed to move '$outputCache' to '$outputFile'";;
130+ errorOhSnap) r="failed to create block-list or restart DNS resolver";;
131+ errorStopping) r="failed to stop $serviceName";;
132+ errorDNSReload) r="failed to reload/restart DNS resolver";;
133+ errorDownloadingConfigUpdate) r="failed to download Config Update file";;
134+ errorDownloadingList) r="failed to download";;
135+ errorParsingConfigUpdate) r="failed to parse Config Update file";;
136+ errorParsingList) r="failed to parse";;
137+ errorNoSSLSupport) r="no HTTPS/SSL support on device";;
138+ errorCreatingDirectory) r="failed to create output/cache/gzip file directory";;
139+
140+ statusNoInstall) r="$serviceName is not installed or not found";;
141+ statusStopped) r="Stopped";;
142+ statusStarting) r="Starting";;
143+ statusRestarting) r="Restarting";;
144+ statusForceReloading) r="Force Reloading";;
145+ statusDownloading) r="Downloading";;
146+ statusProcessing) r="Processing";;
147+ statusError) r="Error";;
148+ statusWarning) r="Warning";;
149+ statusFail) r="Fail";;
150+ statusSuccess) r="Success";;
151+
152+ warningExternalDnsmasqConfig)
153+ r="use of external dnsmasq config file detected, please set 'dns' option to 'dnsmasq.conf'";;
154+ warningMissingRecommendedPackages) r="Some recommended packages are missing";;
144155 esac
145- printf "%b" "$_ret"
156+ echo "$r"
146157 }
147158
148159 output_ok() { output 1 "$_OK_"; output 2 "$__OK__\\n"; }
@@ -187,13 +198,15 @@ load_environment() {
187198 local validation_result="$1" quiet="$2"
188199
189200 if [ "$validation_result" != '0' ]; then
190- output "${_ERROR_}: $packageName config validation failed!\\n"
201+ json add error "errorConfigValidationFail"
202+ output "${_ERROR_}: $(get_text 'errorConfigValidationFail')!\\n"
191203 output "Please check if the '$packageConfigFile' contains correct values for config options.\\n"
192204 return 1
193205 fi
194206
195207 if [ "$enabled" -eq 0 ]; then
196- output "$packageName is currently disabled.\\n"
208+ json add error "errorServiceDisabled"
209+ output "${_ERROR_}: $(get_text 'errorServiceDisabled')!\\n"
197210 output "Run the following commands before starting service again:\\n"
198211 output "uci set ${packageName}.config.enabled='1'; uci commit $packageName;\\n"
199212 return 1
@@ -210,7 +223,8 @@ load_environment() {
210223 dnsmasq.conf) :;;
211224 *)
212225 if [ -z "$quiet" ]; then
213- output "$_WARNING_: use of external dnsmasq config file detected, please set 'dns' option to 'dnsmasq.conf'!\\n"
226+ json add warning "warningExternalDnsmasqConfig"
227+ output "${_WARNING_}: $(get_text 'warningExternalDnsmasqConfig')!\\n"
214228 fi
215229 ;;
216230 esac
@@ -230,13 +244,15 @@ load_environment() {
230244 dnsmasq.ipset)
231245 if dnsmasq -v 2>/dev/null | grep -q 'no-ipset' || ! dnsmasq -v 2>/dev/null | grep -q -w 'ipset'; then
232246 if [ -z "$quiet" ]; then
233- output "$_ERROR_: dnsmasq ipset support is enabled in $packageName, but dnsmasq is either not installed or installed dnsmasq does not support ipset!\\n"
247+ json add error "errorNoDnsmasqIpset"
248+ output "${_ERROR_}: $(get_text 'errorNoDnsmasqIpset')!\\n"
234249 fi
235250 dns='dnsmasq.servers'
236251 fi
237252 if ! ipset help hash:net; then
238253 if [ -z "$quiet" ]; then
239- output "$_ERROR_: dnsmasq ipset support is enabled in $packageName, but ipset is either not installed or installed ipset does not support 'hash:net' type!\\n"
254+ json add error "errorNoIpset"
255+ output "${_ERROR_}: $(get_text 'errorNoIpset')!\\n"
240256 fi
241257 dns='dnsmasq.servers'
242258 fi
@@ -244,13 +260,15 @@ load_environment() {
244260 dnsmasq.nftset)
245261 if dnsmasq -v 2>/dev/null | grep -q 'no-nftset' || ! dnsmasq -v 2>/dev/null | grep -q -w 'nftset'; then
246262 if [ -z "$quiet" ]; then
247- output "$_ERROR_: dnsmasq nft sets support is enabled in $packageName, but dnsmasq is either not installed or installed dnsmasq does not support nft sets!\\n"
263+ json add error "errorNoDnsmasqNftset"
264+ output "${_ERROR_}: $(get_text 'errorNoDnsmasqNftset')!\\n"
248265 fi
249266 dns='dnsmasq.servers'
250267 fi
251268 if [ -z "$nft" ]; then
252269 if [ -z "$quiet" ]; then
253- output "$_ERROR_: dnsmasq nft sets support is enabled in $packageName, but nft is not installed!\\n"
270+ json add error "errorNoNft"
271+ output "${_ERROR_}: $(get_text 'errorNoNft')!\\n"
254272 fi
255273 dns='dnsmasq.servers'
256274 fi
@@ -335,8 +353,8 @@ load_environment() {
335353
336354 for i in "$outputFile" "$outputCache" "$outputGzip"; do
337355 if ! mkdir -p "$(dirname "$i")"; then
338- output "$_ERROR_: Unable to create directory for $i!\\n"
339- json add error "errorOutputFileCreate"
356+ json add error "errorOutputDirCreate" "$i"
357+ output "${_ERROR_}: $(get_text 'errorMkdirFail' "$i")!\\n"
340358 fi
341359 done
342360
@@ -352,7 +370,8 @@ load_environment() {
352370 is_present '/usr/libexec/sed-gnu' || s="$s sed"
353371 is_present '/usr/libexec/sort-coreutils' || s="$s coreutils-sort"
354372 if [ -z "$quiet" ]; then
355- output "$_WARNING_: Some recommended packages are missing, install them by running:\\n"
373+ json add warning "errorOutputFileCreate" "${i}"
374+ output "${_WARNING_}: $(get_text 'warningMissingRecommendedPackages'), install them by running:\\n"
356375 output "$s;\\n"
357376 fi
358377 fi
@@ -390,7 +409,8 @@ load_environment() {
390409 cache 'test_gzip' && return 0
391410 network_flush_cache; network_find_wan wan_if; network_get_gateway wan_gw "$wan_if";
392411 [ -n "$wan_gw" ] && return 0
393- output "$_ERROR_: $serviceName failed to discover WAN gateway.\\n"; return 1;
412+ json add error "errorNoWanGateway"
413+ output "${_ERROR_}: $(get_text 'errorNoWanGateway')!\\n"; return 1;
394414 }
395415
396416 resolver() {
@@ -424,7 +444,7 @@ dns() {
424444 if [ ! -s "$outputFile" ]; then
425445 json set status "statusFail"
426446 json add error "errorOutputFileCreate"
427- output "$_ERROR_: $(get_error_text 'errorOutputFileCreate')!\\n"
447+ output "${_ERROR_}: $(get_text 'errorOutputFileCreate')!\\n"
428448 return 1
429449 fi
430450
@@ -473,7 +493,7 @@ dns() {
473493 output_fail
474494 json set status "statusFail"
475495 json add error "errorDNSReload"
476- output "$_ERROR_: $(get_error_text 'errorDNSReload')!\\n"
496+ output "${_ERROR_}: $(get_text 'errorDNSReload')!\\n"
477497 return 1
478498 fi
479499 ;;
@@ -518,6 +538,9 @@ dns() {
518538 json() {
519539 # shellcheck disable=SC2034
520540 local action="$1" param="$2" value="$3"
541+ shift 3
542+# shellcheck disable=SC2124
543+ local extras="$@" line
521544 local status message error stats
522545 local reload restart curReload curRestart ret i
523546 if [ -s "$jsonFile" ]; then
@@ -549,10 +572,8 @@ json() {
549572 esac
550573 ;;
551574 add)
552- if [ -n "$(eval echo "\$$param")" ]; then
553- value="$(eval echo "\$$param") ${value}"
554- fi
555- eval "$param"='${value}'
575+ line="$(eval echo "\$$param")"
576+ eval "$param"='${line:+$line }${value}${extras:+|$extras}'
556577 ;;
557578 del)
558579 case "$param" in
@@ -573,7 +594,7 @@ json() {
573594 restart="$compressed_cache $force_dns $led $force_dns_port"
574595 ;;
575596 *)
576- eval "$param"='$value';;
597+ eval "$param"='${value}${extras:+|$extras}';;
577598 esac
578599 ;;
579600 esac
@@ -678,7 +699,7 @@ process_url() {
678699 download_dnsmasq_file() {
679700 local hf allow_filter j=0 R_TMP
680701
681- json set message "$(get_status_text "statusDownloading")..."
702+ json set message "$(get_text "statusDownloading")..."
682703 json set status "statusDownloading"
683704
684705 rm -f "$A_TMP" "$B_TMP" "$outputFile" "$outputCache" "$outputGzip"
@@ -714,7 +735,7 @@ download_dnsmasq_file() {
714735 download_lists() {
715736 local hf allow_filter j=0 R_TMP
716737
717- json set message "$(get_status_text "statusDownloading")..."
738+ json set message "$(get_text "statusDownloading")..."
718739 json set status "statusDownloading"
719740
720741 rm -f "$A_TMP" "$B_TMP" "$outputFile" "$outputCache" "$outputGzip"
@@ -775,7 +796,8 @@ $(cat $A_TMP)"
775796
776797 output 1 'Processing downloads '
777798 output 2 'Sorting combined list '
778- json set message "$(get_status_text "statusProcessing"): sorting combined list"
799+ json set status "statusProcessing"
800+ json set message "$(get_text "statusProcessing"): sorting combined list"
779801 if [ "$allow_non_ascii" -gt 0 ]; then
780802 if sort -u "$B_TMP" > "$A_TMP"; then
781803 output_ok
@@ -799,7 +821,7 @@ $(cat $A_TMP)"
799821 [ "$dns" = 'unbound.adb_list' ]; then
800822 # TLD optimization written by Dirk Brenken (dev@brenken.org)
801823 output 2 'Optimizing combined list '
802- json set message "$(get_status_text "statusProcessing"): optimizing combined list"
824+ json set message "$(get_text "statusProcessing"): optimizing combined list"
803825 # sed -E 'G;:t;s/(.*)(\.)(.*)(\n)(.*)/\1\4\5\2\3/;tt;s/(.*)\n(\.)(.*)/\3\2\1/' is actually slower than command below
804826 if $awk -F "." '{for(f=NF;f>1;f--)printf "%s.",$f;print $1}' "$A_TMP" > "$B_TMP"; then
805827 if sort "$B_TMP" > "$A_TMP"; then
@@ -835,7 +857,7 @@ $(cat $A_TMP)"
835857 fi
836858
837859 output 2 'Allowing domains '
838- json set message "$(get_status_text "statusProcessing"): allowing domains"
860+ json set message "$(get_text "statusProcessing"): allowing domains"
839861 if sed -i -E "$allow_filter" "$B_TMP"; then
840862 output_ok
841863 else
@@ -844,7 +866,7 @@ $(cat $A_TMP)"
844866 fi
845867
846868 output 2 'Formatting merged file '
847- json set message "$(get_status_text "statusProcessing"): formatting merged file"
869+ json set message "$(get_text "statusProcessing"): formatting merged file"
848870 if [ -z "$outputFilterIPv6" ]; then
849871 if sed "$outputFilter" "$B_TMP" > "$A_TMP"; then
850872 output_ok
@@ -869,27 +891,27 @@ $(cat $A_TMP)"
869891 case "$dns" in
870892 dnsmasq.addnhosts)
871893 output 2 'Creating dnsmasq addnhosts file '
872- json set message "$(get_status_text "statusProcessing"): creating dnsmasq addnhosts file"
894+ json set message "$(get_text "statusProcessing"): creating dnsmasq addnhosts file"
873895 ;;
874896 dnsmasq.conf)
875897 output 2 'Creating dnsmasq config file '
876- json set message "$(get_status_text "statusProcessing"): creating dnsmasq config file"
898+ json set message "$(get_text "statusProcessing"): creating dnsmasq config file"
877899 ;;
878900 dnsmasq.ipset)
879901 output 2 'Creating dnsmasq ipset file '
880- json set message "$(get_status_text "statusProcessing"): creating dnsmasq ipset file"
902+ json set message "$(get_text "statusProcessing"): creating dnsmasq ipset file"
881903 ;;
882904 dnsmasq.nftset)
883905 output 2 'Creating dnsmasq nft set file '
884- json set message "$(get_status_text "statusProcessing"): creating dnsmasq nft set file"
906+ json set message "$(get_text "statusProcessing"): creating dnsmasq nft set file"
885907 ;;
886908 dnsmasq.servers)
887909 output 2 'Creating dnsmasq servers file '
888- json set message "$(get_status_text "statusProcessing"): creating dnsmasq servers file"
910+ json set message "$(get_text "statusProcessing"): creating dnsmasq servers file"
889911 ;;
890912 unbound.adb_list)
891913 output 2 'Creating Unbound adb_list file '
892- json set message "$(get_status_text "statusProcessing"): creating Unbound adb_list file"
914+ json set message "$(get_text "statusProcessing"): creating Unbound adb_list file"
893915 ;;
894916 esac
895917
@@ -901,7 +923,7 @@ $(cat $A_TMP)"
901923 fi
902924 if [ "$compressed_cache" -gt 0 ]; then
903925 output 2 'Creating compressed cache '
904- json set message "$(get_status_text "statusProcessing"): creating compressed cache"
926+ json set message "$(get_text "statusProcessing"): creating compressed cache"
905927 if cache 'create_gzip'; then
906928 output_ok
907929 else
@@ -912,7 +934,7 @@ $(cat $A_TMP)"
912934 rm -f "$outputGzip"
913935 fi
914936 output 2 'Removing temporary files '
915- json set message "$(get_status_text "statusProcessing"): removing temporary files"
937+ json set message "$(get_text "statusProcessing"): removing temporary files"
916938 rm -f "/tmp/${packageName}_tmp.*" "$A_TMP" "$B_TMP" "$outputCache" || j=1
917939 if [ $j -eq 0 ]; then
918940 output_ok
@@ -1183,7 +1205,7 @@ adb_start() {
11831205 else
11841206 output_failn
11851207 json add error "errorRestoreCompressedCache"
1186- output "$_ERROR_: $(get_error_text 'errorRestoreCompressedCache')!\\n"
1208+ output "${_ERROR_}: $(get_text 'errorRestoreCompressedCache')!\\n"
11871209 action='download'
11881210 fi
11891211 fi
@@ -1196,7 +1218,7 @@ adb_start() {
11961218 else
11971219 output_failn
11981220 json add error "errorRestoreCache"
1199- output "$_ERROR_: $(get_error_text 'errorRestoreCache')!\\n"
1221+ output "${_ERROR_}: $(get_text 'errorRestoreCache')!\\n"
12001222 action='download'
12011223 fi
12021224 fi
@@ -1342,7 +1364,7 @@ adb_status() {
13421364 if [ "$status" = "statusSuccess" ]; then
13431365 output "$stats "; output_okn;
13441366 else
1345- [ -n "$status" ] && status="$(get_status_text "$status")"
1367+ [ -n "$status" ] && status="$(get_text "$status")"
13461368 if [ -n "$status" ] && [ -n "$message" ]; then
13471369 status="${status}: $message"
13481370 fi
@@ -1354,9 +1376,9 @@ adb_status() {
13541376 c="${c%|*}"
13551377 case "$c" in
13561378 errorDownloadingList|errorParsingList)
1357- output "$_ERROR_: $(get_error_text "$c") $url!\\n";;
1379+ output "${_ERROR_}: $(get_text "$c") $url!\\n";;
13581380 *)
1359- output "$_ERROR_: $(get_error_text "$c")!\\n";;
1381+ output "${_ERROR_}: $(get_text "$c")!\\n";;
13601382 esac
13611383 n=$((n+1))
13621384 done
@@ -1382,7 +1404,7 @@ adb_stop() {
13821404 output 0 "$__FAIL__\\n"; output_fail;
13831405 json set status "statusFail"
13841406 json add error "errorStopping"
1385- output "$_ERROR_: $(get_error_text 'errorStopping')!\\n"
1407+ output "${_ERROR_}: $(get_text 'errorStopping')!\\n"
13861408 fi
13871409 fi
13881410 }
Show on old repository browser