From: Frank Brehm Date: Tue, 2 Nov 2021 16:01:02 +0000 (+0100) Subject: Adding additional groups in after-migration.sh X-Git-Url: https://git.uhu-banane.org/?a=commitdiff_plain;h=408de8b503a6eb43d7116a33a98293de437447b6;p=pixelpark%2Fldap-migration.git Adding additional groups in after-migration.sh --- diff --git a/after-migration.sh b/after-migration.sh index c816441..553c38b 100755 --- a/after-migration.sh +++ b/after-migration.sh @@ -8,7 +8,7 @@ DEBUG="n" QUIET='n' SIMULATE='n' -VERSION="2.3" +VERSION="3.3" # console colors: RED="" @@ -743,6 +743,63 @@ update_all_public_sshkeys() { } +#------------------------------------------------ +add_additional_group() { + + local ldif_file="$1" + local dn= + local cmd= + local value= + + empty_line + + dn=$( cat "${ldif_file}" | grep -i "^dn:" | sed -e 's/^dn:[ ][ ]*//i' ) + debug "Checking for group '${CYAN}${dn}${NORMAL}' ..." + cmd="ldapsearch -x -LLL -o ldif-wrap=no -H '${LDAP_URL}' " + cmd+="-b \"${dn}\" -x -D \"${LDAP_USR}\" -y \"${LDAP_PWD_FILE}\" " + cmd+="\"(objectClass=*)\" dn | grep -i '^dn:'" + # debug "Executing: ${cmd}" + value=$( eval ${cmd} || true ) + + if [[ -n "${value}" ]] ; then + info "Group '${CYAN}${dn}${NORMAL}' is already existing." + return 0 + fi + + info "Creating group '${CYAN}${dn}${NORMAL}' ..." + + cmd="ldapadd -H \"${LDAP_URL}\" -x -D \"${LDAP_USR}\" -y \"${LDAP_PWD_FILE}\"" + cmd+=" -f \"${ldif_file}\"" + # debug "Executing: ${cmd}" + if [[ "${SIMULATE}" != "y" ]] ; then + eval $cmd + fi + debug "Done." + +} + +#------------------------------------------------ +adding_additional_groups() { + + empty_line + draw_line + info "Adding additional groups ..." + + local ldif_dir="etc/additional_groups" + + if [[ ! -d "${ldif_dir}" ]] ; then + error "Directory for additional group definitions '${RED}${ldif_dir}${NORMAL}' not found." + exit 8 + fi + + local ldif_file= + + for ldif_file in "${ldif_dir}"/*.ldif ; do + add_additional_group "${ldif_file}" + done + +} + #------------------------------------------------ main() { @@ -757,6 +814,7 @@ main() { update_passwords update_all_mailhosts update_all_public_sshkeys + adding_additional_groups empty_line info "Finished."