]> Frank Brehm's Git Trees - pixelpark/pp-admin-tools.git/commitdiff
Adding bin/get-ldap-membership
authorFrank Brehm <frank.brehm@pixelpark.com>
Fri, 15 Oct 2021 08:49:11 +0000 (10:49 +0200)
committerFrank Brehm <frank.brehm@pixelpark.com>
Fri, 15 Oct 2021 08:49:11 +0000 (10:49 +0200)
bin/get-ldap-membership [new file with mode: 0755]

diff --git a/bin/get-ldap-membership b/bin/get-ldap-membership
new file mode 100755 (executable)
index 0000000..de6de3b
--- /dev/null
@@ -0,0 +1,125 @@
+#!/bin/bash
+
+set -e
+set -u
+
+BASE_NAME="$( basename ${0} )"
+MY_REAL_NAME=$( readlink -f $0 )
+BIN_DIR=$( dirname "${MY_REAL_NAME}" )
+BASE_DIR=$( dirname "${BIN_DIR}" )
+LIB_DIR="${BASE_DIR}/lib"
+CONF_DIR="${BASE_DIR}/etc"
+
+if [[ -f "${LIB_DIR}/functions.rc" ]] ; then
+    . "${LIB_DIR}/functions.rc"
+else
+    echo "Bash resource file '${LIB_DIR}/functions.rc' not found" >&2
+    exit 5
+fi
+
+declare -a SEARCH_IDS=()
+
+detect_color
+
+DESCRIPTION=$( cat <<-EOF
+       Get all LDAP groups, where the user with the given DN uid or mail address is a member of.
+
+       EOF
+)
+
+#------------------------------------------------------------------------------
+get_options() {
+
+    local tmp=
+    local base_dir=
+
+    set +e
+    tmp=$( getopt -o ${LDAP_STD_OPTS_SHORT}${STD_SHORT_OPTIONS} \
+                    --long ${LDAP_STD_OPTS_LONG},${STD_LONG_OPTIONS} \
+                    -n "${BASE_NAME}" -- "$@" )
+    if [[ $? != 0 ]] ; then
+        echo "" >&2
+        usage >&2
+        exit 1
+    fi
+    set -e
+
+    # Note the quotes around `$TEMP': they are essential!
+    eval set -- "${tmp}"
+    eval_common_options "$@"
+    if [[ "${DEBUG}" == 'y' ]] ; then
+        declare -p REMAINING_OPTS
+        declare -p REMAINING_ARGS
+    fi
+
+    eval_ldap_options "${REMAINING_OPTS[@]}" "${REMAINING_ARGS[@]}"
+
+    if [[ "${DEBUG}" == 'y' ]] ; then
+        declare -p REMAINING_OPTS
+        declare -p REMAINING_ARGS
+    fi
+
+    if [[ "${#REMAINING_OPTS[@]}" -gt 0 ]] ; then
+        error "Unknown options: ${REMAINING_OPTS[*]}"
+        echo >&2
+        usage >&2
+        exit 2
+    fi
+
+    if [[ "${#REMAINING_ARGS[@]}" == "0" ]] ; then
+        error "No user given to retrieve."
+        echo >&2
+        usage >&2
+        exit 2
+    fi
+
+    local i=0
+    local token=
+    for token in "${REMAINING_ARGS[@]}" ; do
+        if [[ "$i" == 0 ]]; then
+            i=1
+            continue
+        fi
+        SEARCH_IDS+=(${token})
+        i=$(( $i + 1 ))
+    done
+
+    if [[ "${DEBUG}" == 'y' ]] ; then
+        declare -p SEARCH_IDS
+    fi
+
+}
+
+#------------------------------------------------------------------------------
+usage() {
+    cat <<-EOF
+       Usage: ${BASE_NAME} [Common Options] [LDAP Options] <ID> [<ID> ...]
+              ${BASE_NAME} [-h|--help]
+              ${BASE_NAME} [-V|--version]
+
+           Mandatory Parameter(s):
+               ID: The DN, UID or mail address of the user to search.
+
+           LDAP Options:
+       EOF
+
+    echo "${LDAP_USAGE_MSG}"
+    echo
+    echo "    Common Options:"
+    echo "${STD_USAGE_MSG}"
+
+}
+
+#------------------------------------------------------------------------------
+main() {
+
+    get_options "$@"
+
+
+}
+
+main "$@"
+
+exit 0
+
+# vim: et list