| 1 |
#!/bin/bash
|
| 2 |
# $Header: /var/cvsroot/gentoo-src/mozilla-launcher/mozilla-launcher,v 1.57 2008/01/01 14:07:46 armin76 Exp $
|
| 3 |
#
|
| 4 |
# Portions of this file are extracted from the mozilla.org distributed scripts.
|
| 5 |
# Those portions are Copyright (C) 1998 Netscape Communmications Corporation and
|
| 6 |
# released under the NPL as detailed in
|
| 7 |
# /usr/lib/mozilla-firefox/firefox and /usr/lib/mozilla-thunderbird/thunderbird.
|
| 8 |
#
|
| 9 |
# The remainder of this file is Copyright 1999-2008 Gentoo Foundation
|
| 10 |
# Distributed under the terms of the GNU General Public License v2
|
| 11 |
|
| 12 |
: ${MOZILLA_LAUNCHER_DEBUG:=false}
|
| 13 |
|
| 14 |
# Make sure necessary progs are in the PATH
|
| 15 |
PATH=/usr/bin:/bin:$PATH
|
| 16 |
unset GREP_OPTIONS
|
| 17 |
|
| 18 |
main() {
|
| 19 |
declare args mozargs urls u i mozpid debugger debugging=false
|
| 20 |
declare candidates retval=0 progname
|
| 21 |
declare zero=${0##*/}
|
| 22 |
|
| 23 |
# We'd like to believe that we were called via one of the symlinks in
|
| 24 |
# /usr/bin. However OOo sports some questionable behavior: it follows the
|
| 25 |
# symlinks instead of relying on UNIX filesystem semantics, so $zero is
|
| 26 |
# "/usr/libexec/mozilla-launcher" in that case. We workaround this
|
| 27 |
# misbehavior by using a stub in /usr/bin instead of a symlink. The stub sets
|
| 28 |
# MOZILLA_LAUNCHER and execs /usr/libexec/mozilla-launcher
|
| 29 |
[[ -n $MOZILLA_LAUNCHER ]] && zero=$MOZILLA_LAUNCHER
|
| 30 |
unset MOZILLA_LAUNCHER
|
| 31 |
|
| 32 |
# Determine if we're called as firefox or mozilla and set up
|
| 33 |
# variables appropriately
|
| 34 |
which_browser || exit 1 # note: modifies $zero
|
| 35 |
|
| 36 |
# Parse the command-line and set args, mozargs and urls
|
| 37 |
parse_cmdline "$@" || exit 1
|
| 38 |
|
| 39 |
# Make sure we'll get at least an empty window/tab
|
| 40 |
# when nothing else is specified on the cmdline.
|
| 41 |
if [[ $# -eq 0 && ${#mozargs[@]} == 0 ]]; then
|
| 42 |
if [[ $zero == sunbird* ]]; then
|
| 43 |
args=-calendar
|
| 44 |
else
|
| 45 |
urls=('')
|
| 46 |
fi
|
| 47 |
fi
|
| 48 |
|
| 49 |
# Set the candidates array with find_running
|
| 50 |
find_running
|
| 51 |
|
| 52 |
# Handle some special args. We want to handle these ourselves so
|
| 53 |
# that we can find the right window on the screen to target.
|
| 54 |
set -- "${mozargs[@]}"
|
| 55 |
while [[ $# -gt 0 ]]; do
|
| 56 |
case $1 in
|
| 57 |
-mail) try_running 'xfeDoCommand(openInbox)' ;;
|
| 58 |
-compose)
|
| 59 |
if [[ -n $2 ]]; then
|
| 60 |
try_running "xfeDoCommand(composeMessage,$2)" && shift
|
| 61 |
else
|
| 62 |
try_running "xfeDoCommand(composeMessage)"
|
| 63 |
fi ;;
|
| 64 |
-remote) try_running "$2" && shift ;;
|
| 65 |
*) false ;;
|
| 66 |
esac
|
| 67 |
[[ $? -eq 0 ]] && { shift; continue; }
|
| 68 |
# Error path: try_running failed, so prepend remaining mozargs to
|
| 69 |
# args and drop through to call the browser binary
|
| 70 |
args=("$@" "${args[@]}")
|
| 71 |
break
|
| 72 |
done
|
| 73 |
|
| 74 |
# If there's no running browser, or we've got args, start an
|
| 75 |
# instance.
|
| 76 |
if [[ ${#args[@]} -gt 0 ]] || ! try_running 'ping()'; then
|
| 77 |
# Assume the first url should just be tacked on the end.
|
| 78 |
try_start "${args[@]}" ${urls:+"${urls[0]}"} || exit
|
| 79 |
mozpid=$!
|
| 80 |
set -- "${urls[@]}"; shift; urls=("$@") # shift off the first url
|
| 81 |
candidates=$DISPLAY
|
| 82 |
args=()
|
| 83 |
|
| 84 |
# Handle case of multiple URLs by waiting for browser to map to
|
| 85 |
# the screen so that it can be found by $remote below
|
| 86 |
if [[ ${#urls[@]} -gt 0 ]]; then
|
| 87 |
if [[ -x /usr/bin/xtoolwait ]]; then
|
| 88 |
xtoolwait sleep 10 # hope it hasn't mapped yet
|
| 89 |
else
|
| 90 |
sleep 1
|
| 91 |
for ((i = 0; i < 40; i = i + 1)); do
|
| 92 |
try_running 'ping()' && break || sleep 0.25
|
| 93 |
done
|
| 94 |
fi
|
| 95 |
fi
|
| 96 |
fi
|
| 97 |
|
| 98 |
# Handle multiple URLs by looping over the xremote call
|
| 99 |
for u in "${urls[@]}"; do
|
| 100 |
u="$(sanitize_url $u)"
|
| 101 |
if [[ $u == mailto:* ]]; then
|
| 102 |
try_running "mailto(${u#mailto:})" || retval=$?
|
| 103 |
else
|
| 104 |
if [[ -n $MOZILLA_NEWTYPE ]]; then
|
| 105 |
try_running "openURL($u,new-$MOZILLA_NEWTYPE)" || retval=$?
|
| 106 |
elif [[ ( $zero == firefox* || $zero == seamonkey* ) && -n $u ]]; then
|
| 107 |
# Don't override preferences set in the browser #82653
|
| 108 |
try_running "openURL($u)" || retval=$?
|
| 109 |
elif [[ -n $u ]]; then
|
| 110 |
try_running "openURL($u,new-window)" || retval=$?
|
| 111 |
else
|
| 112 |
try_running "xfeDoCommand(openBrowser)" || retval=$?
|
| 113 |
fi
|
| 114 |
fi
|
| 115 |
done
|
| 116 |
|
| 117 |
# Will only wait here if browser was started by this script
|
| 118 |
if [[ -n ${mozpid} ]]; then
|
| 119 |
wait ${mozpid}
|
| 120 |
retval=$?
|
| 121 |
[[ ${retval} == 0 ]] \
|
| 122 |
|| echo "${mozbin##*/} exited with non-zero status (${retval})" >&2
|
| 123 |
moz_pis_startstop_scripts stop
|
| 124 |
fi
|
| 125 |
|
| 126 |
exit $retval
|
| 127 |
}
|
| 128 |
|
| 129 |
which_browser() {
|
| 130 |
# Newer launcher stubs will set MOZILLA_LIBDIR so that the installation
|
| 131 |
# location is controlled by the ebuild rather than mozilla-launcher, finally!
|
| 132 |
if [[ ! -d $MOZILLA_LIBDIR ]]; then
|
| 133 |
unset MOZILLA_LIBDIR
|
| 134 |
fi
|
| 135 |
|
| 136 |
# Support mozilla-firefox, mozilla-firefox-bin, mozilla-thunderbird,
|
| 137 |
# mozilla-thunderbird-bin, mozilla-sunbird, mozilla-sunbird-bin,
|
| 138 |
# xulrunner!
|
| 139 |
# This case statement does the setup for source-based browsers and
|
| 140 |
# just drops through for binary-based browsers.
|
| 141 |
case $zero in
|
| 142 |
*fox)
|
| 143 |
export MOZILLA_FIVE_HOME=${MOZILLA_LIBDIR:-"/usr/lib/mozilla-firefox"}
|
| 144 |
remote=$MOZILLA_FIVE_HOME/mozilla-xremote-client
|
| 145 |
mozbin=$MOZILLA_FIVE_HOME/firefox-bin
|
| 146 |
;;
|
| 147 |
|
| 148 |
*sunbird)
|
| 149 |
export MOZILLA_FIVE_HOME=${MOZILLA_LIBDIR:-"/usr/lib/mozilla-sunbird"}
|
| 150 |
remote=$MOZILLA_FIVE_HOME/mozilla-xremote-client
|
| 151 |
mozbin=$MOZILLA_FIVE_HOME/sunbird-bin
|
| 152 |
;;
|
| 153 |
|
| 154 |
*thunderbird)
|
| 155 |
export MOZILLA_FIVE_HOME=${MOZILLA_LIBDIR:-"/usr/lib/mozilla-thunderbird"}
|
| 156 |
remote=$MOZILLA_FIVE_HOME/mozilla-xremote-client
|
| 157 |
mozbin=$MOZILLA_FIVE_HOME/thunderbird-bin
|
| 158 |
;;
|
| 159 |
|
| 160 |
*seamonkey)
|
| 161 |
export MOZILLA_FIVE_HOME=${MOZILLA_LIBDIR:-"/usr/lib/seamonkey"}
|
| 162 |
remote=$MOZILLA_FIVE_HOME/mozilla-xremote-client
|
| 163 |
mozbin=$MOZILLA_FIVE_HOME/seamonkey-bin
|
| 164 |
;;
|
| 165 |
|
| 166 |
*xulrunner)
|
| 167 |
export MOZILLA_FIVE_HOME=${MOZILLA_LIBDIR:-"/usr/lib/xulrunner"}
|
| 168 |
remote=$MOZILLA_FIVE_HOME/mozilla-xremote-client
|
| 169 |
mozbin=$MOZILLA_FIVE_HOME/xulrunner-bin
|
| 170 |
xulparams=$XUL_PARAMS
|
| 171 |
;;
|
| 172 |
|
| 173 |
*-bin)
|
| 174 |
unset mozbin # just in case...
|
| 175 |
;; # but don't do anything yet
|
| 176 |
|
| 177 |
*)
|
| 178 |
echo "$0: unknown browser" >&2
|
| 179 |
return 1
|
| 180 |
;;
|
| 181 |
esac
|
| 182 |
|
| 183 |
# Attempt to use -bin version if source version isn't available
|
| 184 |
if [[ -n $mozbin && ! -f $mozbin ]]; then
|
| 185 |
unset mozbin # it's bogus anyway
|
| 186 |
zero=${zero}-bin
|
| 187 |
fi
|
| 188 |
|
| 189 |
case $zero in
|
| 190 |
*fox-bin)
|
| 191 |
export MOZILLA_FIVE_HOME=${MOZILLA_LIBDIR:-"/opt/firefox"}
|
| 192 |
remote=$MOZILLA_FIVE_HOME/mozilla-xremote-client
|
| 193 |
mozbin=$MOZILLA_FIVE_HOME/firefox-bin
|
| 194 |
;;
|
| 195 |
|
| 196 |
*sunbird-bin)
|
| 197 |
export MOZILLA_FIVE_HOME=${MOZILLA_LIBDIR:-"/opt/sunbird"}
|
| 198 |
remote=$MOZILLA_FIVE_HOME/mozilla-xremote-client
|
| 199 |
mozbin=$MOZILLA_FIVE_HOME/sunbird-bin
|
| 200 |
;;
|
| 201 |
|
| 202 |
*thunderbird-bin)
|
| 203 |
export MOZILLA_FIVE_HOME=${MOZILLA_LIBDIR:-"/opt/thunderbird"}
|
| 204 |
remote=$MOZILLA_FIVE_HOME/mozilla-xremote-client
|
| 205 |
mozbin=$MOZILLA_FIVE_HOME/thunderbird-bin
|
| 206 |
;;
|
| 207 |
|
| 208 |
*seamonkey-bin)
|
| 209 |
export MOZILLA_FIVE_HOME=${MOZILLA_LIBDIR:-"/opt/seamonkey"}
|
| 210 |
remote=$MOZILLA_FIVE_HOME/mozilla-xremote-client
|
| 211 |
mozbin=$MOZILLA_FIVE_HOME/seamonkey-bin
|
| 212 |
;;
|
| 213 |
esac
|
| 214 |
|
| 215 |
# Make sure we got something
|
| 216 |
if [[ -z $mozbin || ! -f $mozbin ]]; then
|
| 217 |
echo "$0: can't find the browser :-(" >&2
|
| 218 |
return 1
|
| 219 |
fi
|
| 220 |
|
| 221 |
# Newer xremote has the ability to specify a target program. Base
|
| 222 |
# this on ${zero} but workaround bug 247754 for thunderbird
|
| 223 |
progname=${zero%-bin}
|
| 224 |
if [[ $progname == thunderbird ]]; then
|
| 225 |
grep -q '"0\.[78]"' ${MOZILLA_FIVE_HOME}/defaults/pref/*.js \
|
| 226 |
&& progname=Thunderbird
|
| 227 |
fi
|
| 228 |
|
| 229 |
# Set LD_LIBRARY_PATH (also set in /etc/env.d/10*)
|
| 230 |
export LD_LIBRARY_PATH=$MOZILLA_FIVE_HOME:$MOZILLA_FIVE_HOME/plugins${LD_LIBRARY_PATH:+:$LD_LIBRARY_PATH}
|
| 231 |
|
| 232 |
# Make sure netscape-compatible plugins are picked up
|
| 233 |
[[ -z $MOZ_PLUGIN_PATH ]] && export MOZ_PLUGIN_PATH=/usr/lib/nsbrowser/plugins
|
| 234 |
|
| 235 |
return 0
|
| 236 |
}
|
| 237 |
|
| 238 |
# parse_cmdline: set args, mozargs and urls, which are dynamically
|
| 239 |
# scoped in main()
|
| 240 |
parse_cmdline() {
|
| 241 |
# Validate the args and extract the urls
|
| 242 |
args=() # general arguments
|
| 243 |
mozargs=() # arguments that we handle specifically
|
| 244 |
urls=() # urls to open
|
| 245 |
while [[ $# -ne 0 ]] ; do
|
| 246 |
if [[ $1 == -* ]] ; then
|
| 247 |
case "${1#-}" in
|
| 248 |
# options we handle specially
|
| 249 |
g|-debug)
|
| 250 |
debugging=true
|
| 251 |
shift 1 ;;
|
| 252 |
d|-debugger)
|
| 253 |
debugging=true
|
| 254 |
debugger=$2
|
| 255 |
shift 2 ;;
|
| 256 |
a)
|
| 257 |
# ignore -a which xfhelp4 passes for no reason
|
| 258 |
shift 2 ;;
|
| 259 |
register)
|
| 260 |
# just do this immediately
|
| 261 |
update_chrome
|
| 262 |
exit $? ;;
|
| 263 |
unregister)
|
| 264 |
# just do this immediately
|
| 265 |
remove_chrome
|
| 266 |
exit $? ;;
|
| 267 |
# mozargs with 0 arguments
|
| 268 |
mail)
|
| 269 |
mozargs=("${mozargs[@]}" "$1")
|
| 270 |
shift 1 ;;
|
| 271 |
# mozargs with 0 or 1 arguments
|
| 272 |
compose|remote)
|
| 273 |
if [[ -n $2 ]]; then
|
| 274 |
mozargs=("${mozargs[@]}" "$1" "$2")
|
| 275 |
shift 2
|
| 276 |
else
|
| 277 |
mozargs=("${mozargs[@]}" "$1")
|
| 278 |
shift 1
|
| 279 |
fi ;;
|
| 280 |
# options we pass through 1 argument
|
| 281 |
height|width|CreateProfile|P|UILocale|contentLocale|edit|chrome)
|
| 282 |
args=("${args[@]}" "$1" "$2")
|
| 283 |
shift 2 ;;
|
| 284 |
# unrecognized options are simply passed through
|
| 285 |
*)
|
| 286 |
args=("${args[@]}" "$1")
|
| 287 |
shift 1 ;;
|
| 288 |
esac
|
| 289 |
else
|
| 290 |
if [[ $1 == *://*/* ]]; then
|
| 291 |
urls=("${urls[@]}" "$1")
|
| 292 |
elif [[ $1 == *://* ]]; then
|
| 293 |
# as of mozilla_1.7_rc1 the url checking changed for xremote
|
| 294 |
# calls... now three slashes are required for urls, otherwise we
|
| 295 |
# get the following error from xremote:
|
| 296 |
# Error: Failed to send command: 509 internal error
|
| 297 |
urls=("${urls[@]}" "$1/")
|
| 298 |
elif [[ $1 != /* && -e $1 ]]; then
|
| 299 |
# relative path to a file, transform to URL syntax
|
| 300 |
urls=("${urls[@]}" "file://$PWD/$1")
|
| 301 |
elif [[ $1 == /* && -e $1 ]]; then
|
| 302 |
# absolute path to a file, transform to URL syntax
|
| 303 |
urls=("${urls[@]}" "file://$1")
|
| 304 |
elif [[ $1 != *:* && $1 == *@* ]]; then
|
| 305 |
# looks like an email address, prefix with mailto: so we can
|
| 306 |
# recognize it later.
|
| 307 |
urls=("${urls[@]}" "mailto:$1")
|
| 308 |
else
|
| 309 |
# no idea what this is! just add it to urls and hope it works
|
| 310 |
urls=("${urls[@]}" "$1")
|
| 311 |
fi
|
| 312 |
shift
|
| 313 |
fi
|
| 314 |
done
|
| 315 |
|
| 316 |
return 0
|
| 317 |
}
|
| 318 |
|
| 319 |
# find_running: sets the candidates array
|
| 320 |
find_running() {
|
| 321 |
declare screens s
|
| 322 |
|
| 323 |
# Try to start in an existing session; check all screens
|
| 324 |
# with priority on the current screen.
|
| 325 |
#
|
| 326 |
# If xdpyinfo isn't installed, then this will just check $DISPLAY
|
| 327 |
screens=("$DISPLAY"
|
| 328 |
$(xdpyinfo 2>/dev/null | awk '
|
| 329 |
/^name of display:/ {
|
| 330 |
disp = substr($NF, 0, match($NF, /\.[^.]*$/)-1)
|
| 331 |
}
|
| 332 |
/^number of screens:/ {
|
| 333 |
for (i = 0; i < $NF; i++) {
|
| 334 |
this = sprintf("%s.%d", disp, i)
|
| 335 |
if (this != ENVIRON["DISPLAY"])
|
| 336 |
print this
|
| 337 |
}
|
| 338 |
}')
|
| 339 |
)
|
| 340 |
|
| 341 |
# We used to check displays with xwininfo here but that isn't
|
| 342 |
# necessary with the advent of -a programname.
|
| 343 |
# Instead just test for a running program if we're on a local
|
| 344 |
# display.
|
| 345 |
if [[ $DISPLAY != :* ]] || killall -0 ${mozbin##*/} &>/dev/null; then
|
| 346 |
candidates=("${screens[@]}")
|
| 347 |
else
|
| 348 |
candidates=()
|
| 349 |
fi
|
| 350 |
}
|
| 351 |
|
| 352 |
# try_running: try to use an existing browser to run a command
|
| 353 |
try_running() {
|
| 354 |
declare s retval=2 # default == can't find an instance
|
| 355 |
|
| 356 |
# Try mozilla-xremote-client on each candidate screen.
|
| 357 |
for s in "${candidates[@]}"; do
|
| 358 |
DISPLAY=$s $remote -a ${progname} "$@"
|
| 359 |
retval=$?
|
| 360 |
if [[ $retval -eq 0 ]]; then
|
| 361 |
candidates=("$s") # for future calls
|
| 362 |
return 0
|
| 363 |
fi
|
| 364 |
done
|
| 365 |
|
| 366 |
# Might as well do this error interpretation here
|
| 367 |
case $retval in
|
| 368 |
1) echo "Unable to connect to X server" >&2 ;;
|
| 369 |
2) echo "No running windows found" >&2 ;;
|
| 370 |
3) echo "Browser doesn't understand command" >&2 ;;
|
| 371 |
*) echo "Unknown error $retval from mozilla-xremote-client" >&2 ;;
|
| 372 |
esac
|
| 373 |
|
| 374 |
return $retval
|
| 375 |
}
|
| 376 |
|
| 377 |
# set_debugger: set $debugger
|
| 378 |
set_debugger() {
|
| 379 |
declare d
|
| 380 |
: ${debugger:=ddd gdb}
|
| 381 |
|
| 382 |
# Try to find a workable debugger
|
| 383 |
for d in ${debugger}; do
|
| 384 |
type -fp $d &>/dev/null || continue
|
| 385 |
debugger=$d
|
| 386 |
return 0
|
| 387 |
done
|
| 388 |
|
| 389 |
echo "Can't find debugger (${debugger})" >&2
|
| 390 |
exit 1
|
| 391 |
}
|
| 392 |
|
| 393 |
# try_start: attempt to start a browser
|
| 394 |
try_start() {
|
| 395 |
declare f
|
| 396 |
|
| 397 |
# shouldn't have files in profile that are owned by a user other
|
| 398 |
# than the current one. http://bugs.gentoo.org/show_bug.cgi?id=59849
|
| 399 |
f=$(find ~/{.,.mozilla/}${zero%-bin} ! -uid ${EUID} 2>/dev/null | head -n10)
|
| 400 |
if [[ -n ${f} ]]; then
|
| 401 |
[[ ${zero} == "thunderbird" ]] && hint="thunderbird" || hint="mozilla"
|
| 402 |
cat <<EOF
|
| 403 |
Error launching ${zero}:
|
| 404 |
|
| 405 |
There are files in your profile that are owned by a user other than
|
| 406 |
$(id -un). ${zero} can't execute in this condition. Here are some of
|
| 407 |
the files that I found:
|
| 408 |
EOF
|
| 409 |
echo "${f}" | sed 's/^/ /'
|
| 410 |
(( $(echo "${f}" | wc -l) == 10 )) && echo " ..."
|
| 411 |
echo
|
| 412 |
echo "You can fix this problem by running the following:"
|
| 413 |
echo " su -c 'chown -R $(id -un):$(id -gn) $HOME/.${hint}'"
|
| 414 |
echo
|
| 415 |
return 101
|
| 416 |
fi >&2
|
| 417 |
|
| 418 |
# compreg.dat and/or chrome.rdf will screw things up if it's from an
|
| 419 |
# older version. http://bugs.gentoo.org/show_bug.cgi?id=63999
|
| 420 |
for f in ~/{.,.mozilla/}${zero%-bin}/*/{compreg.dat,chrome.rdf,XUL.mfasl}; do
|
| 421 |
if [[ -f ${f} && ${f} -ot ${mozbin} ]]; then
|
| 422 |
echo "Removing ${f} leftover from older ${zero%-bin}"
|
| 423 |
rm -f "${f}"
|
| 424 |
fi
|
| 425 |
done
|
| 426 |
|
| 427 |
moz_pis_startstop_scripts start
|
| 428 |
|
| 429 |
if $debugging && set_debugger; then
|
| 430 |
for v in MOZILLA_FIVE_HOME LD_LIBRARY_PATH LD_LIBRARYN32_PATH \
|
| 431 |
LD_LIBRARYN64_PATH LD_LIBRARY_PATH_64 DISPLAY XPSERVERLIST \
|
| 432 |
MOZILLA_POSTSCRIPT_PRINTER_LIST DYLD_LIBRARY_PATH LIBRARY_PATH \
|
| 433 |
SHLIB_PATH LIBPATH ADDON_PATH MOZ_PROGRAM MOZ_TOOLKIT debugger; do
|
| 434 |
[[ -n ${!v} ]] && printf "%31s=%s\n" "$v" "${!v}"
|
| 435 |
done
|
| 436 |
echo
|
| 437 |
|
| 438 |
# Note that --args works for gdb and ddd. Other debuggers will need another
|
| 439 |
# method if added to this script.
|
| 440 |
$(type -P aoss) "$debugger" --args "$mozbin" $xulparams "$@"
|
| 441 |
|
| 442 |
# Don't try to load additional URLs if debugging
|
| 443 |
unset urls
|
| 444 |
else
|
| 445 |
case " $* " in
|
| 446 |
*' -ProfileManager '*|*' -P '*)
|
| 447 |
# bug 114683: -ProfileManager doesn't work with DeerPark
|
| 448 |
MOZ_NO_REMOTE=1 $(type -P aoss) "$mozbin" $xulparams "$@" &
|
| 449 |
;;
|
| 450 |
*)
|
| 451 |
$(type -P aoss) "$mozbin" $xulparams "$@" &
|
| 452 |
;;
|
| 453 |
esac
|
| 454 |
fi
|
| 455 |
}
|
| 456 |
|
| 457 |
moz_pis_startstop_scripts() {
|
| 458 |
eval $(grep -m1 MOZ_USER_DIR= $MOZILLA_FIVE_HOME/${zero%-bin})
|
| 459 |
# MOZ_PIS_ is the name space for "Mozilla Plugable Init Scripts"
|
| 460 |
# These variables and there meaning are specified in
|
| 461 |
# mozilla/xpfe/bootstrap/init.d/README
|
| 462 |
MOZ_PIS_API=2
|
| 463 |
MOZ_PIS_MOZBINDIR="${dist_bin}"
|
| 464 |
MOZ_PIS_SESSION_PID="$$"
|
| 465 |
MOZ_PIS_USER_DIR="${MOZ_USER_DIR}"
|
| 466 |
export MOZ_PIS_API MOZ_PIS_MOZBINDIR MOZ_PIS_SESSION_PID MOZ_PIS_USER_DIR
|
| 467 |
|
| 468 |
case "${1}" in
|
| 469 |
"start")
|
| 470 |
for curr_pis in "${dist_bin}/init.d"/S* "${HOME}/${MOZ_USER_DIR}/init.d"/S* ; do
|
| 471 |
if [ -x "${curr_pis}" ] ; then
|
| 472 |
case "${curr_pis}" in
|
| 473 |
*.sh) . "${curr_pis}" ;;
|
| 474 |
*) "${curr_pis}" "start" ;;
|
| 475 |
esac
|
| 476 |
fi
|
| 477 |
done
|
| 478 |
;;
|
| 479 |
"stop")
|
| 480 |
for curr_pis in "${HOME}/${MOZ_USER_DIR}/init.d"/K* "${dist_bin}/init.d"/K* ; do
|
| 481 |
if [ -x "${curr_pis}" ] ; then
|
| 482 |
case "${curr_pis}" in
|
| 483 |
*.sh) . "${curr_pis}" ;;
|
| 484 |
*) "${curr_pis}" "stop" ;;
|
| 485 |
esac
|
| 486 |
fi
|
| 487 |
done
|
| 488 |
;;
|
| 489 |
*)
|
| 490 |
echo 1>&2 "$0: Internal error in moz_pis_startstop_scripts."
|
| 491 |
exit 1
|
| 492 |
;;
|
| 493 |
esac
|
| 494 |
}
|
| 495 |
|
| 496 |
remove_chrome() {
|
| 497 |
if [[ $UID != 0 ]]; then
|
| 498 |
echo "$0: You need to be root to update the registry" >&2
|
| 499 |
return 1
|
| 500 |
fi
|
| 501 |
|
| 502 |
rm -rf ${MOZILLA_FIVE_HOME}/chrome/overlayinfo
|
| 503 |
rm -f ${MOZILLA_FIVE_HOME}/chrome/chrome.rdf
|
| 504 |
rm -f ${MOZILLA_FIVE_HOME}/extensions/installed-extensions-processed.txt
|
| 505 |
rm -f ${MOZILLA_FIVE_HOME}/extensions/Extensions.rdf
|
| 506 |
rm -f ${MOZILLA_FIVE_HOME}/extensions/installed-extensions.txt
|
| 507 |
rm -f ${MOZILLA_FIVE_HOME}/chrome/installed-chrome.txt
|
| 508 |
|
| 509 |
return 0
|
| 510 |
}
|
| 511 |
|
| 512 |
update_chrome() {
|
| 513 |
if [[ $UID != 0 ]]; then
|
| 514 |
echo "$0: You need to be root to update the registry" >&2
|
| 515 |
return 1
|
| 516 |
fi
|
| 517 |
|
| 518 |
# The -bin packages don't support updating the registry, at least not yet.
|
| 519 |
# regxpcom and regchrome are missing from firefox-bin and thunderbird-bin, and
|
| 520 |
# there should be no need to run mozilla-rebuild-databases.pl with mozilla-bin
|
| 521 |
if [[ ${zero} == *-bin ]]; then
|
| 522 |
echo "$0: update_chrome doesn't support ${zero}"
|
| 523 |
return 1
|
| 524 |
fi
|
| 525 |
|
| 526 |
# seamonkey doesn't support -register yet. Until it does, use the
|
| 527 |
# seamonkey-rebuild-databases.pl script instead
|
| 528 |
if [[ ${zero} == seamonkey ]]; then
|
| 529 |
echo "Running seamonkey-rebuild-databases.pl"
|
| 530 |
umask 022
|
| 531 |
${MOZILLA_FIVE_HOME}/seamonkey-rebuild-databases.pl
|
| 532 |
return $?
|
| 533 |
fi
|
| 534 |
|
| 535 |
echo "Updating ${zero} chrome registry..."
|
| 536 |
umask 022
|
| 537 |
export PATH=${MOZILLA_FIVE_HOME}:${PATH}
|
| 538 |
export HOME=$(mktemp -d /tmp/${zero}-register.XXXXXX)
|
| 539 |
declare libdir=${MOZILLA_FIVE_HOME}
|
| 540 |
declare extdir=${libdir}/extensions.d
|
| 541 |
declare chrdir=${libdir}/chrome.d
|
| 542 |
|
| 543 |
# set up libdir
|
| 544 |
remove_chrome || return 1
|
| 545 |
mkdir -p ${libdir}/chrome/overlayinfo
|
| 546 |
mkdir -p ${libdir}/extensions
|
| 547 |
|
| 548 |
# generate installed-extensions.txt
|
| 549 |
:> ${libdir}/extensions/installed-extensions.txt
|
| 550 |
chmod 0644 ${libdir}/extensions/installed-extensions.txt
|
| 551 |
for f in $(ls -d ${extdir}/* 2>/dev/null); do
|
| 552 |
while read line; do
|
| 553 |
extuid=$(echo ${line} | cut -f 2 -d ,)
|
| 554 |
extuiddir=${libdir}/extensions/${extuid}
|
| 555 |
if [[ ! -e ${extuiddir} ]]; then
|
| 556 |
echo "W: ${f}: ${extuiddir} doesn't exist." >&2
|
| 557 |
elif [[ ! -e ${extuiddir}/install.rdf ]]; then
|
| 558 |
echo "W: ${f}: ${extuiddir}/install.rdf doesn't exist." >&2
|
| 559 |
elif grep -Fq ${extuid} ${extuiddir}/install.rdf; then
|
| 560 |
echo $line >> ${libdir}/extensions/installed-extensions.txt
|
| 561 |
else
|
| 562 |
echo "W: ${f}: ${extuiddir}/install.rdf doesn't contain the UID." >&2
|
| 563 |
fi
|
| 564 |
done < $f
|
| 565 |
done
|
| 566 |
|
| 567 |
# do some double-checking
|
| 568 |
if $MOZILLA_LAUNCHER_DEBUG; then
|
| 569 |
for f in $(find ${libdir}/extensions/ -maxdepth 1 -name '{*}'); do
|
| 570 |
if ! grep -Fq ${f##*/} ${libdir}/extensions/installed-extensions.txt; then
|
| 571 |
echo "W: ${f##*/} not in ${libdir}/extensions/installed-extensions.txt" >&2
|
| 572 |
fi
|
| 573 |
done
|
| 574 |
fi
|
| 575 |
|
| 576 |
# generate installed-chrome.txt
|
| 577 |
cat /dev/null $(ls -d ${chrdir}/* 2>/dev/null) > ${libdir}/chrome/installed-chrome.txt
|
| 578 |
chmod 0644 ${libdir}/chrome/installed-chrome.txt
|
| 579 |
|
| 580 |
# let the mozilla binary do its thing...
|
| 581 |
$mozbin -register || echo "E: Registration process exited with status: $?" >&2
|
| 582 |
regchrome || echo "E: regchrome exited with status: $?" >&2
|
| 583 |
regxpcom || echo "E: regxpcom exited with status: $?" >&2
|
| 584 |
|
| 585 |
if [[ -e ${libdir}/extensions/installed-extensions.txt ]]; then
|
| 586 |
echo "E: ${libdir}/extensions/installed-extensions.txt still present" >&2
|
| 587 |
echo "E: Registration might have gone wrong" >&2
|
| 588 |
fi
|
| 589 |
|
| 590 |
rm -fr ${HOME}
|
| 591 |
|
| 592 |
return 0
|
| 593 |
}
|
| 594 |
|
| 595 |
sanitize_url()
|
| 596 |
{
|
| 597 |
# We only really need to filter '(' and ')' as these break openURL
|
| 598 |
echo $1 | sed -e's/(/%28/g' -e's/)/%29/g'
|
| 599 |
}
|
| 600 |
|
| 601 |
# Call the main sub, which is defined at the top of this script
|
| 602 |
main "$@"
|
| 603 |
|
| 604 |
# vim:expandtab sw=2:
|