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:
TheHackdes 2026-05-04 20:41:53 +02:00
parent debf81e5a9
commit ea960e5320
3 changed files with 47 additions and 23 deletions

View file

@ -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
View 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