--- ../releases/moz-0.2.2b Thu Feb 27 02:18:12 2003 +++ latest/moz Thu Apr 10 00:06:37 2003 @@ -1,8 +1,12 @@ #!/bin/sh - echo + appname=`basename "$0"` + ver="0.2.2b+.2003041000" + 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.2b+ -- 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,214 +22,886 @@ echo "Copyright (c) 2002 Thomas Lahn

+ ## 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 # ========== # # 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) + # --------------- + # * 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 is possible + # * With `-k', first try SIGTERM(15) and if (and only if) this has no effect, + # send SIGKILL(9); wait [with `-remote ping()'] for Mozilla to end before + # doing anything + # * `-l' lists running `mozilla-bin' processes/threads using `ps'; + # Tests for and support of user-oriented `ps' output (`u'), + # uses Unix98 options as fallback; allow arbitrary `ps' options + # * `-m' allows to open new Compose window with predefined `To:' field + # * `-i' opens a new MailNews window + # * `-c' opens a new Compose window with empty `To:' field + # * L10n: English and German (using macro function) + # * Send error messages to stderr + # * Fixed function-in-statement-bug on `sh' (@IRIX) + # * Support SysV compliant `ps' calls (@IRIX) + # * If not running on first argument, wait for the process + # [with `-remote ping()'] before passing on to the second argument + # * _XPG=1 for `$( `$command` )' and `$(( `$expression` ))' in `sh' (@IRIX 6.5) + # * `--version': Display version information and exit + # * Speed-up Mozilla process start-up by using ping() only for first -remote + # * Allow to use local directories and filenames as URI argument; the argument + # is then preceded by file://`pwd`/ # * Cosmetics: # - Added status messages # - Bold-formatted title with changed tagline # - Updated and reformatted help screen + # - s/Protected/Distributed/ + # - Fixed typo in english help for `-w' option (deprecated) + # - Output is preformatted for 80 cols; + # reformats only when $COLUMNS is different (fast!) + # - Reformatted source not to exceed 80 cols per line (with `\') + # to make it easier legible on the console + # - Separated help source by a blank line # # See the ChangeLog text file for further information. # + # TO DO (0.2.2 release, scheduled in first week of April 2003) + # + # * POSIX conform parsing of options and arguments (incomplete) + # * `-M', `--mozilla': Support other programs similar to Mozilla like Phoenix + # * `-C', `--command' options to execute arbitrary Mozilla commands + # * Cosmetics: + # - More modular code (incomplete) + # + # TO DO (later): + # + # * New option to call Mozilla if and only if it is not running + # # ---------------------------------------------------------------------------- + function L { + case $lg in + de) if [ -n "$2" ]; then echo "$2"; else echo "$1"; fi;; + *) echo "$1";; + esac + } + + function Title { + echo "\ + ${extd}moz $ver -- "`L "Mozilla process manager" "Manager für \ + Mozilla-Prozesse"`"${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 { + future=${extd}`L "For future use" "Für zukünftige Verwendung"`.${norm} echo - echo "Usage: `basename $0` [ ( -? | --term | --kill ) ]" - echo " [ ( -w | -t | - ) ] [URI] [...] [ ( -w | -t | - ) ] [...]" - 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}-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']]," + 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'." \ + "\ + wobei \`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') . Wenn Sie die Option \ + \`${extd}-L${norm}' nicht + angeben, stellen Sie sicher, dass die Umgebungsvariable(n) + \`LANG' und/oder \`LC_CTYPE' korrekt gesetzt sind." | $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. " \ + "Definiert, wie Mozilla gestartet werden soll." | $fold + echo "\ + $future" | $fmt + echo -n " COMMAND " + L "The command to run Mozilla. The default is \`mozilla'" \ + "Befehl, der benutzt werden soll, um Mozilla zu starten." + L "\ + which requires the \`mozilla' executable in \`\$PATH' + if you have not defined one using the \`MOZILLA_CMD' + environment. You may also specify a command in + \`\$PATH' here, so the program will not check if the + path is correct." \ + "\ + Standard ist \`mozilla', was es erforderlich macht, dass + sich die ausführbare Datei \`mozilla' im \`\$PATH' \ + befindet, + falls Sie nicht mit der Umgebungsvariable \`MOZILLA_CMD' + etwas anderes definiert haben. Sie können hier auch einen + Befehl angeben, der sich im \`\$PATH' befindet, daher wird + das Programm nicht überprüfen, ob der angegebene Pfad + korrekt ist." | $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 + + 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 - function msg_done { - if [ -n "$rc_done" ]; then - echo -e $rc_done - else - echo "done" + 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 e-mail 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 tab." \ + "Zeigt die mit URI angegebene(n) Ressource(n) in einem" | $fold + L "\ + 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 e-mail 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 "Pops up the mail dialog." "Zeigt den Mail-Dialog an." | $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 "Opens a new Mail & Newsgroups window." \ + "Öffnet ein neues Fenster für Mail & Newsgroups." | $fold + + echo -n " ${extd}-c${norm}, ${extd}--compose${norm} " + L "Opens 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 + 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` + 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 + } + + # 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" + attn="${esc}[1;33m" + norm=`echo -en "${esc}[m\017"` + stat=`echo -en "\015${esc}[${COLUMNS}C${esc}[10D"` + + rc_done="${done}done${norm}" + rc_running="${stat}${done}running${norm}" + rc_failed="${warn}failed${norm}" + rc_missed="${warn}not found${norm}" + rc_skipped="${stat}${attn}skipped${norm}" + rc_dead="${stat}${warn}not running${norm}" + rc_unused="${stat}${extd}unused${norm}" + rc_done_up="${esc}[1A${rc_done}" + rc_failed_up="${esc}[1A${rc_failed}" + rc_reset="${norm}" + rc_save="${esc}7" + rc_restore="${esc}8" 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="" + attn="" + norm="" + stat="... " + + rc_done="done" + rc_running="running" + rc_failed="failed" + rc_missed="missing" + rc_skipped="skipped" + rc_dead="not running" + rc_unused="unused" + rc_done_up="${rc_done}" + rc_failed_up="${rc_failed}" + rc_reset="" + rc_save="" + rc_restore="" + fi + + # 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 + + # 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 "$*" + if `getopt -T >/dev/null 2>&1` ; [ $? = 4 ] ; then + getopt_type=long + echo "Enhanced getopt(1)" + tmp=`getopt -o vL:hVM:Tkl::n:w:t:-m::ic \ + -l verbose,locale:,help,version,mozilla:,term,kill,list,full,\ + new:,win:,tab:,mailto::,inbox,compose \ + -n "$appname" -s sh \ + -- "$@"` + else + getopt_type=short + echo "Old getopt(1)" + tmp=`getopt vL:hVM:Tkl:n:w:t:-m:ic "$@"` + fi + + getopt_exit_code=$? + help=0 + verbose=0 + + # 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` + + version=0 + mozilla="mozilla" + 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" + 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;; + -T | --term) test -z "$term" && term=t; shift;; + -k | --kill) term=k; shift;; + -l | --list) list=1; list_style=$2; shift 2;; + --) 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 $list -eq 0 && help=1 + set -- $args + else + echo "getopt exited: $getopt_exit_code + " >&2 + if [ $getopt_exit_code -eq 1 ]; then + help=1 + else + exit $getopt_exit_code + fi + fi + + test $version -eq 0 && echo + Title + + test $help -eq 1 && help && test -n "$1" && shift + + echo `L "Send suggestions and bug reports to" \ + "Senden Sie Vorschläge und Fehlerberichte an"`" <$mail_feedback> + " | $fold + + # 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 + shift + test -z "$1" && echo && exit 0 + fi + + # check for list + test $list -eq 1 && ListMoz "$list_style" && exit 0 + + if [ -n "$1" ]; then # 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 + chk=`which mozilla 2>/dev/null` + if [ $? -ne 0 ]; 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 exit 255 fi - # block=0 - # check for block mode - # if [ "$1" = "-b" ] || [ "$1" = "--block" ]; then block=1; shift; fi - + new_win=0 + new_tab=0 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 + 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 for new-tab - new_tab=0 - if [ "$1" = "-t" ] || [ "$1" = "--tab" ]; then new_tab=1; shift; fi + # check if the current user has Mozilla already run + # 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 for disabling new-* - test "$1" = "-" && shift + # 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" - # check if the current user has Mozilla already run - chk=`ps -u $(whoami) | grep mozilla-bin` if [ -z "$chk" ]; then - echo -n "Starting a new Mozilla process" - test -n "$1" && echo -n " with URI '$1'" - echo "..." + echo -n `L "Starting a new Mozilla process" \ + "Starte einen neuen Mozilla-Prozess"` + test -n "$uri" && test $mailto -eq 1 && test $inbox -eq 0 \ + && test $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 + if [ $error -eq 0 ]; then + echo $rc_done + else + echo $rc_failed + fi + 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"`" " + if [ -n "$uri" ]; then + echo -n "'$uri'" + else + echo -n "'about:blank'" + fi + 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 "... " + echo -n "$stat" mozilla -remote "$cmd" & - if [ $? -eq 0 ]; then msg_done; else msg_failed; fi + if [ $? -eq 0 ]; then echo $rc_done; else echo $rc_failed; fi fi - shift - new_win=1 + test -n "$1" && shift + # new_win=1 done fi + echo + test $verbose -eq 1 -o $getopt_exit_code -eq 1 \ + && L "Press any key..." "Beliebige Taste drücken ..." | $fold && read -n 1 + exit 0