diff --git a/duplicati/create.homedir.sh b/duplicati/create.homedir.sh index 861d558..94aaa77 100755 --- a/duplicati/create.homedir.sh +++ b/duplicati/create.homedir.sh @@ -67,8 +67,8 @@ error_message() { # {{{ local_error_message="${1}" local_error_code="${2}" - ## Print message if DEBUG is enable (=0) - [ "${DEBUG}" -eq "0" ] && printf '%b\n' "ERROR − ${PROGNAME} : ${RED}${local_error_message}${RESET}" + ## Print error message + printf '%b\n' "ERROR − ${PROGNAME} : ${RED}${local_error_message}${RESET}" exit "${local_error_code:=66}" } @@ -77,21 +77,53 @@ define_vars() { # {{{ # If ldap_group_cn wasn't defined (argument) {{{ if [ -z "${ldap_group_cn}" ]; then - ## Display help message - usage - ## As ldap_group_cn is required, exit with message and error - error_message "Please enter a GROUP with -g|--group option" "1" + ## Keep it empty + ldap_group_cn="" fi # }}} } # }}} +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}" + +} +# }}} main() { # {{{ ## Define all vars define_vars + ## 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" + } # }}}