From b45f28f78fda800c267eaa48855fea07c80d4fc7 Mon Sep 17 00:00:00 2001 From: Frank Brehm Date: Tue, 23 Feb 2021 12:20:06 +0100 Subject: [PATCH] Adding get-current-schema for retrieving current schema on target cluster --- get-current-schema | 82 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) create mode 100755 get-current-schema diff --git a/get-current-schema b/get-current-schema new file mode 100755 index 0000000..5af1604 --- /dev/null +++ b/get-current-schema @@ -0,0 +1,82 @@ +#!/bin/bash + +set -e +set -u + +PW_FILE="${HOME}/.private/dirsrv-dpx-admin-pwd-wonl.txt" +URL="ldaps://dev-ldap2.pixelpark.com" +BASE_DN="cn=schema" +BIND_DN="cn=admin" +SCHEMA_FILE="schema-complete.ldif" +ATTR_TYPES_FILE="attributeTypes.txt" +OBJ_CLASSES_FILE="objectClasses.txt" + +SCHEMA_DIR="$( dirname "$0" )/schema" +if [[ ! -d "${SCHEMA_DIR}" ]] ; then + echo "Directory '${SCHEMA_DIR}' does not exists." >&2 + exit 3 +fi + +if [[ ! -f "${PW_FILE}" ]] ; then + echo "Password file '${PW_FILE}' does not exists." >&2 + exit 4 +fi + +cd "${SCHEMA_DIR}" + +i=0 + +TARGET_DIR="target-$(date +'%Y-%m-%d').00" + +while [[ -d "${TARGET_DIR}" ]] ; do + i=$(( $i + 1 )) + TARGET_DIR="target-$(date +'%Y-%m-%d').$( printf "%02d" "$i" )" +done + +mkdir -pv "${TARGET_DIR}" + +cd "${TARGET_DIR}" + +printf "Bin jetzt in: " +pwd +echo + +cmd="ldapsearch -H \"${URL}\" -D \"${BIND_DN}\" -y \"${PW_FILE}\" x -b \"${BASE_DN}\" -s sub -LLL -o ldif-wrap=no 'objectclass=*' '+' '*' > \"${SCHEMA_FILE}\"" +echo "Executing: ${cmd}" +eval ${cmd} + +# cat schema-complete.ldif | grep -i '^objectclasses:' | sed -e 's/.*NAME //' -e "s/^'\([^']*\)'.*/\\1/" | sort -i >objectClasses.txt +echo +echo "Getting all ObjectClasses ..." +cmd="cat \"${SCHEMA_FILE}\"" +cmd+=" | grep -i '^objectclasses:'" +cmd+=" | sed -e 's/.*NAME //'" +cmd+=" -e \"s/^'\\([^']*\\)'.*/\\\\1/\"" +cmd+=" | sort -i" +cmd+=" > \"${OBJ_CLASSES_FILE}\"" +echo "Executing: ${cmd}" +eval ${cmd} + +echo +echo "Getting all AttributeTypes ..." +cmd="cat \"${SCHEMA_FILE}\"" +cmd+=" | grep -i '^attributeTypes:'" +cmd+=" | sed -e 's/.*NAME *//'" +cmd+=" -e \"s/^(\\([^)]*\\)).*/\\1/\"" +cmd+=" -e 's/ *DESC .*//'" +cmd+=" -e 's/ *SYNTAX .*//'" +cmd+=" -e 's/ *EQUALITY .*//'" +cmd+=" -e 's/ *SUP .*//'" +cmd+=" -e 's/^ *//'" +cmd+=" -e \"s/'//g\"" +cmd+=" | tr '[:space:]' '\n'" +cmd+=" | grep -v '^ *$'" +cmd+=" | sort -i" +cmd+=" > \"${ATTR_TYPES_FILE}\"" +echo "Executing: ${cmd}" +eval ${cmd} + +echo +echo "Finished!" + +# vim: ts=4 -- 2.39.5