[19164] | 1 | #!/bin/sh |
---|
| 2 | # |
---|
[19365] | 3 | # $Id: mozilla.athena.in,v 1.5 2003-05-28 22:17:44 rbasch Exp $ |
---|
[19164] | 4 | # Mozilla wrapper script for Athena. |
---|
| 5 | |
---|
| 6 | # Set up the environment. |
---|
| 7 | moz_libdir=%MOZAPPDIR% |
---|
| 8 | if [ -z "$MOZILLA_FIVE_HOME" ]; then |
---|
| 9 | MOZILLA_FIVE_HOME=$moz_libdir |
---|
| 10 | export MOZILLA_FIVE_HOME |
---|
| 11 | fi |
---|
| 12 | |
---|
| 13 | # mozilla-xremote-client sends a command to a running mozilla using |
---|
| 14 | # X properties. Its possible return codes are: |
---|
| 15 | # 0 success |
---|
| 16 | # 1 failed to connect to the X server |
---|
| 17 | # 2 no running window found |
---|
| 18 | # 3 failed to send command |
---|
| 19 | # 4 usage error |
---|
| 20 | moz_remote=$MOZILLA_FIVE_HOME/mozilla-xremote-client |
---|
| 21 | |
---|
| 22 | # The following lockers need to be attached to run plugins and helper |
---|
| 23 | # applications. |
---|
| 24 | lockers="infoagents acro java" |
---|
| 25 | |
---|
| 26 | # Plugins (other than the default "null" plugin) live in infoagents. |
---|
| 27 | plugin_dir=/mit/infoagents/arch/@sys/lib/mozilla/plugins |
---|
| 28 | |
---|
| 29 | # Set LD_LIBRARY_PATH |
---|
| 30 | moz_lib_path=$MOZILLA_FIVE_HOME:$MOZILLA_FIVE_HOME/plugins |
---|
| 31 | LD_LIBRARY_PATH=$moz_lib_path${LD_LIBRARY_PATH:+":$LD_LIBRARY_PATH"} |
---|
| 32 | export LD_LIBRARY_PATH |
---|
| 33 | |
---|
[19321] | 34 | case `uname` in |
---|
| 35 | SunOS) |
---|
| 36 | # On Solaris, use the X server's shared memory transport for better |
---|
| 37 | # performance. |
---|
| 38 | if [ -z "$XSUNTRANSPORT" ]; then |
---|
| 39 | XSUNTRANSPORT=shmem |
---|
| 40 | XSUNSMESIZE=512 |
---|
| 41 | export XSUNTRANSPORT XSUNSMESIZE |
---|
| 42 | fi |
---|
| 43 | ;; |
---|
| 44 | Linux) |
---|
| 45 | # Set LD_ASSUME_KERNEL to avoid a java crash upon exit. |
---|
| 46 | LD_ASSUME_KERNEL=2.4.1 |
---|
| 47 | export LD_ASSUME_KERNEL |
---|
| 48 | ;; |
---|
| 49 | esac |
---|
[19164] | 50 | |
---|
| 51 | # Append our plugins directory to the plugin path. |
---|
| 52 | MOZ_PLUGIN_PATH=${MOZ_PLUGIN_PATH:+"$MOZ_PLUGIN_PATH:"}$plugin_dir |
---|
| 53 | export MOZ_PLUGIN_PATH |
---|
| 54 | |
---|
| 55 | # Prompt the user on how to deal with an existing lock file when no |
---|
| 56 | # running Mozilla window can be found, and take action accordingly. |
---|
| 57 | # Parameter 1 is the existing profile lock file path. |
---|
| 58 | # If the function returns, the lock file may have been removed per the |
---|
| 59 | # user's choice, and the caller should continue. Or, this process may |
---|
| 60 | # exit, if the user so chooses. |
---|
| 61 | dispose_lock () { |
---|
[19240] | 62 | lock=$1 |
---|
[19164] | 63 | # Extract the IP address and PID from the contents of the symlink. |
---|
[19240] | 64 | eval `ls -l $lock | awk '{ |
---|
[19164] | 65 | if (split($NF, a, ":") == 2) |
---|
| 66 | printf("lock_ip=%s ; lock_pid=%s\n", a[1], a[2]); }'` |
---|
| 67 | |
---|
| 68 | # If we cannot recognize the link contents, just continue. |
---|
| 69 | if [ -z "$lock_ip" ]; then |
---|
| 70 | return 0 |
---|
| 71 | fi |
---|
| 72 | |
---|
| 73 | # See if the lock holder is on this machine by comparing IP addresses. |
---|
| 74 | my_host=`hostname` |
---|
| 75 | if [ "$lock_ip" = "`host $my_host | awk '{ print $NF; }'`" ]; then |
---|
| 76 | # Lock is held on this machine. See if the process is running. |
---|
| 77 | if kill -0 $lock_pid 2>/dev/null ; then |
---|
[19240] | 78 | # Lock is held by a running process. |
---|
| 79 | : |
---|
[19164] | 80 | else |
---|
[19240] | 81 | # Process is no longer running. Nuke the lock and continue. |
---|
| 82 | rm -f $lock |
---|
| 83 | return 0 |
---|
[19164] | 84 | fi |
---|
| 85 | lock_host="this machine" |
---|
| 86 | else |
---|
| 87 | # Lock is held on another machine. |
---|
| 88 | # Get the host name of the lock holder. |
---|
| 89 | lock_host=`host $lock_ip | \ |
---|
| 90 | sed -n -e 's/^.*domain name pointer \(.*\)$/\1/p' | \ |
---|
| 91 | sed -e 's/\.*$//' | tr '[A-Z]' '[a-z]'` |
---|
[19240] | 92 | if [ -z "$lock_host" ]; then |
---|
| 93 | lock_host=$lock_ip |
---|
| 94 | fi |
---|
[19164] | 95 | fi |
---|
| 96 | |
---|
| 97 | dialog_text=" |
---|
[19240] | 98 | Your Mozilla profile directory contains a lock file, but no existing |
---|
| 99 | Mozilla window can be detected. The lock is owned by process $lock_pid |
---|
| 100 | on $lock_host. |
---|
[19164] | 101 | |
---|
[19240] | 102 | Note that running multiple instances of Mozilla will likely corrupt |
---|
| 103 | your profile. But, if you know for certain that this lock file is |
---|
| 104 | stale, i.e. that you are not running Mozilla on $lock_host, |
---|
| 105 | you may choose to delete the lock file and continue. |
---|
| 106 | |
---|
| 107 | Otherwise, you may choose to continue with the lock file in place, in |
---|
| 108 | which case Mozilla will display its Profile Manager, allowing you to |
---|
| 109 | select or create a different profile (Mozilla will not permit you to |
---|
| 110 | use a profile which it believes to be in use). |
---|
| 111 | |
---|
| 112 | Or, you can simply exit, leaving the lock file in place. |
---|
| 113 | " |
---|
| 114 | |
---|
[19164] | 115 | tag=`gdialog --title "Mozilla profile locked" --radiolist "$dialog_text" \ |
---|
| 116 | 60 60 3 \ |
---|
[19240] | 117 | Exit, "leaving lock file in place" on \ |
---|
| 118 | Continue, "and invoke Mozilla's Profile Manager" off \ |
---|
| 119 | Delete "lock file and proceed" off 2>&1` |
---|
[19164] | 120 | |
---|
| 121 | case "$tag" in |
---|
[19240] | 122 | *Continue*) |
---|
[19164] | 123 | ;; |
---|
[19240] | 124 | *Delete*) |
---|
[19164] | 125 | rm -f $lock |
---|
| 126 | ;; |
---|
| 127 | *) |
---|
| 128 | exit 1 |
---|
| 129 | ;; |
---|
| 130 | esac |
---|
| 131 | } |
---|
| 132 | |
---|
| 133 | # Give a warning if we're running on a dialup machine. |
---|
| 134 | if [ -x /etc/athena/dialuptype ]; then |
---|
| 135 | cat << \EOF |
---|
| 136 | |
---|
| 137 | *** PLEASE DO NOT RUN MOZILLA ON THE DIALUPS! *** |
---|
| 138 | |
---|
| 139 | Mozilla is a very large and resource-intensive program, and it is |
---|
| 140 | not appropriate to run it on a dialup machine. |
---|
| 141 | |
---|
| 142 | Please run Mozilla on your local machine rather than on a dialup. |
---|
| 143 | |
---|
| 144 | Thank you. |
---|
| 145 | |
---|
| 146 | EOF |
---|
| 147 | fi |
---|
| 148 | |
---|
| 149 | # Attach needed lockers. |
---|
| 150 | for locker in $lockers ; do |
---|
| 151 | /bin/athena/attach -h -n -q $locker |
---|
| 152 | done |
---|
| 153 | |
---|
[19365] | 154 | # Add fonts for MathML. |
---|
| 155 | infoagents_bindir=`athdir /mit/infoagents` |
---|
| 156 | if [ -x $infoagents_bindir/add-mathml-fonts ]; then |
---|
| 157 | $infoagents_bindir/add-mathml-fonts |
---|
| 158 | fi |
---|
| 159 | |
---|
[19164] | 160 | # If the user specified a profile to use, is otherwise manipulating |
---|
| 161 | # profiles, or is just looking for help, skip the check for a running |
---|
| 162 | # Mozilla, and invoke the program now. |
---|
| 163 | skip_lock_check=false |
---|
| 164 | case "$1" in |
---|
| 165 | -P|-*Profile*|-help) |
---|
| 166 | exec $MOZILLA_FIVE_HOME/mozilla-bin "$@" |
---|
| 167 | ;; |
---|
| 168 | esac |
---|
| 169 | |
---|
| 170 | # See if there is a running instance of Mozilla. |
---|
| 171 | if $moz_remote "ping()" >/dev/null 2>&1 ; then |
---|
| 172 | found_running=true |
---|
| 173 | else |
---|
| 174 | found_running=false |
---|
| 175 | fi |
---|
| 176 | |
---|
| 177 | # If Mozilla is not running, check for a (possibly stale) lock file in |
---|
| 178 | # the default profile directory. |
---|
| 179 | if [ $found_running = false ]; then |
---|
| 180 | if [ -d $HOME/.mozilla/$USER ]; then |
---|
| 181 | profdir=$HOME/.mozilla/$USER |
---|
| 182 | else |
---|
| 183 | profdir=$HOME/.mozilla/default |
---|
| 184 | fi |
---|
| 185 | if [ -d "$profdir" ]; then |
---|
| 186 | for lock in $profdir/????????.slt/lock ; do |
---|
| 187 | if [ -h $lock ]; then |
---|
| 188 | # The profile is locked. Ask the user how to deal with it. |
---|
| 189 | dispose_lock $lock |
---|
| 190 | break |
---|
| 191 | fi |
---|
| 192 | done |
---|
| 193 | fi |
---|
| 194 | fi |
---|
| 195 | |
---|
| 196 | # Handle the case where no argument was given. If there is a running |
---|
| 197 | # instance, try to open a new window. Otherwise, run the standard |
---|
| 198 | # binary. |
---|
| 199 | if [ $# -eq 0 ]; then |
---|
| 200 | if [ "$found_running" = true ]; then |
---|
| 201 | exec $moz_remote "xfeDoCommand(openBrowser)" |
---|
| 202 | else |
---|
| 203 | exec $MOZILLA_FIVE_HOME/mozilla-bin |
---|
| 204 | fi |
---|
| 205 | fi |
---|
| 206 | |
---|
| 207 | # Examine the argument to see if we were given a URL or filename. |
---|
| 208 | case "$1" in |
---|
| 209 | -*) |
---|
| 210 | # No URL argument given. |
---|
| 211 | url= |
---|
| 212 | ;; |
---|
| 213 | *:/*|/*) |
---|
| 214 | # Looks like a URL or absolute path. |
---|
| 215 | url="$1" |
---|
| 216 | ;; |
---|
| 217 | *) |
---|
| 218 | # Handle a relative path. |
---|
| 219 | if [ -e "$1" ]; then |
---|
| 220 | url="`pwd`/$1" |
---|
| 221 | else |
---|
| 222 | url="$1" |
---|
| 223 | fi |
---|
| 224 | ;; |
---|
| 225 | esac |
---|
| 226 | |
---|
| 227 | # If there is a running instance, and we have a URL argument, tell |
---|
| 228 | # Mozilla to open the URL in a new window. Otherwise, start the |
---|
| 229 | # standard binary with the given arguments. |
---|
| 230 | if [ "$found_running" = true -a -n "$url" ]; then |
---|
| 231 | exec $moz_remote "openURL($url,new-window)" |
---|
| 232 | fi |
---|
| 233 | exec $MOZILLA_FIVE_HOME/mozilla-bin "$@" |
---|