| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #!/bin/bash -e
- . /etc/ldap-utils.conf
- . /usr/local/lib/ldap-utils/funcs
- usage() {
- echo "Usage : $(basename $0) -u <uid> -n <First name> -s <Last Name> [-p] [-g group1,group2,...]"
- }
- trap usage ERR
- while getopts 'u:n:s:p?g:?' opt; do
- case "$opt" in
- u)
- uid="$OPTARG"
- ;;
- n)
- gn="$OPTARG"
- ;;
- s)
- sn="$OPTARG"
- ;;
- p)
- posix="true"
- ;;
- g)
- grouplist=$( echo $OPTARG | tr ',' ' ')
- ;;
- esac
- done
- clearpw=$(pwgen 50 1)
- pw=$(/usr/sbin/slappasswd -o module-load=pw-sha2 -h '{SSHA512}' -s "$clearpw")
- if user_exists $uid; then
- echo "User $uid already exists."
- exit 1
- fi
- user="dn: uid=$uid,$PEOPLEDN
- objectClass: top
- objectClass: inetOrgPerson
- sn: $sn
- gn: $gn
- cn: $gn $sn
- mail: $uid@$DOMAIN
- userPassword: $pw"
- echo "$user" | ldapadd $LDAPOPTS
- [ -n "$posix" ] && echo posix && person2posix $uid
- [ -n "$grouplist" ] && echo groups && addtogroups $uid $grouplist
- echo "User $uid created, here is their password :"
- echo "$clearpw"
|