View Single Post
  #10 (permalink)  
Old 07-03-2009, 01:58 PM
ewilen ewilen is offline
Moderator
 
Posts: 1,405
Default shell script to delegate between accounts

First real shell scripting I've done...

Note that this should no longer be necessary once 6.0 (GunsNRoses) is released.

Code:
# ! /bin/sh
#
# Script to perform Calendar delegation between accounts
#
# Usage ./zmdelegate source_account delegate_account
# Should be executed as zimbra user.
# 
#
# Name of notifications folder
notifications="Meeting Notifications"
# Name of filter used on boss's account
filtername="Meeting Notifications"
# response variable
response=
# Note: could do all checking and then output list of all problems
# instead of exiting after first detected problem
#
# Verify exactly two arguments
# (Could use shell Shift command to allow multiple delegation)
if test $# -ne 2
then
echo "Must supply exactly two arguments."
exit 1
fi
# Assign variables
boss_account=$1
assistant_account=$2
# Verify <boss_account> and <assistant_account> exist on the server
if ! zmmailbox -z -m $boss_account gms 1>/dev/null 2>/dev/null
then
echo "Boss account doesn't exist. Terminating."
exit 1
fi
if ! zmmailbox -z -m $assistant_account gms 1>/dev/null 2>/dev/null
then
echo "Assistant account doesn't exist. Terminating."
exit 1
fi
# Check if Meeting Notifications Folder already exists; if it does, then post warning and ask if want to continue.
# Otherwise Create Meeting Notifications Folder
if zmmailbox -z -m $boss_account gf "$notifications" 1>/dev/null 2>/dev/null
then
	while [ "$response" != "y"  -a "$response" != "n" ]
		do
			echo -e 'Folder "\c'
			echo -e "$notifications\c"
			echo -e '" already exists, use it to store/share notification messages? (y/n) \c'
			read response
	done
	if [ "$response" = n ]
	then
		echo "Command cancelled."
		exit 1
	fi
else
	echo -e 'Creating folder "\c'
	echo -e "$notifications\c"
	echo -e '".'
	zmmailbox -z -m $boss_account cf -V message "/$notifications" 1>/dev/null 2>/dev/null
fi
# Make sure that mountpoint names on assistant's account don't already exist
# Am having to use account names in names of sharepoints because I don't see
# a way to discover display names via CLI. Could add user-defined sharepoint
# names later.
if zmmailbox -z -m $assistant_account gf "/$boss_account $notifications" 1>/dev/null 2>/dev/null
then
echo -e 'Naming conflict--delete or unmount folder "\c'
echo -e "$boss_account $notifications\c"
echo -e '" on assistant account.'
exit 1
fi
if zmmailbox -z -m $assistant_account gf "/$boss_account Calendar" 1>/dev/null 2>/dev/null
then
echo -e 'Naming conflict--delete or unmount calendar "\c'
echo -e "$boss_account Calendar\c"
echo -e '" on assistant account.'
exit 1
fi
#Verify that filter rule with same name doesn't already exist
if eval zmmailbox -z -m $boss_account gfrl | grep ^\"Meeting\ Notifications\" 1>/dev/null
then
echo -e 'Naming conflict--delete or rename filter "\c'
echo -e "$filtername\c"
echo -e '" on boss account.'
exit 1
fi
# Share Meeting Notifications Folder and Calendar to assistant R/W
echo "Sharing Meeting Notifications Folder."
zmmailbox -z -m $boss_account mfg "/$notifications" account $assistant_account rwidx
echo "Sharing Calendar."
zmmailbox -z -m $boss_account mfg "/Calendar" account $assistant_account rwidx
#Accept shares by assistant (only for web interface; Outlook must be done at the workstation)
echo "Mounting Meeting Notifications Folder on assistant account. Right-click in Zimbra Web Client to change name."
zmmailbox -z -m $assistant_account cm -F# "/$boss_account $notifications" $boss_account "/$notifications" 1>/dev/null
echo "Mounting Calendar Folder on assistant account. Right-click in Zimbra Web Client to change name."
zmmailbox -z -m $assistant_account cm -F# "/$boss_account Calendar" $boss_account "/Calendar" 1>/dev/null
echo '(In Outlook, use File>Open>Other User’s Folder to access.)'
#Create filter to file meeting messages into folder
echo "Creating filter in boss account."
zmmailbox -z -m $boss_account afrl -f "$filtername" body contains "Content-Type: text/calendar" body contains "method=" body contains "METHOD:" body contains "BEGIN:VEVENT" body contains "BEGIN:VCALENDAR" fileinto "/$notifications" stop
echo "Delegation complete!"
__________________
Elliot Wilen
Berkeley, CA

Don't forget to enter your Zimbra version in your forum profile.

Last edited by ewilen; 07-03-2009 at 02:04 PM..
Reply With Quote