#!/bin/sh # # new.sh # # # $Id: thunderbird.sh 26 2006-08-29 20:54:25Z cfdoming $ # $LastChangedBy: cfdoming $ # $LastChangedDate: 2006-08-29 16:54:25 -0400 (Tue, 29 Aug 2006) $ # $LastChangedRevision: 26 $ # $HeadURL: file:///mit/thunderbird/repository.svn/config/trunk/bin/thunderbird.sh $ # # # Thunderbird Wrapper Script # Charles Dominguez (cfdoming) # # configdir='.thunderbird' binary='thunderbird' bindir=`athdir -p /mit/thunderbird -t versions` profname='default' runver='current' libpath='/usr/athena/lib:/usr/lib' # Check script parameters case "$1" in --runver) # User is specifying the version to run. case "$2" in *[!a-z0-9A-Z._-]*|.|..) ;; *) runver="$2" ;; esac shift shift ;; --listver) # User only wants a list of availible versions curr=`ls -l $bindir | sed -n -e '/current -> / s/.* current -> //p'` echo "The current version of Mozilla Thunderbird for $ATHENA_SYS is:" echo " ${curr}" echo '' echo "The versions availible for $ATHENA_SYS are:" for dir in "$bindir"/[!.]* ; do ver=`echo $dir | sed -e 's#.*/##' -e '/current/d' ` [ ${ver} ] && echo " ${ver}" done exit 0 esac # Check that thunderbird binaries exist for the version specified if [ ! -d "$bindir/$runver" ]; then echo "thunderbird.sh: The specified version of Mozilla Thunderbird could not be found." echo "To see a list of the availible versions, run the command:" echo "thunderbird --listver" exit 2 fi # Set up the environment. moz_libdir="$bindir/$runver" if [ -z "$MOZILLA_FIVE_HOME" ]; then MOZILLA_FIVE_HOME=$moz_libdir export MOZILLA_FIVE_HOME fi # Sanity check to verify that the binaries are availible #if [ ! -r "$MOZILLA_FIVE_HOME/$binary" -o ! -r "$MOZILLA_FIVE_HOME/mozilla-xremote-client" ]; #then # echo 'thunderbird.sh: Program binaries were not found.' # echo "in: $MOZILLA_FIVE_HOME" # echo 'Please email firebird@mit.edu to report this error.' # exit 3 #fi # Disable the Solaris patch checker MOZILLA_SOLARIS_PATCHCHECKER='disable_patchchecker' export MOZILLA_SOLARIS_PATCHCHECKER # mozilla-xremote-client sends a command to a running mozilla using # X properties. Its possible return codes are: # 0 success # 1 failed to connect to the X server # 2 no running window found # 3 failed to send command # 4 usage error moz_remote="$MOZILLA_FIVE_HOME/mozilla-xremote-client -a thunderbird -u ${USER} " # The following lockers need to be attached to run plugins and helper # applications. lockers="gnu infoagents acro" # Set up mozilla's runtime library path. moz_lib_path=$MOZILLA_FIVE_HOME:$MOZILLA_FIVE_HOME/plugins:$libpath case `uname` in SunOS) # On Solaris, use the X server's shared memory transport for better # performance. if [ -z "$XSUNTRANSPORT" ]; then XSUNTRANSPORT=shmem XSUNSMESIZE=512 export XSUNTRANSPORT XSUNSMESIZE fi # Ensure that we use the Sun gtk libraries. moz_lib_path=$moz_lib_path:/usr/sfw/lib java_plugin_dir=/usr/j2se/jre/plugin/sparc/ns610 ;; Linux) # Set LD_ASSUME_KERNEL to avoid a java crash upon exit. LD_ASSUME_KERNEL=2.4.1 export LD_ASSUME_KERNEL java_plugin_dir=/usr/java/j2re1.4.2_04/plugin/i386/ns610-gcc32 ;; esac LD_LIBRARY_PATH=$moz_lib_path${LD_LIBRARY_PATH:+":$LD_LIBRARY_PATH"} export LD_LIBRARY_PATH # Set the plugin path. We allow the user to skip loading our # standard plugins via the MOZ_PLUGIN_PATH_OVERRIDE variable. if [ "${MOZ_PLUGIN_PATH_OVERRIDE+set}" = set ]; then MOZ_PLUGIN_PATH="$MOZ_PLUGIN_PATH_OVERRIDE" else # Append our plugin path to the user's setting (if any). # The Java plugin is in the locally-installed JRE package, and its # directory is set above; others (besides the default "null" plugin) # live in infoagents. plugin_path=$java_plugin_dir:/mit/infoagents/arch/@sys/lib/mozilla/plugins MOZ_PLUGIN_PATH=${MOZ_PLUGIN_PATH:+"$MOZ_PLUGIN_PATH:"}$plugin_path fi export MOZ_PLUGIN_PATH # Prompt the user on how to deal with an existing lock file when no # running Thunderbird window can be found, and take action accordingly. # Parameter 1 is the existing profile lock file path. # Parameter 2 is any unexpected error output by mozilla-xremote-client, # i.e. when it returned an error status other than 2. It should be null # for the normal case. # If the function returns, the lock file may have been removed per the # user's choice, and the caller should continue. Or, this process may # exit, if the user so chooses. dispose_lock () { lock=$1 remote_error="$2" # Extract the IP address and PID from the contents of the symlink. eval `ls -l $lock | awk '{ if (split($NF, a, ":") == 2) printf("lock_ip=%s ; lock_pid=%s\n", a[1], a[2]); }'` # If we cannot recognize the link contents, just continue. if [ -z "$lock_ip" ]; then return 0 fi # See if the lock holder is on this machine by comparing IP addresses. my_host=`hostname` if [ "$lock_ip" = "`host $my_host | awk '{ print $NF; }'`" ]; then # Lock is held on this machine. See if the process is running. if kill -0 $lock_pid 2>/dev/null ; then # Lock is held by a running process. : else # Process is no longer running. Nuke the lock and continue. rm -f $lock return 0 fi lock_host="this machine" else # Lock is held on another machine. # Get the host name of the lock holder. lock_host=`host $lock_ip | \ sed -n -e 's/^.*domain name pointer \(.*\)$/\1/p' | \ sed -e 's/\.*$//' | tr '[A-Z]' '[a-z]'` if [ -z "$lock_host" ]; then lock_host=$lock_ip fi fi dialog_text=" Your Thunderbird profile directory contains a lock file, but no existing Thunderbird window can be detected. The lock is owned by process $lock_pid on $lock_host. " if [ -n "$remote_error" ]; then dialog_text="$dialog_text Warning: The attempt to find an existing Thunderbird window resulted in the following unexpected error: $remote_error " fi dialog_text="$dialog_text Note that running multiple instances of Thunderbird will likely corrupt your profile. But, if you know for certain that this lock file is stale, i.e. that you are not running Thunderbird on $lock_host, you may choose to delete the lock file and continue. Otherwise, you may choose to continue with the lock file in place, in which case Thunderbird will display its Profile Manager, allowing you to select or create a different profile (Thunderbird will not permit you to use a profile which it believes to be in use). Or, you can simply exit, leaving the lock file in place. " tag=`zenity --title "Thunderbird profile locked" --list --radiolist \ --height 480 --text "$dialog_text" \ --column "" --column "Select one of the following actions" \ TRUE "Exit, leaving lock file in place" \ FALSE "Continue, and invoke Thunderbird's Profile Manager" \ FALSE "Delete lock file and proceed" 2>&1` case "$tag" in Continue*) ;; Delete*) rm -f $lock ;; *) exit 1 ;; esac } # Give a warning if we're running on a dialup machine. if [ -x /etc/athena/dialuptype ]; then cat << \EOF *** PLEASE DO NOT RUN MOZILLA THUNDERBIRD ON THE DIALUPS! *** Mozilla Thunderbird is a very large and resource-intensive program, and it is not appropriate to run it on a dialup machine. Please run Mozilla Thunderbird on your local machine rather than on a dialup. Thank you. EOF fi # Attach needed lockers. for locker in $lockers ; do eval `/bin/athena/attach -Padd -b $locker` done # Configure fontconfig to use fonts for MathML. if [ -z "$FONTCONFIG_FILE" ]; then FONTCONFIG_FILE=/mit/infoagents/share/fonts/fonts.conf export FONTCONFIG_FILE fi # If the user specified a profile to use, is otherwise manipulating # profiles, or is just looking for help, skip the check for a running # Mozilla, and invoke the program now. skip_lock_check=false case "$1" in -P|-*Profile*|-help|-remote) exec $MOZILLA_FIVE_HOME/$binary "$@" 2>/dev/null ;; esac # See if there is a running instance of Mozilla. remote_error=`$moz_remote "ping()" 2>&1 >/dev/null` case $? in 0) found_running=true ;; 2) # This is the expected status when there is no running mozilla window. # Clear the error condition. remote_error= found_running=false ;; *) # An unexpected error occurred. found_running=error ;; esac # If Mozilla is not running, check for a (possibly stale) lock file in # the default profile directory. if [ $found_running != true ]; then profdir=$HOME/$configdir/????????.$profname if [ -d $profdir ]; then if [ -r $profdir/.parentlock ]; then rm $profdir/.parentlock # Workaround for Bugzilla bug #318801 fi if [ -h $profdir/lock ]; then # The profile is locked. Ask the user how to deal with it. dispose_lock $profdir/lock fi fi fi # Handle the case where no argument was given. If there is a running # instance, try to open a new window. Otherwise, run the standard # binary. if [ $# -eq 0 ]; then if [ "$found_running" = true ]; then exec $moz_remote "xfeDoCommand(composeMessage)" else exec $MOZILLA_FIVE_HOME/$binary 2>/dev/null fi fi # Examine the argument to see if we were given an email addresses. case "$1" in *@*) # email address given: try and open compose window addresses="$1" ;; *) # No arguments or bad arguments: try and open the Inbox addresses= ;; esac # If there is a running instance, and we have a email address arguments, tell # Mozilla to open compose window with them. Otherwise, start the # standard binary with the given arguments. if [ "$found_running" = true -a -n "$addresses" ]; then exec $moz_remote "mailto($addresses)" fi exec $MOZILLA_FIVE_HOME/$binary "$@"