Allow to define LDAP group_base

This commit is contained in:
Jeremy Gardais 2021-11-19 14:13:23 +01:00
parent 6c134757cf
commit aac9641c04
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 22 additions and 3 deletions

View File

@ -17,7 +17,7 @@ readonly NBARGS="${#}"
export DEBUG export DEBUG
# Default values for some vars # Default values for some vars
#readonly MY_VAR_XY_DEFAULT="666" readonly LDAP_GROUP_BASE_DEFAULT="ou=grouper,dc=univ-rennes1,dc=fr"
## Colors ## Colors
readonly PURPLE='\033[1;35m' readonly PURPLE='\033[1;35m'
@ -28,15 +28,18 @@ readonly COLOR_DEBUG="${PURPLE}"
usage() { # {{{ usage() { # {{{
cat <<- EOF cat <<- EOF
usage: $PROGNAME [-d|-g|-h] usage: $PROGNAME [-b|-d|-g|-h]
Create homedir for members of the given LDAP group Create homedir for members of the given LDAP group.
EXAMPLES: EXAMPLES:
- Create homedir for members of "ldap:group:my_group" - Create homedir for members of "ldap:group:my_group"
${PROGNAME} --group "ldap:group:my_group" ${PROGNAME} --group "ldap:group:my_group"
OPTIONS: OPTIONS:
-b,--base LDAP_BASE
Set different LDAP base (default: ${LDAP_GROUP_BASE_DEFAULT}).
-d,--debug -d,--debug
Enable debug messages. Enable debug messages.
@ -81,6 +84,12 @@ define_vars() { # {{{
ldap_group_cn="" ldap_group_cn=""
fi fi
# }}} # }}}
# If ldap_group_base wasn't defined (argument) {{{
if [ -z "${ldap_group_base}" ]; then
## Use default value
ldap_group_base="${LDAP_GROUP_BASE_DEFAULT}"
fi
# }}}
} }
# }}} # }}}
@ -124,6 +133,10 @@ main() { # {{{
&& usage \ && usage \
&& error_message "Please enter a GROUP with -g|--group option." "1" && error_message "Please enter a GROUP with -g|--group option." "1"
## Information message
debug_message "Search for members in ${ldap_group_cn},${ldap_group_base} group."
} }
# }}} # }}}
@ -149,6 +162,12 @@ if [ ! "${NBARGS}" -eq "0" ]; then
while printf -- '%s' "${1}" | grep -q -E -- "^-+"; do while printf -- '%s' "${1}" | grep -q -E -- "^-+"; do
case "${1}" in case "${1}" in
-b|--base ) ## Define ldap_group_base
## Move to the next argument
shift
## Define var
readonly ldap_group_base="${1}"
;;
-d|--debug ) ## debug -d|--debug ) ## debug
DEBUG=0 DEBUG=0
;; ;;