addtogroups 894 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #!/bin/bash
  2. . /etc/ldap-utils.conf
  3. . /usr/local/lib/ldap-utils/funcs
  4. uid=$1
  5. if user_exists $uid; then
  6. true
  7. else
  8. echo "User $uid does not exist."
  9. exit 1
  10. fi
  11. group_ofnames="dn: cn=%GROUP%,$GROUPSDN
  12. changeType: modify
  13. add: member
  14. member: uid=%UID%,$PEOPLEDN"
  15. group_posix="dn: cn=%GROUP%,$GROUPSDN
  16. changeType: modify
  17. add: memberUid
  18. memberUid: %UID%"
  19. # remove uid ($1) from args so that only the list
  20. # of groups remains in $@
  21. shift
  22. # add user to each of the groups given
  23. for g in $@; do
  24. if group_exists $g ; then
  25. if group_is_posix $g; then
  26. user_is_posix $uid || { echo "User $uid is not a posixAccount, skipping posixGroup $g..." && continue; }
  27. group="$group_posix"
  28. else
  29. group="$group_ofnames"
  30. fi
  31. echo "$group" | sed \
  32. -e "s/%GROUP%/$g/" \
  33. -e "s/%UID%/$uid/" | ldapmodify $LDAPOPTS
  34. else
  35. echo "Group $g does not exist, skipping..."
  36. fi
  37. done