--- ../../releases/moz-0.2.2b Sat Nov 30 23:52:18 2002 +++ moz Tue Jun 17 20:42:03 2003 @@ -1,8 +1,12 @@ #!/bin/sh -echo +appname=`basename "$0"` +ver="0.2.2RC1.2003053008" +copy="2002, 2003" +mail="PointedEars@gmx.de" +mail_feedback="bug-moz@PointedEars.de" # ---------------------------------------------------------------------------- -echo -e "\033[1mmoz 0.2.2b -- A Mozilla process manager\033[m" -echo "Copyright (c) 2002 Thomas Lahn " +# moz 0.2.2 -- Mozilla Process Manager +# Copyright (C) 2002, 2003 Thomas Lahn # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -18,213 +22,897 @@ # along with this program; if not, write to the Free Software # Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. # -# This is work in progress. -# Send suggestions and bug reports to +## Standard shell script disclaimer blurb thing: +## +## This script is a hack. It's brute force. It's horrible. +## It doesn't use Artificial Intelligence. It doesn't use Virtual Reality. +## It's not perl. It's not python. It probably won't work unchanged on +## the "other" thousands of unices. But it worksforme. --ramiro +# (from /usr/local/mozilla/run-mozilla.sh) +# +# This is work in progress. If you have an improvement, patch, +# idea, whatever, on how to make this script better, please +# send it to # # ChangeLog # ========== +# +# See the ChangeLog text file for further information. # -# 0.2.2 (future) -# ------------------ -# * Accessing the URI in a new browser tab (Mozilla 1.0.1, 1.1 and beyond). -# * Mixing of new-window, new-tab and new-process options. -# * With -k, first try SIGTERM(15) and if (and only if) this has no effect, -# send SIGKILL(9) +# +# TO DO (0.2.2RC1, scheduled 2003-04-28) +# ======================================= +# +# * POSIX conform parsing of options and arguments (incomplete) +# * L10n: English and German (using macro function) (incomplete) # * Cosmetics: -# - Added status messages -# - Bold-formatted title with changed tagline -# - Updated and reformatted help screen +# - More modular code (incomplete) # -# See the ChangeLog text file for further information. +# See the ROADMAP and TODO text files for further information. # # ---------------------------------------------------------------------------- +function L { + case $lg in + de) echo "${2:-$1}";; + *) echo "$1";; + esac +} + +function Title { + echo " +${extd}moz $ver -- "`L "Mozilla Process Manager" \ + "Mozilla Prozess-Manager"`"${norm} +Copyright (C) $copy Thomas Lahn <$mail> +"`L "Distributed under the terms of the" \ + "Veröffentlicht unter den Bedingungen der"`" GNU General Public License \ +(GPL)," | $fold + L "see COPYING file or http://www.fsf.org/copyleft/gpl.html for \ +details." \ + "Details in Datei COPYING oder unter http://www.fsf.org/copyleft/gpl.html" \ + | $fold + +# ` +} + function help { - echo - echo "Usage: `basename $0` [ ( -? | --term | --kill ) ]" - echo " [ ( -w | -t | - ) ] [URI] [...] [ ( -w | -t | - ) ] [...]" + future=${extd}`L "For future use" "Für zukünftige Verwendung"`.${norm} echo - echo "-?, --help Show this help screen." + echo "${extd}${appname}${norm} + [${extd}-v${norm}] [${extd}-L${norm} LOCALE] [( ${extd}-h${norm} \ +| ${extd}-V${norm} )] [${extd}-M${norm} COMMAND] [${extd}-B${norm} BINARY] \ +[( ${extd}-T${norm} | ${extd}-k${norm} )] + [${extd}-l${norm}[OPTIONS]] [( [${extd}-wt${norm}] [URI] [...] \ +| ${extd}-${norm} )] [${extd}-m${norm}[ADDRESS[${extd},${norm}...]]] \ +[${extd}-ic${norm}] + [${extd}-C${norm} COMMAND] [...] + " + echo -n " ${extd}-v${norm}, ${extd}--verbose${norm} " +L "Activate verbose mode. For testing purposes." \ + "Ausführliche Ausgabe. Zu Testzwecken." | $fold + echo -n " ${extd}-L${norm}, ${extd}--locale${norm} " +L "Preselects the locale for program output." \ + "Wählt die Ausgabesprache." | $fold + echo -n " LOCALE " +L "A string of the form \`lc'[\`_CC'[\`.CHARSET']], where \`lc'" \ + "Eine Zeichenfolge der Form \`lc'[\`_CC'[\`.CHARSET']], wobei" +L "\ + is a lowercased language code, \`CC' an uppercased country + code and \`CHARSET' a character set code. While \`CC' and + \`CHARSET' are optional (note the rectangle brackets), a + language code must be provided, e.g. \`en', \`en_US' and + \`en_US.US-ASCII'." \ + "\ + \`lc' ein Sprachcode in Kleinbuchstaben, \`CC' ein \ +Ländercode + in Grossbuchstaben und \`CHARSET' ein Zeichensatz ist. + Während \`CC' und \`CHARSET' optional sind (siehe die + eckigen Klammern), ist ein Sprachcode erforderlich, + z.B. \`de', \`de_DE' und \`de_DE.ISO-8859-1'." | $fmt +L "\ + This program currently supports the English (\`en') and + German (\`de') locale. If you are not using the \ +\`${extd}-L${norm}' + option, be sure to have your \`LANG' and/or \`LC_CTYPE' + environment properly set." \ + "\ + Dieses Programm unterstützt zur Zeit Englisch (\`en') und + Deutsch (\`de'). Wird die Option \`${extd}-L${norm}' \ +nicht angegeben, + so müssen für die Verwendung der richtigen Sprache die + Umgebungsvariable(n) \`LANG' und/oder \`LC_CTYPE' korrekt + gesetzt sein." | $fmt + + echo -n " ${extd}-h${norm}, ${extd}--help${norm} " +L "Display this help and exit." "Anzeige dieser Hilfe und beenden." | $fold + + echo -n " ${extd}-V${norm}, ${extd}--version${norm} " +L "Display version information and exit." \ + "Anzeige der Version und beenden." | $fold + + echo -n " ${extd}-M${norm}, ${extd}--mozilla${norm} " +L "Specifies how to run Mozilla." \ + "Gibt an, wie Mozilla gestartet werden soll." | $fold + echo -n " COMMAND " +L "The command to run Mozilla. The default is \`mozilla'," \ + "Befehl, der benutzt werden soll, um Mozilla zu starten." +L "\ + which applies at least for Mozilla, Netscape 6.2.3 and + above, and for Phoenix < 0.5. Users of other programs + need to specify the command in order to get \`moz' + working with them. The following commands are known: + + Netscape < 6.2.3 netscape + Phoenix 0.5 phoenix + Mozilla Firebird 0.6 MozillaFirebird + + This requires COMMAND to be an executable file that + accepts the \`-remote' option, located either in a + directory specified in the \`PATH' environment or in + the current directory. + If the option is left out, the default value can be + overwritten defining the \`MOZILLA_CMD' environment." \ + No check is performed, neither on the option's argument + nor on the environment." \ + "\ + Standard ist \`mozilla', was für Mozilla, Netscape ab + Version 6.2.3 und Phoenix < 0.5 zutrifft. Benutzer + anderer Programme müssen diese Option angeben, damit + \`moz' bei ihnen funktioniert. Die folgenden Befehle + sind bekannt: + + Netscape < 6.2.3 netscape + Phoenix 0.5 phoenix + Mozilla Firebird 0.6 MozillaFirebird + + Erforderlich ist wie COMMAND benannte ausführbare Datei, + welche die Option \`-remote' unterstützt, die sich + entweder in einem mit der \`PATH'-Umgebungsvariable + definierten Verzeichnis oder im aktuellen Verzeichnis + befindet. + Wenn diese Option nicht angegeben wird, so kann der + Standardwert durch Definition der Umgebungsvariablen + \`MOZILLA_CMD' überschrieben werden. + Weder das Optionsargument noch die Umgebungsvariable + werden einer Prüfung unterzogen." | $fmt + + echo -n " ${extd}-B${norm}, ${extd}--binary${norm} " +L "Specifies what binary is used by Mozilla." \ + "Gibt an, welche Binärdatei von Mozilla benutzt wird." | $fold + echo -n " BINARY " +L "This is needed to determine if Mozilla is already running" \ + "Diese Angabe wird benötigt, um zu ermitteln, ob Mozilla" +L "\ + and for \`${extd}-l${norm}' display. The default is \ +\`mozilla-bin' which + applies at least for Mozilla, Netscape 6.2.3 and above, + and for Phoenix < 0.5. Users of other programs need to + specify the binary in order to get \`moz' working with + them. The following binaries are known: + + Netscape < 6.2.3 netscape-bin + Phoenix 0.5 phoenix-bin + Mozilla Firebird 0.6 MozillaFirebird-bin + + If the option is left out, the default value can be + overwritten defining the \`MOZILLA_BIN' environment." \ + "\ + bereits läuft und für die Anzeige mit der Option \ +\`${extd}-l${norm}'. + Standard ist \`mozilla-bin', was für Mozilla, Netscape + ab Version 6.2.3 und Phoenix < 0.5 zutrifft. Benutzer + anderer Programme müssen diese Option angeben, damit + \`moz' bei ihnen funktioniert. Die folgenden Binärdateien + sind bekannt: + + Netscape < 6.2.3 netscape-bin + Phoenix 0.5 phoenix-bin + Mozilla Firebird 0.6 MozillaFirebird-bin + + Wird diese Option nicht angegeben, so kann der Standardwert + durch Definition der Umgebungsvariablen \`MOZILLA_BIN' + überschrieben werden." | $fmt + +# ` # version 0.2.3 proposal -# echo " --block Block the shell for the \`mozilla' process, i.e. prevent" -# echo " following commands to be executed until Mozilla is quit." - echo " --term Terminate all \`mozilla-bin' processes (first), sending each of" - echo " them a SIGTERM(15) signal. Need not to work as a process may" - echo " refuse to terminate (see -k). Note that the -t option, which" - echo " was previously short for --term, now (for POSIX conformance)" - echo " refers to the creation of a new browser tab (see below)." - echo "-k, --kill Kill all \`mozilla-bin' processes (first). Tries first to" - echo " send each of the processes a SIGTERM(15) signal to end" - echo " them politely, and if (and only if) this does not work," - echo " send them the kinda rude SIGKILL(9) signal." - echo " Note that -k (but not --kill) may become obsolete in" - echo " future versions for POSIX conformance." - echo "-n, --new Same as -w. For backward compatibility only, this may become" - echo " obsolete in future versions." - echo "-w, --win Show the resource(s) specified by URI in a new browser window." - echo " If not provided, the current window/tab content will be" - echo " replaced. Resources with \`mailto:' URIs will create a new" - echo " e-mail compose window anyway." - echo "-t, --tab Show the resource(s) specified by URI in a new browser tab." - echo " Works with Mozilla 1.0.1, 1.1 and beyond. If not provided," - echo " the current window/tab content will be replaced. Resources" - echo " with \`mailto:' URIs will create a new e-mail compose window" - echo " anyway." - echo "URI The URI(s) of the resource(s) to display. If not provided and" - echo " no further options are given this help screen is displayed." - echo " Two or more URIs are separated by spaces, while the second" - echo " and following resources are displayed in a new browser window" - echo " (if not specified otherwise with -t or a \`mailto:' URI.)" - echo " Use \`-' to (re)start Mozilla with a blank page (new process)" - echo " or show a window that allows you to select what to do (Mozilla" - echo " 1.1 and beyond). This disables any previous -w or -t options" - echo " and is especially useful in conjunction with --term or -k." - echo -} +# echo " --block Block the shell for the 'mozilla' process, i.e. prevent" +# echo " following commands to be executed until Mozilla is \ +# quit." -rc_done="\033[1mdone\033[m" -rc_failed="\033[1m\033[31mfailed\033[m" + echo -n " ${extd}-T${norm}, ${extd}--term${norm} " +L "Terminate all Mozilla processes (first), sending each" \ + "Beendet (zuerst) alle Mozilla-Prozesse, indem jedem" | $fold +L "\ + of them a SIGTERM(15) signal. Need not to work as a + process may refuse to terminate (see \ +\`${extd}-k${norm}')." \ + "\ + Prozess ein SIGTERM(15)-Signal gesendet wird. Das + muss nicht funktionieren, da ein Prozess das Beenden + verweigern kann (siehe \`${extd}-k${norm}')." \ +| $fmt +L "\ + Note that the \`${extd}-t${norm}' option, which was \ +previously used + for this feature, now refers to the creation of a new + browser tab (see below)." \ + "\ + Hinweis: Die Option \`${extd}-t${norm}' wurde vorher für \ +diese + Funktion benutzt, bedeutet aber jetzt, dass ein + neuer Browser-Tab erzeugt wird (siehe unten)." | $fmt -function msg_done { - if [ -n "$rc_done" ]; then - echo -e $rc_done - else - echo "done" + echo -n " ${extd}-k${norm}, ${extd}--kill${norm} " +L "Kill all Mozilla processes (first). Tries first to send" \ + "Beendet (zuerst) alle Mozilla-Prozesse." | $fold +L "\ + each of the processes a SIGTERM(15) signal to end them + politely. If, and only if, this does not work, send + them the kinda rude SIGKILL(9) signal ;-)" \ + "\ + Versucht zunächst, jedem Prozess ein SIGTERM(15)-Signal + zu senden, um ihn höflich um seine Beendigung zu bitten. + Nur wenn das nicht funktioniert, wird an den Prozess das + ziemlich ruppige SIGKILL(9)-Signal gesendet ;-)" | $fmt + + echo -n " ${extd}-l${norm}, ${extd}--list${norm} " +L "List running Mozilla processes and threads and exit." \ + "Zeigt laufende Mozilla-Prozesse an." | $fold + + echo -n " OPTIONS " +L "Options for \`ps'. Type \`ps --help' for details." \ + "Optionen für \`ps'. \`ps --help' für Details eingeben." | $fold +L "\ + The default is to use the user-oriented format + if supported." \ + "\ + Standardmässig wird das benutzerorientierte Format + benutzt, falls es unterstützt wird." | $fmt + + echo -n " ${extd}-n${norm}, ${extd}--new${norm} " +L "Same as \`${extd}-w${norm}'. For backwards compatibility only," \ + "Wie \`${extd}-w${norm}'. Nur für Abwärtskompatibilität vorhanden," | $fold +L "\ + this may become obsolete in future versions." \ + "\ + diese Option wird möglicherweise in zukünftigen + Versionen nicht mehr verfügbar sein." | $fmt + + echo -n " ${extd}-w${norm}, ${extd}--win${norm} " +L "Show the resource(s) specified by URI in a new browser" \ + "Zeigt die mit URI angegebene(n) Ressource(n) in" | $fold +L "\ + window. If not provided, the current window/ tab + content will be replaced. Resources with \`mailto:' + URIs will create a new Message Compose window anyway." \ + "\ + einem neuen Browser-Fenster. Wenn nicht angegeben, + wird der Inhalt des aktuellen Fensters/Tabs ersetzt. + Ressourcen mit \`mailto:'-URIs erzeugen jedoch immer + ein neues Fenster für die Mailbearbeitung." | $fmt + + echo -n " ${extd}-t${norm}, ${extd}--tab${norm} " +L "Show the resource(s) specified by URI in a new browser" \ + "Zeigt die mit URI angegebene(n) Ressource(n) in einem" | $fold +L "\ + tab. Works with Mozilla 1.0.1, 1.1 and beyond. + If not provided, the current window/ tab content + will be replaced. Resources with \`mailto:' URIs + will create a new Message Compose window anyway." \ + "\ + neuen Browser-Tab. Funktioniert mit Mozilla 1.0.1, + 1.1 und höher. Wenn nicht angegeben, wird der Inhalt + des aktuellen Fensters/Tabs ersetzt. Ressourcen mit + \`mailto:'-URIs erzeugen jedoch immer ein neues Fenster + für die Mailbearbeitung." | $fmt + + echo -n " URI " +L "The URI(s) of the resource(s) to display. If not provided" \ + "URI(s) der anzuzeigenden Ressource(n). Wenn nicht" | $fold +L "\ + and no further options are given, show this help and \ +exit." \ + "\ + angegeben und keine weiteren Optionen angegeben + sind, wird diese Hilfe angezeigt und das Programm + beendet." | $fmt +L "\ + Two or more URIs are separated by spaces or comma, while + the second and following resources are displayed in a new + browser window, if not specified otherwise with \ +\`${extd}-t${norm}' or a + \`mailto:' URI." \ + "\ + Zwei oder mehr URIs werden durch Leerzeichen oder + Komma getrennt, dabei werden die zweite und alle + weiteren Ressourcen in einem neuen Browser-Fenster + angezeigt, falls nicht anders mit \`${extd}-t${norm}' oder\ + durch + einen \`mailto:'-URI festgelegt." | $fmt + + echo -n " ${extd}-${norm} " +L "(Re)start Mozilla with a blank page (or home page in a" \ + "(Neu)start von Mozilla mit einer leeren Seite (bzw." | $fold +L "\ + new process) or show a window that allows you to select + what to do (Mozilla 1.1 and beyond). This disables any + previous \`${extd}-w${norm}' or \`${extd}-t${norm}' \ +options and is especially useful + in conjunction with \`${extd}-T${norm}' or \ +\`${extd}-k${norm}'." \ + "\ + der Startseite) oder Anzeige eines Fensters, welches + es erlaubt, eine Aktion auszuwählen (Mozilla 1.1 und + höher). Dies deaktiviert ein vorheriges \ +\`${extd}-w${norm}' oder + \`${extd}-t${norm}' und ist besonders nützlich in \ +Verbindung mit + \`${extd}-T${norm}' oder \`${extd}-k${norm}'." | $fmt + + echo -n " ${extd}-m${norm}, ${extd}--mailto${norm} " +L "Pop up the mail dialog." "Öffnet ein neues Fenster zum Verfassen einer E-Mail." | $fold + + echo -n " ADDRESS " +L "If left out, the \`To:' field is empty. Given one or more" \ + "Wenn dieses Argument ausgelassen wird, ist das Feld" | $fold +L "\ + comma-separated addresses, put those in the default \ +\`To:'." \ + "\ + \`An:' (\`To:') leer. Werden eine oder mehr durch Komma + getrennte Adressen angegeben, so stehen diese zunächst + im Feld \`An:'." | $fmt + + + echo -n " ${extd}-i${norm}, ${extd}--inbox${norm} " +L "Open a new Mail & Newsgroups window." \ + "Öffnet ein neues Fenster für Mail & Newsgroups." | $fold + + echo -n " ${extd}-c${norm}, ${extd}--compose${norm} " +L "Open a new Message Compose window. + Same as \`${extd}-m${norm}' without ADDRESS." \ + "Öffnet ein neues Fenster zum Verfassen von Mails/News. + Wie \`${extd}-m${norm}' ohne ADDRESS." | $fold + + echo -n " ${extd}-C${norm}, ${extd}--command${norm} " +L "Execute arbitrary Mozilla COMMAND. $future" \ + "Beliebigen Mozilla-Befehl COMMAND ausführen. + $future" | $fold + + if [ $getopt_type = "short" ]; then +_XPG=1 + echo " +$(L "\ +Note that the long options are not available on this system, so you +must use the short options instead. Also, optional arguments are not +supported, so if you do not pass an argument to an option, you must +use \"\" instead." \ + "\ +Beachten Sie, dass die langen Optionen auf diesem System nicht verfügbar +sind, so dass Sie die kurzen Optionen verwenden müssen. Weiterhin werden +optionale Argumente nicht unterstützt. Wenn Sie ein optionales Argument +nicht angeben, müssen Sie stattdessen \"\" angeben." | $fmt)" +_XPG=0 fi + echo } -function msg_failed { - if [ -n "$rc_failed" ]; then - echo -e $rc_failed +function isMozRunning { + # check for supported `ps' options + whoami=`whoami` + # BSD style user-oriented + args="u " + ps $args >/dev/null 2>&1 + if [ $? -eq 0 ]; then + fallback=$args + args=$args" -u $whoami" # current user's processes only + ps $args >/dev/null 2>&1 + test $? -ne 0 && args=$fallback else - echo "failed" + # SysV/Unix98 (i.e. IRIX) style + fallback="-" + args="-f" # full output + ps $args >/dev/null 2>&1 + test $? -eq 0 && fallback=$args || args=$fallback + args=$args"u $whoami" # current user's processes only + ps $args >/dev/null 2>&1 + test $? -ne 0 && args=$fallback fi + chk=`ps $args | grep $mozilla_bin | grep -v grep` + test -z "$chk" && return 1 + return 0 } function KillMoz { local result=0 - if [ -n "`ps -A | grep mozilla-bin`" ]; then - echo -n "Sending all Mozilla processes the " - case "$1" in - "-9") echo -n "KILL";; - *) echo -n "TERM";; - esac - echo -n " signal... " - killall $1 mozilla-bin 2> /dev/null + echo -n `L "Sending all Mozilla processes the" \ + "Sende allen Mozilla-Prozessen das"`" " + case "$1" in + "-9") echo -n "KILL";; + *) echo -n "TERM";; + esac + Lout=`L " signal" "-Signal"` + echo -n "$Lout$stat" + if isMozRunning; then + killall $1 $mozilla_bin 2>/dev/null result=$? +# FIX ME! +# allow other user's processes to run and be successful anyway if [ $result -ne 0 ]; then - msg_failed - echo + echo $rc_failed else - msg_done + ping=1 + "$mozilla" -remote "ping()" 2>/dev/null + error=$? + test $verbose -eq 1 && echo -n $error" " >&2 + while [ $error -eq 0 ] && [ $ping -le 50 ]; do + let ping++ + "$mozilla" -remote "ping()" 2>/dev/null + error=$? + test $verbose -eq 1 && echo -n $error" " >&2 + if [ $ping -eq 25 ]; then + echo " + " + L "Mozilla was pinged $ping times without response, trying +$ping more times before giving up. Press Ctrl+C to quit." \ + "Mozilla wurde $ping Mal erfolglos gepingt, es werden weitere +$ping Versuche unternommen. Drücken Sie Strg+C, um abzubrechen." | $fmt >&2 + echo -n " +$stat" >&2 + fi + done + if [ $error -ne 0 ]; then + echo $rc_done + test $verbose -eq 1 && \ + L "Mozilla was pinged "$ping" times until shutdown was complete." \ + "Mozilla wurde "$ping" Mal gepingt, bevor er vollständig beendet \ +war." | $fmt >&2 + else + echo $rc_failed + test $verbose -eq 1 && \ + L " +Mozilla was pinged "$ping" times without response. +Please check your Mozilla installation." \ + " +Mozilla wurde "$ping" Mal erfolglos gepingt. +Bitte überprüfen Sie ihre Mozilla-Installation." | $fmt >&2 + fi fi else - echo -e "No Mozilla process is running that could be terminated or killed." + echo $rc_dead +# echo `L "No Mozilla process is running that could be terminated or killed."\ +# "Es läuft kein Mozilla-Prozess, der beendet werden kann."` \ +# | $fold >&2 fi +_XPG=1 return $(( $result )) +_XPG=0 } -echo "Protected under the terms of the GNU General Public License (GPL)." -echo "See COPYING file or http://www.fsf.org/copyleft/gpl.html for details." -help=0 -if [ -z "$1" ] || [ "$1" = "-?" ] || [ "$1" = "--help" ]; then - help=1; - help +function ListMoz { + # check for supported `ps' options + whoami=`whoami` + args=" $1 " + ps $args >/dev/null 2>&1 + if [ $? -eq 0 ]; then + fallback=$args + args=$args" u" # BSD style user-oriented + ps $args >/dev/null 2>&1 + if [ $? -eq 0 ]; then + fallback=$args + else + args=$fallback + fi + args=$args" -H" # with process hierarchy + ps $args >/dev/null 2>&1 + if [ $? -eq 0 ]; then + fallback=$args + else + args=$fallback + fi + args=$args" -u $whoami" # current user's processes only + ps $args >/dev/null 2>&1 + test $? -ne 0 && args=$fallback + else + # SysV/Unix98 (i.e. IRIX) style + fallback="-" + args="-f" # full output + ps $args >/dev/null 2>&1 + if [ $? -eq 0 ]; then + fallback=$args + else + args=$fallback + fi + args=$args"H" # with process hierarchy + ps $args >/dev/null 2>&1 + if [ $? -eq 0 ]; then + fallback=$args + else + args=$fallback + fi + args=$args"u $whoami" # current user's processes only + ps $args >/dev/null 2>&1 + test $? -ne 0 && args=$fallback + fi + chk=`ps $args | grep $mozilla_bin | grep -v grep` + if [ -z "$chk" ]; then + L "There are no \`${mozilla_bin}' processes running." \ + "Es laufen keine \`${mozilla_bin}'-Prozesse." | $fold >&2 + else + echo `L "Running Mozilla processes and threads" \ + "Laufende Mozilla-Prozesse und Threads"`": + " | $fold >&2 + ps $args 2>/dev/null | head -n 1 + echo "$chk" + fi + echo +} + +function RunMsg { + case $1 in + new) + echo -n `L "Starting a new Mozilla process" \ + "Starte einen neuen Mozilla-Prozess"` + shift + RunMsg $* + ;; + *) ;; + esac +} + +# ********************************** MAIN ************************************** + +# from /etc/rc.status +# check for $COLUMNS +if test -z "$LINES" -o -z "$COLUMNS" ; then + eval `stty size 2>/dev/null | (read L C; echo LINES=${L:-24} \ +COLUMNS=${C:-80})` fi -echo "Send suggestions and bug reports to " -echo -test $help -eq 1 && exit 255 +test $LINES -eq 0 && LINES=24 +test $COLUMNS -eq 0 && COLUMNS=80 -if [ "$1" = "-?" ] || [ "$1" = "--help" ]; then - help +if test "$TERM" != "raw" && stty size >/dev/null 2>&1 ; then + esc=`echo -en "\033"` + extd="${esc}[1m" + warn="${esc}[1;31m" + done="${esc}[1;32m" + norm=`echo -en "${esc}[m\017"` + stat=`echo -en "\015${esc}[${COLUMNS}C${esc}[10D"` + up="[1a" else - kill=0 - # check for term/kill - if [ "$1" = "--term" ] || [ "$1" = "--kill" ] || [ "$1" = "-k" ]; then - kill=1 - if [ "$1" = "--kill" ] || [ "$1" = "-k" ]; then sig=-9; fi - KillMoz - if [ $? -ne 0 ] && [ $sig -eq -9 ]; then KillMoz $sig; fi - shift - test -z "$1" && echo && exit 0 + esc="" + extd="" + warn="" + done="" + norm="" + stat="... " + up="" +fi + + rc_done="${done}done${norm}" + rc_running="${stat}${done}running${norm}" + rc_failed="${warn}failed${norm}" + rc_dead="${stat}${warn}not running${norm}" + rc_done_up="${esc}${up}${rc_done}" +rc_failed_up="${esc}${up}${rc_failed}" + rc_reset="${norm}" + rc_save="${esc}7" + rc_restore="${esc}8" + +# check for fold +fold="fold -sw $COLUMNS" +chk=`which fold 2>/dev/null` +test $? -ne 0 && fold="cat" +chk=`echo x | $fold 2>/dev/null` +test -n "$chk" && fold="cat" + +# check for fmt +fmt=cat +if [ $COLUMNS -ne 80 ]; then # output is preformatted for 80 cols + chk=`which fmt 2>/dev/null` + if [ $? -ne 0 ]; then + fmt=$fold + else + # check for columns + fmt="fmt -$COLUMNS" + chk=`echo x | $fmt 2>/dev/null` + test -z "$chk" && fmt="fmt" + # check for -c|--crown-margin + chk=`echo x | $fmt -c 2>/dev/null` + if [ -n "$chk" ]; then + fmt=$fmt" -c" + else + chk=`echo x | $fmt --crown-margin 2>/dev/null` + test -n "$chk" && fmt=$fmt" --crown-margin" + fi fi +fi - # check for Mozilla - chk=`which mozilla 2> /dev/null` - if [ -z "$chk" ]; then - echo "moz Error: The \`mozilla' executable is required for this script." - echo - exit 255 +# L10n +lg="" +test -n "$LANG" && lg=`echo $LANG | sed 's/_.*[.].*//' 2>/dev/null` +test -z "$lg" && lg=`echo $LC_CTYPE | sed 's/_.*//' 2>/dev/null` + +# Note that we use `"$@"' to let each command-line parameter expand to a +# separate word. The quotes around `$@' are essential! +# We need `tmp' as the `eval set --' would nuke the return value of getopt. + +echo "$extd +Debug output for POSIX conform command-line +parsing (will require -vv in the release). + +Original arguments: $*" >&2 +if `getopt -T >/dev/null 2>&1` ; [ $? = 4 ] ; then + getopt_type=long + echo "getopt(1) type: enhanced" >&2 + tmp=`getopt -o vL:hVM:B:Tkl::n:w:t:-m::ic \ + -l verbose,locale:,help,version,mozilla:,binary:,term,kill,list,\ +full,new:,win:,tab:,mailto::,inbox,compose \ + -n "$appname" -s sh \ + -- "$@"` +else + getopt_type=short + echo "getopt(1) type: old" >&2 + tmp=`getopt vL:hVM:Tkl:n:w:t:-m:ic "$@"` +fi + +getopt_exit_code=$? +help=0 +verbose=0 +version=0 +mozilla=${MOZILLA_CMD:-mozilla} +mozilla_bin=${MOZILLA_BIN:-mozilla-bin} +term="" +list=0 +list_style="" +args="" +if [ $getopt_exit_code -eq 0 ]; then +## getopt returns error code 0 for successful parsing, 1 if +## getopt(3) returns errors, 2 if it does not understand its +## own parameters, 3 if an internal error occurs like out-of- +## memory, and 4 if it is called with -T. +# +# Note the quotes around `$tmp': they are essential! +# echo $tmp +# remove "--" +# for i in $tmp; do if [ "$i" != "--" ]; then tmp2="${tmp2} $i"; fi; done + eval set -- "$tmp" +echo "New arguments: $*$norm" >&2 + while true ; do + case "$1" in + -h | --help) help=1; shift;; + -v | --verbose) verbose=1; shift;; + # -b | --block) block=1; shift;; + -L | --locale) lg=$2; shift 2;; + -V | --version) version=1; shift;; + -M | --mozilla) mozilla=$2; shift 2;; + -B | --binary) mozilla_bin=$2; shift 2;; + -T | --term) test -z "$term" && term=t; shift;; + -k | --kill) term=k; shift;; + -l | --list) list=1; list_style=$2; [ -n "$2" ] && shift 2 || shift;; + --) shift; break;; + -n | --new | -w | --win | -t | --tab | -m | --mailto) + args=$args" "$1" "$2; shift 2;; + -i | --inbox | -c | --compose | *) + args=$args" "$1; shift;; + esac + done + test -n "$*" && args=$args" $*" + test -z "$args" -a $version -eq 0 -a "$term" = "" -a $list -eq 0 && help=1 + set -- $args +else + echo "getopt exited: $getopt_exit_code + " >&2 + if [ $getopt_exit_code -eq 1 ] || [ $getopt_exit_code -eq 2 ]; then + help=1 + else + exit $getopt_exit_code fi +fi - # block=0 - # check for block mode - # if [ "$1" = "-b" ] || [ "$1" = "--block" ]; then block=1; shift; fi +Title - while [ -n "$1" ]; do - # check for new-window - new_win=0 - if [ "$1" = "-n" ] || [ "$1" = "--new" ] || [ "$1" = "-w" ] || [ "$1" = "--win" ]; then - new_win=1 - shift - fi +test $help -eq 1 && help - # check for new-tab - new_tab=0 - if [ "$1" = "-t" ] || [ "$1" = "--tab" ]; then new_tab=1; shift; fi +echo `L "Send suggestions and bug reports to" \ + "Senden Sie Vorschläge und Fehlerberichte an"`" <$mail_feedback> +" | $fold - # check for disabling new-* - test "$1" = "-" && shift +test $version -eq 1 && exit 0 +test $help -eq 1 && exit 255 + +# check for term/kill +kill=0 +if [ "$term" = "t" ] || [ "$term" = "k" ]; then + kill=1 + test "$term" = "k" && sig=-9 + KillMoz + test $? -ne 0 && $sig -eq -9 && KillMoz $sig +fi + +error=0 + +# check for list +test $list -eq 1 && ListMoz "$list_style" && set -- "" + +new_win=0 +if [ -n "$1" ]; then + + # check for Mozilla + chk=`which "$mozilla" 2>/dev/null` + if [ $? -ne 0 ] && [ ! -x "$mozilla" ]; then + _XPG=1 + echo "${appname}: \ +$(L "The \`${mozilla}' executable is required for this program." \ + "Die ausführbare Datei \`${mozilla}' wird für dieses Programm benötigt.") + " | $fold >&2 + _XPG=0 + set -- "" + error=255 + fi + + new_tab=0 + while [ -n "$1" ]; do + mailto=0 + inbox=0 + compose=0 + uri="" + cmd="" + case "$1" in + # check for new-window + "-n" | "--new" | "-w" | "--win") + new_win=1 + new_tab=0 + shift;; + # check for new-tab + "-t" | "--tab") + new_win=0 + new_tab=1 + shift;; + # check for mailto + "-m" | "--mailto") + mailto=1 + shift + uri="-mail" + cmd="mailto($1)";; + "-i" | "--inbox") + inbox=1 + uri="-mail" + cmd="xfeDoCommand(openInbox)" + shift;; + "-c" | "--compose") + compose=1 + uri="-compose $2" + cmd="xfeDoCommand(composeMessage)" + shift;; + # check for disabling new-* + "-") + new_win=0 + new_tab=0 + shift;; + esac # check if the current user has Mozilla already run - chk=`ps -u $(whoami) | grep mozilla-bin` + # AFAIK mozilla -remote "ping()" does not pay respect to different accounts + _XPG=1 + chk=`ps -fu $(whoami) 2>/dev/null | grep $mozilla_bin | grep -v grep` + _XPG=0 + test -z "$uri" && uri="$1" + + # check if argument denotes a local file or directory, + # determine the current working directory and append + # to the URI if successful + test -d "$uri" -o -f "$uri" && uri="file://"`pwd 2>/dev/null`"/$uri" + if [ -z "$chk" ]; then - echo -n "Starting a new Mozilla process" - test -n "$1" && echo -n " with URI '$1'" - echo "..." + RunMsg new + test -n "$uri" -a $mailto -eq 1 -a $inbox -eq 0 \ + -a $compose -eq 0 && echo -n " "`L "with URI" "mit dem URI"`" '$uri'" + echo -n "$stat" #if [ $block -eq 1 ]; then - # mozilla "$1" + # "$mozilla" "$uri" #else - mozilla "$1" & + "$mozilla" $uri & #fi + error=$? + if [ -n "$2" ]; then + ping=1 + "$mozilla" -remote "ping()" 2>/dev/null + error=$? + test $verbose -eq 1 && echo -n $error" " >&2 + while [ $error -ne 0 ] && [ $ping -le 50 ]; do + let ping++ + "$mozilla" -remote "ping()" 2>/dev/null + error=$? + test $verbose -eq 1 && echo -n $error" " >&2 + if [ $ping -eq 25 ]; then + echo " + " + L "Mozilla was pinged $ping times without response, trying + $ping more times before giving up. Press Ctrl+C to quit." \ + "Mozilla wurde $ping Mal erfolglos gepingt, es werden weitere + $ping Versuche unternommen. Drücken Sie Strg+C, um abzubrechen." | $fmt >&2 + echo -n " + $stat" >&2 + fi + done + if [ $error -eq 0 ]; then + echo $rc_done + test $verbose -eq 1 && \ + L "Mozilla was pinged "$ping" times until startup was complete." \ + "Mozilla wurde "$ping" Mal gepingt, bevor er vollständig gestartet \ +war." | $fmt >&2 + else + echo $rc_failed + test $verbose -eq 1 && \ + L " +Mozilla was pinged "$ping" times without response. +Please check your Mozilla installation." \ + " +Mozilla wurde "$ping" Mal erfolglos gepingt. +Bitte überprüfen Sie ihre Mozilla-Installation." | $fmt >&2 + fi + else + test $error -eq 0 && echo $rc_done || echo $rc_failed + fi else # check what kind of URI was given - cmd="openURL($1" - test $new_win -eq 1 && cmd=$cmd", new-window" - test $new_tab -eq 1 && cmd=$cmd", new-tab" - cmd=$cmd")" + if [ -z "$cmd" ]; then + cmd="openURL("$uri + test $new_win -eq 1 && cmd=$cmd", new-window" + test $new_tab -eq 1 && cmd=$cmd", new-tab" + cmd=$cmd")" + fi # checking for grep - chk=`which grep 2> /dev/null` - if [ -z "$chk" ]; then - echo "moz Error: \`grep' not found. Cannot check for mailto: URI." + chk=`which grep 2>/dev/null` + _XPG=1 + if [ $? -ne 0 ]; then + echo "${appname}: \`grep' "\ + $(L "not found. Cannot check for \`mailto:' URI." \ + "nicht gefunden. Überprüfung auf \`mailto:'-URI nicht möglich.") >&2 else - if [ -n "`echo "$1" | grep "^mailto:"`" ]; then - address="$1" + if [ -n "`echo "$uri" | grep "^mailto:"`" ]; then + address="$uri" # checking for sed - chk=`which sed 2> /dev/null` - if [ -z "$chk" ]; then - echo "moz Error: \`sed' not found. Cannot handle mailto: URI properly." + chk=`which sed 2>/dev/null` + if [ $? -ne 0 ]; then + echo $appname": \`sed' "\ + $(L "not found. Cannot handle \`mailto:' URI properly." \ + "nicht gefunden. \`mailto:'-URI kann nicht richtig umgesetzt werden.") >&2 else address=`echo "$address" | sed "s/^mailto://"` fi cmd="mailto($address)" + mailto=1 fi fi - echo -n "Accessing URI " - if [ -n "$1" ]; then - echo -n "'$1'" + _XPG=0 + if [ $mailto -eq 0 ] && [ $inbox -eq 0 ] && [ $compose -eq 0 ]; then + echo -n `L "Accessing URI" "Lade URI"`" " + test -n "$uri" && echo -n "'$uri'" || echo -n "'about:blank'" + test $new_win -eq 1 && \ + echo -n " "`L "in a new browser window" "in einem neuen Browserfenster"` + test $new_tab -eq 1 && \ + echo -n " "`L "in a new browser tab" "in einem neuen Browser-Tab"` else - echo -n "'about:blank'" + if [ $mailto -eq 1 ]; then + echo -n `L "Opening new e-mail Compose window" \ + "Neues Fenster zur E-Mail-Bearbeitung wird geöffnet"` + elif [ $inbox -eq 1 ]; then + echo -n `L "Opening new MailNews window" \ + "Neues MailNews-Fenster wird geöffnet"` + else + echo -n `L "Opening new Compose window" \ + "Neues Fenster zur Nachrichtenbearbeitung wird geöffnet"` + fi fi - test $new_win -eq 1 -a $mailto=0 && echo -n " in a new browser window" - test $new_tab -eq 1 -a $mailto=0 && echo -n " in a new browser tab" - echo -n "... " - mozilla -remote "$cmd" & - if [ $? -eq 0 ]; then msg_done; else msg_failed; fi + echo -n "$stat" + "$mozilla" -remote "$cmd" & + test $? -eq 0 && echo $rc_done || echo $rc_failed fi - shift + test -n "$1" && shift new_win=1 done fi @@ -228,4 +916,9 @@ new_win=1 done fi + echo +test $verbose -eq 1 -o $getopt_exit_code -eq 1 \ + && read -rs -p "`L "Press any key..." "Beliebige Taste drücken ..." | $fold`" -n 1 && echo " + " +exit $error