diff --git a/duplicati/create.homedir.sh b/duplicati/create.homedir.sh index 9722d52..2b69d4c 100755 --- a/duplicati/create.homedir.sh +++ b/duplicati/create.homedir.sh @@ -277,6 +277,50 @@ Error in ${RED}ldapsearch${COLOR_DEBUG} command for ${ldap_group_cn} LDAP group. } # }}} +is_file_present() { # {{{ + + local_file_present="${1}" + + ## File doesn't exist by default + return_is_file_present="1" + + ### Check if the file exists + # shellcheck disable=SC2086 + if find ${local_file_present} > /dev/null 2>&1; then + return_is_file_present="0" + debug_message "is_file_present − \ +The file ${RED}${local_file_present}${COLOR_DEBUG} exists." + else + return_is_file_present="1" + debug_message "is_file_present − \ +The file ${RED}${local_file_present}${COLOR_DEBUG} doesn't exist." + fi + + return "${return_is_file_present}" + +} +# }}} +is_file_similar() { # {{{ + + local_similar_file_one="${1}" + local_similar_file_two="${2}" + + ## Files aren't similar by default doesn't exist by default + return_is_file_similar="1" + + if diff --brief -- "${local_similar_file_one}" "${local_similar_file_two}" > /dev/null; then + debug_message "is_file_similar − \ +${local_similar_file_one} and ${local_similar_file_two} are ${RED}similar${COLOR_DEBUG}." + return_is_file_similar="0" + else + debug_message "is_file_similar − \ +${local_similar_file_one} and ${local_similar_file_two} are ${RED}NOT${COLOR_DEBUG} similar." + return_is_file_similar="1" + fi + + return "${return_is_file_similar}" +} +# }}} main() { # {{{ ## If ldapsearch command is not available {{{ @@ -313,6 +357,14 @@ main() { # {{{ get_ldap_user_list \ || error_message "Can't get the user list of ${ldap_group_cn} LDAP group. Please use --debug option." 4 ## }}} + ## If a previous list of users exists {{{ + ### If the two lists are the same + ### Exit + is_file_present "${ldap_previous_user_list_path}" \ + && is_file_similar "${ldap_user_list_path}" "${ldap_previous_user_list_path}" \ + && debug_message "main − No new user from previous run, no more actions required." \ + && exit 0 + ## }}} ## Information message debug_message "Create home directory in ${RED}${home_base}${COLOR_DEBUG}, \