summaryrefslogtreecommitdiff
path: root/populate-ldap/10d-test-use-detected-vlv.sh
blob: 26f67bcd75f963fc3e3a3a23eaba598989560588 (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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
#!/bin/bash

 . ./settings.sh

vlvbasedn=""
vlvscope=""
vlvfilter=""
vlvsort=""

(
    ldapsearch -x -h ${ldap_host} -D "${ldap_binddn}" -w "${ldap_bindpw}" -LLL -b "cn=ldbm database,cn=plugins,cn=config" "(objectclass=vlvsearch)" entrydn | grep ^dn | cut -d':' -f2-
) | while read vlvsearch; do
    vlvbasedn=`ldapsearch -x -h ${ldap_host} -D "${ldap_binddn}" -w "${ldap_bindpw}" -LLL -b "${vlvsearch}" -s base vlvbase | grep -v ^dn | sed '/^vlvbase:/{
    $!{ N
    s/vlvbase: //
    s/\n\s//
}}'`

    vlvscope=`ldapsearch -x -h ${ldap_host} -D "${ldap_binddn}" -w "${ldap_bindpw}" -LLL -b "${vlvsearch}" -s base vlvscope | grep -v ^dn | sed '/^vlvscope:/{
    $!{ N
    s/vlvscope: //
    s/\n\s//
}}'`

    vlvfilter=`ldapsearch -x -h ${ldap_host} -D "${ldap_binddn}" -w "${ldap_bindpw}" -LLL -b "${vlvsearch}" -s base vlvfilter | grep -v ^dn | sed '/^vlvfilter:/{
    $!{ N
    s/vlvfilter: //
    s/\n\s//
}}'`

    vlvsort=`ldapsearch -x -h ${ldap_host} -D "${ldap_binddn}" -w "${ldap_bindpw}" -LLL -b "${vlvsearch}" -s sub "(objectclass=vlvIndex)" vlvsort | grep -v ^dn | sed '/^vlvsort:/{
    $!{ N
    s/vlvsort: //
    s/\n\s//
}}'`

    echo "Found a VLV index and search with parameters:"
    echo " - Base: ${vlvbasedn}"
    echo -n " - Scope: "

    case ${vlvscope} in
        0)
            echo "base"
            vlvscope="base"
        ;;

        1)
            echo "one"
            vlvscope="one"
        ;;

        2)
            echo "sub"
            vlvscope="sub"
        ;;
    esac

    echo " - Filter: ${vlvfilter}"
    echo " - Sorting by: ${vlvsort}"

    # Use it

    uses_before=`ldapsearch \
        -x \
        -h ${ldap_host} \
        -D "${ldap_binddn}" \
        -w "${ldap_bindpw}" \
        -b "${vlvsearch}" \
        -s sub \
        "(&(objectclass=vlvindex)(vlvsort=${vlvsort}))" \
        -LLL \
        vlvuses | \
        grep -i ^vlvuses | awk '{print $2}'`

    if [ -z "${uses_before}" ]; then
        uses_before=0
    fi

    echo "after" | ldapsearch \
        -x \
        -h ${ldap_host} \
        -D "${ldap_binddn}" \
        -w "${ldap_bindpw}" \
        -b "${vlvbasedn}" \
        -s ${vlvscope} "${vlvfilter}" \
        -E '!vlv=5/5/1/10' \
        -E "!sss=$(echo ${vlvsort} | sed -e 's| |/|g')" >/dev/null 2>&1

    uses_after=`ldapsearch \
        -x \
        -h ${ldap_host} \
        -D "${ldap_binddn}" \
        -w "${ldap_bindpw}" \
        -b "${vlvsearch}" \
        -s sub \
        "(&(objectclass=vlvindex)(vlvsort=${vlvsort}))" \
        -LLL \
        vlvuses | \
        grep -i ^vlvuses | awk '{print $2}'`

    if [ -z "${uses_after}" ]; then
        uses_after=0
    fi

    if [ ${uses_before} -lt ${uses_after} ]; then
        echo "Actually works, too (before: ${uses_before}, after: ${uses_after})"
    fi
done