feat(main.sh): add functionality to add users to a group
This commit introduces the ability to add one or more users to a group using the main script. The user is prompted to select this option from the menu, and if chosen, the action/add\_user\_to\_group.sh script is sourced to perform the operation. If an unrecognized choice is made, an error message is displayed and the script exits with a status of 1.
This commit is contained in:
parent
debf81e5a9
commit
ea960e5320
3 changed files with 47 additions and 23 deletions
|
|
@ -1,20 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
source ./sources/functions.sh
|
||||
|
||||
banner "Adding user in group"
|
||||
|
||||
sleep 1
|
||||
|
||||
log info "Search all users..."
|
||||
sleep 1
|
||||
SELECTED_USER=$(ldapsearch -x -LLL -H ldap://${LDAP_SERVER} -b "${LDAP_BASE_DN}" "(objectClass=inetOrgPerson)" dn | grep '^dn' | sed 's/dn: //g' | fzf --height=10 --reverse --cycle --prompt="❯ Choix : " -m)
|
||||
|
||||
if [ -z "$SELECTED_USER" ]; then
|
||||
log error "No user selected"
|
||||
else
|
||||
log success "User selected : "
|
||||
for i in $SELECTED_USER; do
|
||||
echo -e " - ${i}"
|
||||
done
|
||||
fi
|
||||
34
actions/add_user_to_group·sh
Executable file
34
actions/add_user_to_group·sh
Executable file
|
|
@ -0,0 +1,34 @@
|
|||
#!/bin/bash
|
||||
|
||||
source ./sources/functions.sh
|
||||
|
||||
banner "Adding user in group"
|
||||
sleep 1
|
||||
|
||||
log info "Search all users..."
|
||||
sleep 1
|
||||
|
||||
SELECTED_USER=$(ldapsearch -x -LLL -H ldap://${LDAP_SERVER} -b "${LDAP_BASE_DN}" "(objectClass=inetOrgPerson)" dn | grep '^dn' | sed 's/dn: //g' | fzf --height=10 --reverse --cycle --prompt="❯ Choix : " -m)
|
||||
|
||||
if [ -z "$SELECTED_USER" ]; then
|
||||
log error "No user selected"
|
||||
else
|
||||
log success "List of selected users :"
|
||||
for i in $SELECTED_USER; do
|
||||
log info "User : ${i}"
|
||||
done
|
||||
fi
|
||||
|
||||
SELECTED_GROUP=$(ldapsearch -x -LLL -H ldap://${LDAP_SERVER} -b "${LDAP_BASE_DN}" "(|(objectClass=groupOfNames)(objectClass=groupOfUniqueNames)(objectClass=posixGroup))" dn |
|
||||
grep '^dn' |
|
||||
sed 's/dn: //g' |
|
||||
fzf --height=10 --reverse --cycle --prompt="❯ Groupe : " -m)
|
||||
|
||||
if [ -z "$SELECTED_GROUP" ]; then
|
||||
log error "No group selected"
|
||||
else
|
||||
log success "List of selected groups :"
|
||||
for i in $SELECTED_GROUP; do
|
||||
log info "Group : ${i}"
|
||||
done
|
||||
fi
|
||||
16
main.sh
16
main.sh
|
|
@ -5,12 +5,10 @@ source ./sources/functions.sh
|
|||
banner "Manage OpenLDAP"
|
||||
|
||||
CHOIX=(
|
||||
"1. Ajouter un nouveau utilisateur"
|
||||
"2. Supprimer un utilisateur"
|
||||
"1. Ajouter un ou plusieurs utilisateurs a un groupe"
|
||||
)
|
||||
|
||||
select_option() {
|
||||
local choice
|
||||
choice=$(printf "%s\n" "${CHOIX[@]}" | fzf --height=4 --reverse --cycle --prompt="❯ Choix : " --layout=reverse)
|
||||
log info "Selection - ${choice}"
|
||||
}
|
||||
|
|
@ -18,3 +16,15 @@ select_option() {
|
|||
sleep 1.5
|
||||
|
||||
select_option
|
||||
|
||||
case $choice in
|
||||
"1. Ajouter un ou plusieurs utilisateurs a un groupe")
|
||||
log success "Ajouter un ou plusieurs utilisateurs a un groupe"
|
||||
sleep 1
|
||||
source ./actions/add_user_to_group·sh
|
||||
;;
|
||||
*)
|
||||
log error "Choice non reconnue"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue