From 29e64cc35dca9e5979d1b54ce16512d2661e9640 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gardais=20J=C3=A9r=C3=A9my?= Date: Fri, 19 Nov 2021 14:48:41 +0100 Subject: [PATCH] Add is_var_empty_silent for sensitives variables --- duplicati/create.homedir.sh | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/duplicati/create.homedir.sh b/duplicati/create.homedir.sh index 1aa905d..5408f62 100755 --- a/duplicati/create.homedir.sh +++ b/duplicati/create.homedir.sh @@ -158,6 +158,31 @@ Test var: ${1}." return "${return_var_empty}" +} +# }}} +is_var_empty_silent() { # {{{ + + ## Return False by default + return_var_empty_silent="1" + ## Total number of variables to test + local_total_var="${#}" + + loop_count_var_empty_silent="0" + + ## While it remains a variable to test + while [ "${local_total_var}" -gt "${loop_count_var_empty_silent}" ]; do + ### Test if this is empty and set return value to True + [ -z "${1}" ] && return_var_empty_silent="0" + + ### Increase the number of tested variables + loop_count_var_empty_silent=$((loop_count_var_empty_silent+1)) + + ### Shift to the next variable + shift + done + + return "${return_var_empty_silent}" + } # }}} main() { # {{{ @@ -165,13 +190,20 @@ main() { # {{{ ## Define all vars define_vars - ## If ldap_group_cn is empty + ## If ldap_group_cn is empty {{{ ### Print help message ### AND exit with message and error is_var_empty "${ldap_group_cn}" \ && usage \ && error_message "Please enter a GROUP with -g|--group option." "1" - + ## }}} + ## If ldap_user or ldap_passwd is empty {{{ + ### Print help message + ### AND exit with message and error + is_var_empty_silent "${ldap_user}" "${ldap_passwd}" \ + && usage \ + && error_message "LDAP user or password is empty. Please verify your configuration or the --user-cmd|--passwd-cmd options." "2" + ## }}} ## Information message debug_message "Search for members in ${RED}${ldap_group_cn},${ldap_group_base}${COLOR_DEBUG} group \