summaryrefslogtreecommitdiff
path: root/utils/add-attribute-index.sh
blob: 381ffadb46570157dd1b04a9d4b36ff88ade9bd6 (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
#!/bin/bash

 . ./settings.sh

if [ $# -ne 1 ]; then
    echo "Usage: $0 <attribute>"
    exit 1
fi

export index_attr=$1

(
    echo "dn: cn=${index_attr},cn=index,cn=${domain_db},cn=ldbm database,cn=plugins,cn=config"
    echo "objectclass: top"
    echo "objectclass: nsindex"
    echo "cn: ${index_attr}"
    echo "nsSystemIndex: false"
    echo "nsindextype: pres"
    echo "nsindextype: eq"
    echo "nsindextype: sub"

) | ldapadd -x -h ${ldap_host} -D "${ldap_binddn}" -w "${ldap_bindpw}" -c


(
    echo "dn: cn=${domain_db} ${index_attr} index,cn=index,cn=tasks,cn=config"
    echo "objectclass: top"
    echo "objectclass: extensibleObject"
    echo "cn: ${domain_db} ${index_attr} index"
    echo "nsinstance: ${domain_db}"
    echo "nsIndexAttribute: ${index_attr}:pres"
    echo "nsIndexAttribute: ${index_attr}:eq"
    echo "nsIndexAttribute: ${index_attr}:sub"
    echo ""
) | ldapadd -x -h ${ldap_host} -D "${ldap_binddn}" -w "${ldap_bindpw}" -c

ldap_complete=0

while [ ${ldap_complete} -ne 1 ]; do
    result=$(
            ldapsearch \
                -x \
                -h ${ldap_host} \
                -D "${ldap_binddn}" \
                -w "${ldap_bindpw}" \
                -c \
                -LLL \
                -b "cn=${domain_db} ${index_attr} index,cn=index,cn=tasks,cn=config" \
                -s base 2>/dev/null
        )
    if [ -z "$result" ]; then
        ldap_complete=1
        echo ""
    else
        echo -n "."
        sleep 1
    fi
done