summaryrefslogtreecommitdiff
path: root/populate-ldap/02a-add-groups-using-vlv.sh
blob: af0360ba74feba56e3e15065b66142f3fe93e326 (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
48
49
50
51
52
53
54
55
56
#!/bin/bash

 . ./settings.sh

num_groups=$1
num_members=$2

if [ -z "${num_groups}" ]; then
    num_groups=10
fi

if [ -z "${num_members}" ]; then
    num_members=10
fi

x=0
while [ $x -lt ${num_groups} ]; do

    cn=`head -c 200 /dev/urandom | tr -dc A-Za-z | head -c5`

    echo "dn: cn=${cn},ou=Groups,${rootdn}"
    echo "cn: ${cn}"
    echo "objectClass: top"
    echo "objectClass: groupofuniquenames"
    echo "objectClass: kolabgroupofuniquenames"

    y=0
    while [ $y -lt ${num_members} ]; do
        uid_search=`head -c 200 /dev/urandom | tr -dc A-Za-z | head -c3 | tr '[:upper:]' '[:lower:]'`

        search_result=`echo "exit" | ldapsearch \
            -x \
            -h ${ldap_host} \
            -D "${ldap_binddn}" \
            -w "${ldap_bindpw}" \
            -LLL \
            -b "ou=People,${rootdn}" \
            -s sub "(&(objectclass=inetorgperson)(displayname=*${uid_search}*))" \
            -E '!vlv=10/10/1/1000' \
            -E '!sss=displayname sn givenname cn' dn 2>&1 | \
            grep -vE "(^$|^#|^Press|^VLV)" | \
            sed -e 's/dn: //g'`

        if [ ! -z "${search_result}" ]; then
            for dn in ${search_result}; do
                let y++
                echo "uniquemember: ${dn}"
            done
        fi
    done | sort -u

    echo ""

    let x++
done | ldapadd -x -h ${ldap_host} -D "${ldap_binddn}" -w "${ldap_bindpw}" -c