#!/bin/bash . /etc/ldap-utils.conf . /usr/local/lib/ldap-utils/funcs uid=$1 if user_exists $uid; then true else echo "User $uid does not exist." exit 1 fi group_ofnames="dn: cn=%GROUP%,$GROUPSDN changeType: modify add: member member: uid=%UID%,$PEOPLEDN" group_posix="dn: cn=%GROUP%,$GROUPSDN changeType: modify add: memberUid memberUid: %UID%" # remove uid ($1) from args so that only the list # of groups remains in $@ shift # add user to each of the groups given for g in $@; do if group_exists $g ; then if group_is_posix $g; then user_is_posix $uid || { echo "User $uid is not a posixAccount, skipping posixGroup $g..." && continue; } group="$group_posix" else group="$group_ofnames" fi echo "$group" | sed \ -e "s/%GROUP%/$g/" \ -e "s/%UID%/$uid/" | ldapmodify $LDAPOPTS else echo "Group $g does not exist, skipping..." fi done