From: <svn...@op...> - 2009-03-26 00:13:55
|
Author: scriptor Date: Thu Mar 26 01:13:36 2009 New Revision: 5334 URL: http://www.opensync.org/changeset/5334 Log: Initial version of the LDAP plugin having been ported to libopensync-0.3x. Added: plugins/ldap-sync/misc/ plugins/ldap-sync/misc/clean_ldap.sh (contents, props changed) Added: plugins/ldap-sync/misc/clean_ldap.sh ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ plugins/ldap-sync/misc/clean_ldap.sh Thu Mar 26 01:13:36 2009 (r5334) @@ -0,0 +1,122 @@ +#!/bin/bash + +# $Id$ + +file=`basename $0` +tmpfile="/tmp/list" + +# 1 is FALSE or "No, do NOT delete it." in bash. +# 0 is TRUE or "Yes, delete it." +# Or I should have better said, empty it. +delete_addressbook=1 +delete_calendar=1 +delete_todo=1 +delete_note=1 + +binddn="cn=ldap_user,dc=example,dc=com" +user="ldap_user" +password="secret" +sasl_mechanism="DIGEST-MD5" + +#auth="-x -D \"$binddn\" -w \"$password\" " +auth="-U \"$user\" -w \"$password\" -Y \"$sasl_mechanism\"" + + +addressbook='ou=addressbook,dc=example,dc=com' +calendar='ou=calendar,dc=example,dc=com' +todo='ou=todo,dc=example,dc=com' +note='o=notes,dc=example,dc=com' + + +if test -f "$tmpfile"; then + rm -f "$tmpfile"; +fi + +if test -f "$tmpfile"; then + echo "$file:$LINENO: ERROR: $tmpfile already exists and is NOT writable. Exiting." + exit 1 +fi + + + +run_command() +{ + cmd=$1 + + #echo "cmd = \"$cmd\"" + if test -n "$cmd"; then + eval $cmd + rv=$? + + if test $rv -ne 0; then + echo -e "The command \n\n$cmd\n\nhas failed. Exiting." + exit + fi + + return $rv + fi +} + + + +############### addressbook ################# +if test $delete_addressbook -eq 0; then + # What is to be deleted? + run_command "ldapsearch $auth -LLL -A -s one -b \"$addressbook\" 'dn' | awk 'BEGIN {RS = \"\n\n\"} {gsub(\"dn: \", \"\"); gsub(/\n /, \"\"); print}' > $tmpfile" + + + # Clear all the entries of the addressbook: + if test -s "$tmpfile"; then + run_command "ldapdelete $auth -r -c -f $tmpfile" + fi + + + # Check the result: + run_command "ldapsearch $auth -LLL -s sub -b \"$addressbook\"" +fi + + +############# calendar ################## +if test $delete_calendar -eq 0; then + run_command "ldapsearch $auth -LLL -s one -A -b \"$calendar\" 'dn' | awk 'BEGIN {RS = \"\n\n\"} {gsub(\"dn: \", \"\"); gsub(/\n /, \"\"); print}' > $tmpfile" + + # Clear all the entries of the calendar: + if test -s "$tmpfile"; then + run_command "ldapdelete $auth -r -f $tmpfile" + fi + + # Check the result: + run_command "ldapsearch $auth -LLL -s sub -b \"$calendar\"" +fi + + + +############# todo ################## +if test $delete_todo -eq 0; then + run_command "ldapsearch $auth -LLL -s one -A -b \"$todo\" 'dn' | awk 'BEGIN {RS = \"\n\n\"} {gsub(\"dn: \", \"\"); gsub(/\n /, \"\"); print}' > $tmpfile" + + # Clear all the entries of the todo's: + if test -s "$tmpfile"; then + run_command "ldapdelete $auth -r -f $tmpfile" + fi + + # Check the result: + run_command "ldapsearch $auth -LLL -s sub -b \"$todo\"" +fi + + + +############## notes #################### +if test $delete_note -eq 0; then + # What is to be deleted? + run_command "ldapsearch $auth -LLL -s one -A -b \"$note\" 'dn' | awk 'BEGIN {RS = \"\n\n\"} {gsub(\"dn: \", \"\"); gsub(/\n /, \"\"); gsub(/^ou=.+$/, \"\"); print}' > $tmpfile" + + # Clear all the entries of the notes: + if test -s "$tmpfile"; then + run_command "ldapdelete $auth -r -f $tmpfile" + fi + + # Check the result: + run_command "ldapsearch $auth -LLL -s sub -b \"$note\"" +fi + |