summaryrefslogtreecommitdiff
path: root/utils/create-large-groups.sh
blob: 9e33f4d4f17df4ca18fc59031ce83ffdd0c7852b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash

 . ./settings.sh

declare -a members

for member_dn in `ldapsearch -x -h ${ldap_host} -D "${ldap_binddn}" -w "${ldap_bindpw}" -b "ou=People,${rootdn}" -LLL "(objectclass=kolabinetorgperson)" entrydn | grep ^dn: | cut -d':' -f2`; do
    members[${#members[@]}]="${member_dn}"
done

declare -a random_numbers

i=0
done=0
while [ ${i} -lt $(( ${#members[@]} / 2 )) -a ${done} -eq 0 ]; do

    for random_number in `head -n ${#members[@]} /dev/urandom | od | awk '{print $2}' | sort -u`; do
        if [ ${random_number} -le ${#members[@]} ]; then
            random_numbers[${#random_numbers[@]}]=${random_number}
        else
            done=1
            break
        fi
    done

    i=${#random_numbers[@]}

done
(
    echo "dn: cn=Students,ou=Groups,${rootdn}"
    echo "objectclass: top"
    echo "objectclass: groupofuniquenames"
    echo "objectclass: kolabgroupofuniquenames"
    echo "cn: Students"
    echo "mail: students@${domain}"
    i=0
    while [ $i -lt ${#random_numbers[@]} ]; do
        if [ ! -z "${members[${random_numbers[$i]}]}" ]; then
            echo "uniquemember: ${members[${random_numbers[$i]}]}"
        fi
        let i++
    done | sort -u
    echo ""
) > /tmp/ldif

ldapadd -x -h ${ldap_host} -D "${ldap_binddn}" -w "${ldap_bindpw}" -c -f /tmp/ldif