person2posix 1021 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. #!/bin/bash
  2. . .env
  3. . 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. user="dn: uid=%UID%,$PEOPLEDN
  12. changeType: modify
  13. add: objectClass
  14. objectClass: posixAccount
  15. -
  16. add: uidNumber
  17. uidNumber: %NUMBER%
  18. -
  19. add: gidNumber
  20. gidNumber: %NUMBER%
  21. -
  22. add: homeDirectory
  23. homeDirectory: /home/%UID%
  24. -
  25. add: loginShell
  26. loginShell: /bin/bash
  27. -
  28. add: objectClass
  29. objectClass: shadowAccount
  30. -
  31. add: objectClass
  32. objectClass: ldapPublicKey"
  33. group="dn: cn=%UID%,$GROUPSDN
  34. objectClass: top
  35. objectClass: posixGroup
  36. cn: %UID%
  37. gidNumber: %NUMBER%
  38. memberUid: %UID%"
  39. # get the list of currently used uid numbers and add 1 to get the next one
  40. uidnumber=get_posix_number
  41. # add the necessary attribbute for a posixAccount
  42. echo "$user" | sed \
  43. -e "s/%NUMBER%/$uidnumber/" \
  44. -e "s/%UID%/$uid/" | ldapmodify $LDAPOPTS
  45. # create a posix group with the same name and uid as the user
  46. # and add them to it
  47. echo "$group" | sed \
  48. -e "s/%NUMBER%/$uidnumber/" \
  49. -e "s/%UID%/$uid/" | ldapadd $LDAPOPTS