diff options
author | Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> | 2012-08-23 13:50:15 (GMT) |
---|---|---|
committer | Jeroen van Meeuwen (Kolab Systems) <vanmeeuwen@kolabsys.com> | 2012-08-23 13:50:15 (GMT) |
commit | 811f83ace1e63d493093dff78151e9a64d90cf53 (patch) | |
tree | f3dde9326fdc7b4d3592f46c95bf687915ed4513 /populate-ldap | |
parent | be3183ea867ad6fe909e9684b45d6e3667cf2ede (diff) | |
download | kolab-scripts-811f83ace1e63d493093dff78151e9a64d90cf53.tar.gz |
Add the kolab-scripts used in migration and development
Diffstat (limited to 'populate-ldap')
-rwxr-xr-x | populate-ldap/000-add-kolab-users-and-groups.sh | 10 | ||||
-rwxr-xr-x | populate-ldap/00a-add-kolab-users.sh | 84 | ||||
-rwxr-xr-x | populate-ldap/00b-add-kolab-users-group.sh | 15 | ||||
-rwxr-xr-x | populate-ldap/100-add-vlv.sh | 9 | ||||
-rwxr-xr-x | populate-ldap/10a-add-vlv-searches.sh | 28 | ||||
-rwxr-xr-x | populate-ldap/10b-add-vlv-indexes.sh | 24 | ||||
-rwxr-xr-x | populate-ldap/10c-run-vlv-index-tasks.sh | 71 | ||||
-rwxr-xr-x | populate-ldap/10d-test-use-detected-vlv.sh | 78 | ||||
-rwxr-xr-x | populate-ldap/99-cleanup-users-and-groups.sh | 33 | ||||
l--------- | populate-ldap/settings.sh | 1 |
10 files changed, 353 insertions, 0 deletions
diff --git a/populate-ldap/000-add-kolab-users-and-groups.sh b/populate-ldap/000-add-kolab-users-and-groups.sh new file mode 100755 index 0000000..5cc5575 --- /dev/null +++ b/populate-ldap/000-add-kolab-users-and-groups.sh @@ -0,0 +1,10 @@ +#!/bin/bash + +if [ -z "$1" ]; then + num_add=10 +else + num_add=$1 +fi + +./00a-add-kolab-users.sh ${num_add} +./00b-add-kolab-users-group.sh diff --git a/populate-ldap/00a-add-kolab-users.sh b/populate-ldap/00a-add-kolab-users.sh new file mode 100755 index 0000000..3c1586a --- /dev/null +++ b/populate-ldap/00a-add-kolab-users.sh @@ -0,0 +1,84 @@ +#!/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="Welcome2KolabSystems" + + 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" + + 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 + diff --git a/populate-ldap/00b-add-kolab-users-group.sh b/populate-ldap/00b-add-kolab-users-group.sh new file mode 100755 index 0000000..6f1670c --- /dev/null +++ b/populate-ldap/00b-add-kolab-users-group.sh @@ -0,0 +1,15 @@ +#!/bin/bash + + . ./settings.sh + +( + echo "dn: cn=Kolab Users,ou=Groups,${rootdn}" + echo "objectClass: top" + echo "objectClass: groupofurls" + echo "objectClass: kolabgroupofuniquenames" + echo "cn: Kolab Users" + echo "mail: kolab-users@${domain}" + echo "memberURL: ldap:///ou=People,${rootdn}??sub?(&(objectClass=kolabinetorgperson)(mail=*))" + echo "" +) | ldapadd -x -h ${ldap_host} -D "${ldap_binddn}" -w "${ldap_bindpw}" -c + diff --git a/populate-ldap/100-add-vlv.sh b/populate-ldap/100-add-vlv.sh new file mode 100755 index 0000000..d4b90c1 --- /dev/null +++ b/populate-ldap/100-add-vlv.sh @@ -0,0 +1,9 @@ +#!/bin/bash + + . ./settings.sh + +./10a-add-vlv-searches.sh +./10b-add-vlv-indexes.sh +./10c-run-vlv-index-tasks.sh +./10d-test-use-detected-vlv.sh + diff --git a/populate-ldap/10a-add-vlv-searches.sh b/populate-ldap/10a-add-vlv-searches.sh new file mode 100755 index 0000000..96f5752 --- /dev/null +++ b/populate-ldap/10a-add-vlv-searches.sh @@ -0,0 +1,28 @@ +#!/bin/bash + + . ./settings.sh + +( + echo "dn: cn=People VLV Search,cn=${domain_db},cn=ldbm database,cn=plugins,cn=config" + echo "objectClass: top" + echo "objectClass: vlvSearch" + echo "cn: People VLV Search" + echo "vlvBase: ou=People,${rootdn}" + echo "vlvScope: 2" + echo "vlvFilter: (objectclass=inetorgperson)" + echo "aci: (targetattr = \"*\") (version 3.0;acl \"Read Access\";allow (read,compare,search)(userdn = \"ldap:///anyone\");)" + echo "" +) | ldapadd -x -h ${ldap_host} -D "${ldap_binddn}" -w "${ldap_bindpw}" -c + +( + echo "dn: cn=Groups VLV Search,cn=${domain_db},cn=ldbm database,cn=plugins,cn=config" + echo "objectClass: top" + echo "objectClass: vlvSearch" + echo "cn: Groups VLV Search" + echo "vlvBase: ou=Groups,${rootdn}" + echo "vlvScope: 2" + echo "vlvFilter: (|(objectclass=groupofuniquenames)(objectclass=groupofurls))" + echo "aci: (targetattr = \"*\") (version 3.0;acl \"Read Access\";allow (read,compare,search)(userdn = \"ldap:///anyone\");)" + echo "" +) | ldapadd -x -h ${ldap_host} -D "${ldap_binddn}" -w "${ldap_bindpw}" -c + diff --git a/populate-ldap/10b-add-vlv-indexes.sh b/populate-ldap/10b-add-vlv-indexes.sh new file mode 100755 index 0000000..92fcabc --- /dev/null +++ b/populate-ldap/10b-add-vlv-indexes.sh @@ -0,0 +1,24 @@ +#!/bin/bash + + . ./settings.sh + +( + echo "dn: cn=People VLV Index,cn=People VLV Search,cn=${domain_db},cn=ldbm database,cn=plugins,cn=config" + echo "objectClass: top" + echo "objectClass: vlvIndex" + echo "cn: People VLV Index" + echo "vlvSort: displayname sn givenname cn" + echo "aci: (targetattr = \"*\") (version 3.0;acl \"Read Access\";allow (read,compare,search)(userdn = \"ldap:///anyone\");)" + echo "" +) | ldapadd -x -h ${ldap_host} -D "${ldap_binddn}" -w "${ldap_bindpw}" -c + +( + echo "dn: cn=Groups VLV Index,cn=Groups VLV Search,cn=${domain_db},cn=ldbm database,cn=plugins,cn=config" + echo "objectClass: top" + echo "objectClass: vlvIndex" + echo "cn: Groups VLV Index" + echo "vlvSort: cn" + echo "aci: (targetattr = \"*\") (version 3.0;acl \"Read Access\";allow (read,compare,search)(userdn = \"ldap:///anyone\");)" + echo "" +) | ldapadd -x -h ${ldap_host} -D "${ldap_binddn}" -w "${ldap_bindpw}" -c + diff --git a/populate-ldap/10c-run-vlv-index-tasks.sh b/populate-ldap/10c-run-vlv-index-tasks.sh new file mode 100755 index 0000000..31fd2ca --- /dev/null +++ b/populate-ldap/10c-run-vlv-index-tasks.sh @@ -0,0 +1,71 @@ +#!/bin/bash + + . ./settings.sh + +( + echo "dn: cn=${domain_db} People VLV Index,cn=index,cn=tasks,cn=config" + echo "objectclass: top" + echo "objectclass: extensibleObject" + echo "cn: ${domain_db} People VLV Index" + echo "nsinstance: ${domain_db}" + echo "nsIndexVLVAttribute: People VLV Index" + echo "" +) | ldapmodify -a -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} People VLV 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 + +( + echo "dn: cn=${domain_db} Groups VLV Index,cn=index,cn=tasks,cn=config" + echo "objectclass: top" + echo "objectclass: extensibleObject" + echo "cn: ${domain_db} Groups VLV Index" + echo "nsinstance: ${domain_db}" + echo "nsIndexVLVAttribute: Groups VLV Index" + echo "" +) | ldapmodify -a -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} Groups VLV 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 + + diff --git a/populate-ldap/10d-test-use-detected-vlv.sh b/populate-ldap/10d-test-use-detected-vlv.sh new file mode 100755 index 0000000..1b21aca --- /dev/null +++ b/populate-ldap/10d-test-use-detected-vlv.sh @@ -0,0 +1,78 @@ +#!/bin/bash + + . ./settings.sh + +( + 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 -i ^vlvbase | awk 'BEGIN { FS = ": " } ; {print $2}'` + vlvscope=`ldapsearch -x -h ${ldap_host} -D "${ldap_binddn}" -w "${ldap_bindpw}" -LLL -b "${vlvsearch}" -s base vlvscope | grep -i ^vlvscope | awk 'BEGIN { FS = ": " } ; {print $2}'` + vlvfilter=`ldapsearch -x -h ${ldap_host} -D "${ldap_binddn}" -w "${ldap_bindpw}" -LLL -b "${vlvsearch}" -s base vlvfilter | grep -i ^vlvfilter | awk 'BEGIN { FS = ": " } ; {print $2}'` + vlvsort=`ldapsearch -x -h ${ldap_host} -D "${ldap_binddn}" -w "${ldap_bindpw}" -LLL -b "${vlvsearch}" -s sub "(objectclass=vlvIndex)" vlvsort | grep -i ^vlvsort | awk 'BEGIN { FS = ": " } ; {print $2}'` + + 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 "cn=ldbm database,cn=plugins,cn=config" \ + -s sub \ + "(&(objectclass=vlvindex)(vlvsort=${vlvsort}))" \ + -LLL \ + vlvuses | \ + grep -i ^vlvuses | awk '{print $2}'` + + 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 "cn=ldbm database,cn=plugins,cn=config" \ + -s sub \ + "(&(objectclass=vlvindex)(vlvsort=${vlvsort}))" \ + -LLL \ + vlvuses | \ + grep -i ^vlvuses | awk '{print $2}'` + + if [ ${uses_before} -lt ${uses_after} ]; then + echo "Actually works, too (before: ${uses_before}, after: ${uses_after})" + fi +done + + diff --git a/populate-ldap/99-cleanup-users-and-groups.sh b/populate-ldap/99-cleanup-users-and-groups.sh new file mode 100755 index 0000000..38c3f39 --- /dev/null +++ b/populate-ldap/99-cleanup-users-and-groups.sh @@ -0,0 +1,33 @@ +#!/bin/bash + + . ./settings.sh + +( + ldapsearch \ + -x \ + -h ${ldap_host} \ + -D "${ldap_binddn}" \ + -w "${ldap_bindpw}" \ + -b "ou=People,${rootdn}" \ + -s one \ + "(objectclass=inetorgperson)" \ + -LLL \ + dn | \ + grep ^dn | \ + sed -e 's/dn: //g' +) | ldapdelete -x -h ${ldap_host} -D "${ldap_binddn}" -w "${ldap_bindpw}" -c + +( + ldapsearch \ + -x \ + -h ${ldap_host} \ + -D "${ldap_binddn}" \ + -w "${ldap_bindpw}" \ + -b "ou=Groups,${rootdn}" \ + "(|(objectclass=groupofuniquenames)(objectclass=groupofurls))" \ + -LLL \ + dn | \ + grep ^dn | \ + sed -e 's/dn: //g' +) | ldapdelete -x -h ${ldap_host} -D "${ldap_binddn}" -w "${ldap_bindpw}" -c + diff --git a/populate-ldap/settings.sh b/populate-ldap/settings.sh new file mode 120000 index 0000000..a08eca5 --- /dev/null +++ b/populate-ldap/settings.sh @@ -0,0 +1 @@ +../settings.sh
\ No newline at end of file |