]> Frank Brehm's Git Trees - pixelpark/ldap-migration.git/commitdiff
Adding additional groups in after-migration.sh
authorFrank Brehm <frank.brehm@pixelpark.com>
Tue, 2 Nov 2021 16:01:02 +0000 (17:01 +0100)
committerFrank Brehm <frank.brehm@pixelpark.com>
Tue, 2 Nov 2021 16:01:02 +0000 (17:01 +0100)
after-migration.sh

index c816441cc590128dff60c66da5075066a7f03d12..553c38b181b5a5102bf566ad094e76b7e8365f6f 100755 (executable)
@@ -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."