Bug 424363 - Customize Toolbar ? Restore Default Set uses gtk-refresh instead of...
[wine-gecko.git] / xulrunner / app / mozilla.in
blob00b9a8d18ae7a7b462b59beec96588861b8b3949
1 #!/bin/sh
3 # ***** BEGIN LICENSE BLOCK *****
4 # Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 # The contents of this file are subject to the Mozilla Public License Version
7 # 1.1 (the "License"); you may not use this file except in compliance with
8 # the License. You may obtain a copy of the License at
9 # http://www.mozilla.org/MPL/
11 # Software distributed under the License is distributed on an "AS IS" basis,
12 # WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 # for the specific language governing rights and limitations under the
14 # License.
16 # The Original Code is mozilla.org code.
18 # The Initial Developer of the Original Code is
19 # Netscape Communications Corporation.
20 # Portions created by the Initial Developer are Copyright (C) 1998
21 # the Initial Developer. All Rights Reserved.
23 # Contributor(s):
25 # Alternatively, the contents of this file may be used under the terms of
26 # either the GNU General Public License Version 2 or later (the "GPL"), or
27 # the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
28 # in which case the provisions of the GPL or the LGPL are applicable instead
29 # of those above. If you wish to allow use of your version of this file only
30 # under the terms of either the GPL or the LGPL, and not to allow others to
31 # use your version of this file under the terms of the MPL, indicate your
32 # decision by deleting the provisions above and replace them with the notice
33 # and other provisions required by the GPL or the LGPL. If you do not delete
34 # the provisions above, a recipient may use your version of this file under
35 # the terms of any one of the MPL, the GPL or the LGPL.
37 # ***** END LICENSE BLOCK *****
39 ## $Id: mozilla.in,v 1.4 2008/01/07 23:17:05 reed%reedloden.com Exp $
40 ##
41 ## Usage:
43 ## $ mozilla [args]
45 ## This script is meant to run the mozilla-bin binary from either
46 ## mozilla/xpfe/bootstrap or mozilla/dist/bin.
48 ## The script will setup all the environment voodoo needed to make
49 ## the mozilla-bin binary to work.
52 moz_pis_startstop_scripts()
54 MOZ_USER_DIR="%MOZ_USER_DIR%"
55 # MOZ_PIS_ is the name space for "Mozilla Plugable Init Scripts"
56 # These variables and there meaning are specified in
57 # mozilla/xpfe/bootstrap/init.d/README
58 MOZ_PIS_API=2
59 MOZ_PIS_MOZBINDIR="${dist_bin}"
60 MOZ_PIS_SESSION_PID="$$"
61 MOZ_PIS_USER_DIR="${MOZ_USER_DIR}"
62 export MOZ_PIS_API MOZ_PIS_MOZBINDIR MOZ_PIS_SESSION_PID MOZ_PIS_USER_DIR
64 case "${1}" in
65 "start")
66 for curr_pis in "${dist_bin}/init.d"/S* "${HOME}/${MOZ_USER_DIR}/init.d"/S* ; do
67 if [ -x "${curr_pis}" ] ; then
68 case "${curr_pis}" in
69 *.sh) . "${curr_pis}" ;;
70 *) "${curr_pis}" "start" ;;
71 esac
73 done
75 "stop")
76 for curr_pis in "${HOME}/${MOZ_USER_DIR}/init.d"/K* "${dist_bin}/init.d"/K* ; do
77 if [ -x "${curr_pis}" ] ; then
78 case "${curr_pis}" in
79 *.sh) . "${curr_pis}" ;;
80 *) "${curr_pis}" "stop" ;;
81 esac
83 done
86 echo 1>&2 "$0: Internal error in moz_pis_startstop_scripts."
87 exit 1
89 esac
92 #uncomment for debugging
93 #set -x
95 moz_libdir=%MOZAPPDIR%
96 MRE_HOME=%MREDIR%
98 # Use run-mozilla.sh in the current dir if it exists
99 # If not, then start resolving symlinks until we find run-mozilla.sh
100 found=0
101 progname="$0"
102 curdir=`dirname "$progname"`
103 progbase=`basename "$progname"`
104 profile=""
105 run_moz="$curdir/run-mozilla.sh"
106 if test -x "$run_moz"; then
107 dist_bin="$curdir"
108 found=1
109 else
110 here=`/bin/pwd`
111 while [ -h "$progname" ]; do
112 bn=`basename "$progname"`
113 cd `dirname "$progname"`
114 progname=`/bin/ls -l "$bn" | sed -e 's/^.* -> //' `
115 progbase=`basename "$progname"`
116 if [ ! -x "$progname" ]; then
117 break
119 curdir=`dirname "$progname"`
120 run_moz="$curdir/run-mozilla.sh"
121 if [ -x "$run_moz" ]; then
122 cd "$curdir"
123 dist_bin=`pwd`
124 found=1
125 break
127 done
128 cd "$here"
130 if [ $found = 0 ]; then
131 # Check default compile-time libdir
132 if [ -x "$moz_libdir/run-mozilla.sh" ]; then
133 dist_bin="$moz_libdir"
134 else
135 echo "Cannot find mozilla runtime directory. Exiting."
136 exit 1
140 script_args=""
141 debugging=0
142 MOZILLA_BIN="${progbase}-bin"
143 MOZ_CLIENT_PROGRAM="$dist_bin/mozilla-xremote-client"
145 run_xremote_client() {
146 if [ -n "${profile}" ]; then
147 "${run_moz}" "$MOZ_CLIENT_PROGRAM" -a "${progbase}" -p "${profile}" "$1"
148 else
149 "${run_moz}" "$MOZ_CLIENT_PROGRAM" -a "${progbase}" "$1"
153 # The following is to check for a currently running instance.
154 # This is taken almost verbatim from the Mozilla RPM package's launch script.
155 check_running() {
156 run_xremote_client 'ping()' 2>/dev/null >/dev/null
157 RETURN_VAL=$?
158 if [ $RETURN_VAL -eq 0 ]; then
159 echo 1
160 return 1
161 else
162 echo 0
163 return 0
167 if [ "$OSTYPE" = "beos" ]; then
168 mimeset -F "$MOZILLA_BIN"
171 ################################################################ Parse Arguments
172 # If there's a command line argument but it doesn't begin with a -
173 # it's probably a url. Try to send it to a running instance.
174 _USE_EXIST=0
175 _NEW_WINDOW=
176 _optOne="$1"
177 case "${_optOne}" in
178 -*)
181 _USE_EXIST=1
183 esac
185 _optOthers=
186 _optLast=
187 for i in "$@"; do
188 _optLast="${i}"
189 done #last arg
191 for i in "$@"; do
192 [ "$i" = "${_optLast}" ] && break
193 _optOthers="${_optOthers} ${i}"
194 done #others arg
196 #???: needs check if othersopt begin with -* ?
197 if [ `expr "${_optLast}" : '.*:/.*'` -eq 0 -a \( -f "${_optLast}" -o -d "${_optLast}" \) ]; then
198 # Last argument seems to be a local file/directory
199 # Check, if it is absolutely specified (ie. /home/foo/file vs. ./file)
200 # If it is just "relatively" (./file) specified, make it absolutely
201 [ `expr "${_optLast}" : '/.*'` -eq 0 ] && _optLast="file://`pwd`/${_optLast}"
202 elif [ `expr "${_optLast}" : '.*:/.*'` -gt 0 -o -n "${_optOthers}" ]; then #???? like before...
203 _NEW_WINDOW=1
206 # check for -P argument used to select a user profile
207 _expectProfileName=0
208 for i in "$@"; do
209 if [ "$i" = "-P" ]; then
210 _expectProfileName=1
211 profile=""
212 elif [ ${_expectProfileName} = 1 ]; then
213 _expectProfileName=0
214 profile="$i"
216 done
218 ################################################################ Parse Arguments
220 ########################################################################### Main
221 ALREADY_RUNNING=`check_running`
223 if [ $ALREADY_RUNNING -eq 1 ]; then
224 # There's an instance already running. Use it.
225 # Any command line args passed in?
226 if [ $# -gt 0 ]; then
227 # There were "some" command line args.
228 if [ ${_USE_EXIST} -eq 1 ]; then
229 # We should use an existing instance, as _USE_EXIST=$_USE_EXIST=-1
230 _open_type="window"
231 #_open_type="tab"
232 _remote_cmd="openURL(${_optLast} , new-${_open_type})"
233 run_xremote_client "${_remote_cmd}"
234 unset _remote_cmd _open_type
235 exit $?
237 else
238 # No command line args. Open new window/tab
239 run_xremote_client "xfeDoCommand(openBrowser)"
240 exit $?
243 # Default action - no running instance or _USE_EXIST (${_USE_EXIST}) ! -eq 1
244 ########################################################################### Main
246 pass_arg_count=0
247 while [ $# -gt $pass_arg_count ]
249 case "$1" in
250 -p | --pure | -pure)
251 MOZILLA_BIN="${MOZILLA_BIN}.pure"
252 shift
254 -g | --debug)
255 script_args="$script_args -g"
256 debugging=1
257 shift
259 -d | --debugger)
260 script_args="$script_args -d $2"
261 shift 2
264 # Move the unrecognized argument to the end of the list.
265 arg="$1"
266 shift
267 set -- "$@" "$arg"
268 pass_arg_count=`expr $pass_arg_count + 1`
270 esac
271 done
273 export MRE_HOME
275 ## Start addon scripts
276 moz_pis_startstop_scripts "start"
278 if [ $debugging = 1 ]
279 then
280 echo $dist_bin/run-mozilla.sh $script_args $dist_bin/$MOZILLA_BIN "$@"
282 "$dist_bin/run-mozilla.sh" $script_args "$dist_bin/$MOZILLA_BIN" "$@"
283 exitcode=$?
285 ## Stop addon scripts
286 moz_pis_startstop_scripts "stop"
288 exit $exitcode
289 # EOF.