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