summaryrefslogtreecommitdiff
path: root/populate-ldap/00a-add-kolab-users.sh
blob: f7bbbf4c7776d5eb3f9cb5b833da04e4b929fd00 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/bash

 . ./settings.sh

i=0
while [ $i -lt 0$1 ]; do

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

    givenname="$(echo ${givenname:0:1} | tr '[:lower:]' '[:upper:]')$(echo ${givenname:1} | tr '[:upper:]' '[:lower:]')"
    givenname_lower="$(echo ${givenname} | tr '[:upper:]' '[:lower:]')"
    surname="$(echo ${surname:0:1} | tr '[:lower:]' '[:upper:]')$(echo ${surname:1} | tr '[:upper:]' '[:lower:]')"
    surname_lower="$(echo ${surname} | tr '[:upper:]' '[:lower:]')"

    uid="$(echo ${givenname:0:1}.${surname} | tr '[:upper:]' '[:lower:]')"

    userpassword="${default_user_password}"

    telephonenumber=""
    if [ $(( $RANDOM % 2 )) -eq 0 ]; then
        telephonenumber="+"
        while [ "$(echo ${telephonenumber} | wc -c)" -lt 12 ]; do
            telephonenumber="${telephonenumber}$(echo $RANDOM)"
        done
    fi

    mobile=""
    if [ $(( $RANDOM % 2 )) -eq 0 ]; then
        mobile="+"
        while [ "$(echo ${mobile} | wc -c)" -lt 12 ]; do
            mobile="${mobile}$(echo $RANDOM)"
        done
    fi

    jpegphoto_from=""
    if [ $(( $RANDOM % 2 )) -eq 0 ]; then
        [ ! -f "/root/hackergotchi.png" ] && \
            wget -q -O/root/hackergotchi.png \
                http://kanarip.fedorapeople.org/kanarip.png

        jpegphoto_from="< file:/root/hackergotchi.png"
    fi

    mailalternateaddress=""
    if [ $(( $RANDOM % 2 )) -eq 0 ]; then
        mailalternateaddress="${uid}@${surname_lower}.com"
    fi

    echo "dn: uid=$uid,ou=People,${rootdn}"
    echo "uid: $uid"
    echo "givenName: $givenname"
    echo "objectClass: top"
    echo "objectClass: person"
    echo "objectClass: inetOrgPerson"
    echo "objectclass: kolabinetorgperson"
    echo "objectclass: organizationalperson"
    echo "objectclass: mailrecipient"
    echo "userpassword: ${userpassword}"

    if [ ! -z "${telephonenumber}" ]; then
        echo "telephonenumber: ${telephonenumber}"
    fi

    if [ ! -z "${mobile}" ]; then
        echo "mobile: ${mobile}"
    fi

    if [ ! -z "${jpegphoto_from}" ]; then
        echo "jpegphoto:${jpegphoto_from}"
    fi

    if [ ! -z "${mailalternateaddress}" ]; then
        echo "mailalternateaddress: ${mailalternateaddress}"
    fi

    echo "sn: $surname"
    echo "cn: $givenname $surname"
    echo "displayname: $surname, $givenname"
    echo "mail: ${givenname_lower}.${surname_lower}@${domain}"
    echo ""

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