From c4b15327bc6276ebba833016baa728979860b6fb Mon Sep 17 00:00:00 2001 From: Stan Grishin Date: Mon, 8 Mar 2021 10:34:38 +0000 Subject: [PATCH] vpn-policy-routing: better processing of custom user files Signed-off-by: Stan Grishin --- net/vpn-policy-routing/Makefile | 2 +- .../files/vpn-policy-routing.init | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/net/vpn-policy-routing/Makefile b/net/vpn-policy-routing/Makefile index 609674b03..f5ac83338 100644 --- a/net/vpn-policy-routing/Makefile +++ b/net/vpn-policy-routing/Makefile @@ -5,7 +5,7 @@ include $(TOPDIR)/rules.mk PKG_NAME:=vpn-policy-routing PKG_VERSION:=0.3.2 -PKG_RELEASE:=18 +PKG_RELEASE:=20 PKG_LICENSE:=GPL-3.0-or-later PKG_MAINTAINER:=Stan Grishin diff --git a/net/vpn-policy-routing/files/vpn-policy-routing.init b/net/vpn-policy-routing/files/vpn-policy-routing.init index 7bd82e6f5..095069823 100755 --- a/net/vpn-policy-routing/files/vpn-policy-routing.init +++ b/net/vpn-policy-routing/files/vpn-policy-routing.init @@ -89,6 +89,7 @@ output() { printf "%b" "$msg" >> "$sharedMemoryOutput" fi } +is_present() { command -v "$1" >/dev/null 2>&1; } is_installed() { [ -s "/usr/lib/opkg/info/${1}.control" ]; } is_variant_installed() { [ "$(echo /usr/lib/opkg/info/"${1}"*.control)" != "/usr/lib/opkg/info/${1}*.control" ]; } @@ -867,22 +868,26 @@ process_user_file(){ config_get path "$1" 'path' [ "$enabled" -gt 0 ] || return 0 if [ ! -s "$path" ]; then - errorSummary="${errorSummary}${_ERROR_}: Custom user file '$path' not found or empty\\n" + errorSummary="${errorSummary}${_ERROR_}: Custom user file '$path' not found or empty!\\n" output_fail return 1 fi if ! $shellBin -n "$path"; then - errorSummary="${errorSummary}${_ERROR_}: Syntax error in custom user file '$path'\\n" + errorSummary="${errorSummary}${_ERROR_}: Syntax error in custom user file '$path'!\\n" output_fail return 1 fi + output 2 "Running $path " # shellcheck disable=SC1090 if ! . "$path"; then - errorSummary="${errorSummary}${_ERROR_}: Error running custom user file '$path'\\n" + errorSummary="${errorSummary}${_ERROR_}: Error running custom user file '$path'!\\n" + if grep -q -w 'curl' "$path" && ! is_present 'curl'; then + errorSummary="${errorSummary}${_ERROR_}: Use of 'curl' is detected in custom user file '$path', but 'curl' isn't installed!\\n" + errorSummary="${errorSummary}${_ERROR_}: If 'curl' is needed, install it with 'opkg update; opkg install curl;' command in CLI.\\n" + fi output_fail return 1 else - output 2 "Running $path " output_ok return 0 fi @@ -1174,7 +1179,7 @@ support() { } | tee -a /var/${packageName}-support if [ -n "$set_p" ]; then printf "%b" "Pasting to paste.ee... " - if is_installed 'curl' && is_variant_installed 'libopenssl' && is_installed 'ca-bundle'; then + if is_present 'curl' && is_variant_installed 'libopenssl' && is_installed 'ca-bundle'; then json_init; json_add_string "description" "${packageName}-support" json_add_array "sections"; json_add_object '0' json_add_string "name" "$(uci -q get system.@system[0].hostname)"