Allow to define LDAP server

This commit is contained in:
Jeremy Gardais 2021-11-19 14:19:57 +01:00
parent aac9641c04
commit 2be03f6701
Signed by: jegardai
GPG Key ID: E759BAA22501AF32
1 changed files with 19 additions and 2 deletions

View File

@ -18,6 +18,7 @@ export DEBUG
# Default values for some vars # Default values for some vars
readonly LDAP_GROUP_BASE_DEFAULT="ou=grouper,dc=univ-rennes1,dc=fr" readonly LDAP_GROUP_BASE_DEFAULT="ou=grouper,dc=univ-rennes1,dc=fr"
readonly LDAP_SERVER_DEFAULT="ldap://ldap.univ-rennes1.fr"
## Colors ## Colors
readonly PURPLE='\033[1;35m' readonly PURPLE='\033[1;35m'
@ -28,7 +29,7 @@ readonly COLOR_DEBUG="${PURPLE}"
usage() { # {{{ usage() { # {{{
cat <<- EOF cat <<- EOF
usage: $PROGNAME [-b|-d|-g|-h] usage: $PROGNAME [-b|-d|-g|-h|-s]
Create homedir for members of the given LDAP group. Create homedir for members of the given LDAP group.
@ -51,6 +52,9 @@ OPTIONS:
-h,--help -h,--help
Print this help message. Print this help message.
-s,--server ldap://ldap.domain.tld
LDAP url to use for ldapsearch request (default: ${LDAP_SERVER_DEFAULT}).
EOF EOF
} }
@ -90,6 +94,12 @@ define_vars() { # {{{
ldap_group_base="${LDAP_GROUP_BASE_DEFAULT}" ldap_group_base="${LDAP_GROUP_BASE_DEFAULT}"
fi fi
# }}} # }}}
# If ldap_server wasn't defined (argument) {{{
if [ -z "${ldap_server}" ]; then
## Use default value
ldap_server="${LDAP_SERVER_DEFAULT}"
fi
# }}}
} }
# }}} # }}}
@ -135,7 +145,8 @@ main() { # {{{
## Information message ## Information message
debug_message "Search for members in ${ldap_group_cn},${ldap_group_base} group." debug_message "Search for members in ${RED}${ldap_group_cn},${ldap_group_base}${COLOR_DEBUG} group \
on ${RED}${ldap_server}${COLOR_DEBUG} LDAP server."
} }
# }}} # }}}
@ -182,6 +193,12 @@ if [ ! "${NBARGS}" -eq "0" ]; then
## Exit after help informations ## Exit after help informations
exit 0 exit 0
;; ;;
-s|--server) ## Define ldap_server
## Move to the next argument
shift
## Define var
readonly ldap_server="${1}"
;;
* ) ## unknow option * ) ## unknow option
printf '%b\n' "${RED}Invalid option: ${1}${RESET}" printf '%b\n' "${RED}Invalid option: ${1}${RESET}"
printf '%b\n' "---" printf '%b\n' "---"