summaryrefslogtreecommitdiff
path: root/populate-ldap/01b-add-contacts.sh
blob: b548c0fb0b7d89968402ec082e2963a58e96972b (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
#!/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

    echo "dn: uid=$uid,ou=Contacts,ou=People,${rootdn}"
    echo "uid: $uid"
    echo "givenName: $givenname"
    echo "objectClass: top"
    echo "objectClass: person"
    echo "objectClass: inetOrgPerson"
    echo "objectclass: organizationalperson"
    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

    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