From be99fd38e8f26d89202cca6904a29a720d927253 Mon Sep 17 00:00:00 2001 From: Gardouille Date: Wed, 29 Sep 2021 09:03:47 +0200 Subject: [PATCH] Check if vars are empty --- github/check.adguard.update | 38 +++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/github/check.adguard.update b/github/check.adguard.update index 5bf1f43..bc6a937 100755 --- a/github/check.adguard.update +++ b/github/check.adguard.update @@ -85,6 +85,33 @@ error_message() { # {{{ exit "${local_error_code:=66}" } # }}} +is_var_empty() { # {{{ + + ## Return False by default + return_var_empty="1" + ## Total number of variables to test + local_total_var="${#}" + + loop_count_var_empty="0" + + ## While it remains a variable to test + while [ "${local_total_var}" -gt "${loop_count_var_empty}" ]; do + debug_message "is_var_empty − \ +Test var: ${1}." + ### Test if this is empty and set return value to True + [ -z "${1}" ] && return_var_empty="0" + + ### Increase the number of tested variables + loop_count_var_empty=$((loop_count_var_empty+1)) + + ### Shift to the next variable + shift + done + + return "${return_var_empty}" + +} +# }}} define_vars() { # {{{ ## If adguard_bin wasn't defined (argument,...) {{{ @@ -116,6 +143,17 @@ main() { # {{{ ## Define all vars according to selected options define_vars + ## Test adguard_current_version + ## AND exit with error 2 + is_var_empty "${adguard_current_version}" \ + && error_message "adguard_current_version seems empty (${adguard_current_version})." 2 + + ## Test adguard_new_version + ## AND exit without error + is_var_empty "${adguard_new_version}" \ + && debug_message "adguard_new_version seems empty (${adguard_new_version}), exit without error." \ + && exit 0 + ## Check if the current version is the last one {{{ if [ "${adguard_current_version}" != "${adguard_new_version}" ]; then debug_message "Test AdGuard Home version − \