#!/bin/bash

eval "$(ucr shell ldap/base)"

udm users/user create --set username=test1 --set lastname=last1 --set password=univention
sleep 5
udm users/user create --set username=test2 --set lastname=last2 --set password=univention
sleep 5

da_dn=$(univention-ldapsearch "(&(objectClass=univentionGroup)(cn=Domain Admins))" | sed -n 's/^dn: //p')
test1_dn=$(univention-ldapsearch "(&(objectClass=posixAccount)(uid=test1))" | sed -n 's/^dn: //p')
test2_dn=$(univention-ldapsearch "(&(objectClass=posixAccount)(uid=test2))" | sed -n 's/^dn: //p')
udm users/user modify --dn "$test1_dn" --append groups="$da_dn"
sleep 5
udm users/user modify --dn "$test2_dn" --append groups="$da_dn"
sleep 5

udm users/user create --set username=test3 --set lastname=last3 --set password=univention
sleep 5

udm users/user delete --dn "$test1_dn"
sleep 5

ldapmodify -D "cn=admin,$ldap_base" -y /etc/ldap.secret <<-%EOF
dn: $da_dn
changetype: modify
add: uniqueMember
uniqueMember: $test1_dn
-
add: memberUid
memberUid: test1
%EOF
