Compare new and old users list (if available)

This commit is contained in:
Jeremy Gardais 2021-11-29 15:13:40 +01:00
parent 6b130315dd
commit 71b0499341
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 52 additions and 0 deletions

View File

@ -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() { # {{{ main() { # {{{
## If ldapsearch command is not available {{{ ## If ldapsearch command is not available {{{
@ -313,6 +357,14 @@ main() { # {{{
get_ldap_user_list \ get_ldap_user_list \
|| error_message "Can't get the user list of ${ldap_group_cn} LDAP group. Please use --debug option." 4 || 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 ## Information message
debug_message "Create home directory in ${RED}${home_base}${COLOR_DEBUG}, \ debug_message "Create home directory in ${RED}${home_base}${COLOR_DEBUG}, \