[tbb-commits] [tor-browser-bundle/master] Bug 15747: Improve Linux startup script argument handling.
mikeperry at torproject.org
mikeperry at torproject.org
Tue Apr 21 22:11:02 UTC 2015
commit 063f65368f32600904945399f7024be3a6ae1f5f
Author: Mike Perry <mikeperry-git at torproject.org>
Date: Mon Apr 20 16:18:38 2015 -0700
Bug 15747: Improve Linux startup script argument handling.
This commit makes the following changes:
1. Allows multiple arguments to be specified at once to start-tor-browser
2. Separates --debug from file logging (and creates --log)
3. Solves #15739 by creating -v and --verbose as --debug aliases
4. Solves #15740 by creating -h and -? aliases for --help.
5. Solves #15741 by creating --detach and using it from the .desktop file
---
RelativeLink/start-tor-browser | 128 ++++++++++++++++++++++----------
RelativeLink/start-tor-browser.desktop | 29 ++++----
2 files changed, 103 insertions(+), 54 deletions(-)
diff --git a/RelativeLink/start-tor-browser b/RelativeLink/start-tor-browser
index 098f506..940ec96 100755
--- a/RelativeLink/start-tor-browser
+++ b/RelativeLink/start-tor-browser
@@ -3,8 +3,6 @@
# GNU/Linux does not really require something like RelativeLink.c
# However, we do want to have the same look and feel with similar features.
#
-# To run in debug mode simply pass --debug
-#
# Copyright 2015 The Tor Project. See LICENSE for licensing information.
complain_dialog_title="Tor Browser"
@@ -35,8 +33,8 @@ complain () {
# Trim leading newlines, to avoid breaking formatting in some dialogs.
complain_message="`echo "$1" | sed '/./,$!d'`"
- # If we're being run in debug mode, complain to stderr.
- if [ "$debug" -eq 1 ]; then
+ # If we're being run in debug/verbose mode, complain to stderr.
+ if [ "$show_output" -eq 1 ]; then
echo "$complain_message" >&2
return
fi
@@ -98,30 +96,82 @@ if [ "`id -u`" -eq 0 ]; then
exit 1
fi
-debug=0
+tbb_usage () {
+ printf "\nTor Browser Script Options\n"
+ printf " --verbose Display Tor and Firefox output in the terminal\n"
+ printf " --log [file] Record Tor and Firefox output in file (default: tor-browser.log)\n"
+ printf " --detach Detach from terminal and run Tor Browser in the background.\n"
+ printf " --register-app Register Tor Browser as a desktop app for this user\n"
+ printf " --unregister-app Unregister Tor Browser as a desktop app for this user\n"
+}
+log_output=0
+show_output=0
+detach=0
show_usage=0
register_desktop_app=0
-# !!! We may have more than one argument, changed -eq to -ge in if & elif clauses below
-if [ "$#" -ge 1 -a \( "x$1" = "x--debug" -o "x$1" = "x-debug" \) ]; then
- debug=1
- shift # pop the debug argument
- printf "\nDebug enabled.\n\n"
-elif [ "$#" -ge 1 -a \( "x$1" = "x--register-app" -o "x$1" = "x-register-app" \) ]; then
- register_desktop_app=1
- shift # pop the register arg
-elif [ "$#" -ge 1 -a \( "x$1" = "x--unregister-app" -o "x$1" = "x-unregister-app" \) ]; then
- register_desktop_app=-1
- shift # pop the register arg
-elif [ "$#" -ge 1 -a \( "x$1" = "x--help" -o "x$1" = "x-help" \) ]; then
- show_usage=1
-else
+logfile=/dev/null
+while :
+do
+ case "$1" in
+ --detach)
+ detach=1
+ shift
+ ;;
+ -v | --verbose | -d | --debug)
+ show_output=1
+ verbose_arg="$2"
+ shift
+ ;;
+ -h | "-?" | --help | -help)
+ show_usage=1
+ show_output=1
+ shift
+ ;;
+ -l | --log)
+ if [ -z "$2" -o "${2:0:1}" == "-" ]; then
+ printf "Logging Tor Browser debug information to tor-browser.log\n"
+ logfile="../tor-browser.log"
+ elif [ "${2:0:1}" == "/" -o "${2:0:1}" == "~" ]; then
+ printf "Logging Tor Browser debug information to %s\n" "$2"
+ logfile="$2"
+ shift
+ else
+ printf "Logging Tor Browser debug information to %s\n" "$2"
+ logfile="../$2"
+ shift
+ fi
+ log_output=1
+ shift
+ ;;
+ --register-app)
+ register_desktop_app=1
+ show_output=1
+ shift
+ ;;
+ --unregister-app)
+ register_desktop_app=-1
+ show_output=1
+ shift
+ ;;
+ *) # No more options
+ break
+ ;;
+ esac
+done
+
+# We can't detach and show output at the same time..
+if [ "$show_output" -eq 1 -a "$detach" -eq 1 ]; then
+ detach=0
+fi
+
+if [ "$show_output" -eq 0 ]; then
# If the user hasn't requested 'debug mode' or --help, close stdout and stderr,
# to keep Firefox and the stuff loaded by/for it (including the
# system's shared-library loader) from printing messages to
# $HOME/.xsession-errors or other files. (Users wouldn't have seen
# messages there anyway.)
- exec >/dev/null
- exec 2>/dev/null
+ exec > "$logfile"
+ exec 2> "$logfile"
fi
# If XAUTHORITY is unset, set it to its default value of $HOME/.Xauthority
@@ -186,7 +236,7 @@ fi
cp start-tor-browser.desktop ../
sed -i -e "s,^Name=.*,Name=Tor Browser,g" ../start-tor-browser.desktop
sed -i -e "s,^Icon=.*,Icon=$PWD/browser/icons/mozicon128.png,g" ../start-tor-browser.desktop
-sed -i -e "s,^Exec=.*,Exec=sh -c '\"$PWD/start-tor-browser\" || ([ ! -x \"$PWD/start-tor-browser\" ] \&\& \"\$(dirname \"\$*\")\"/Browser/start-tor-browser)' dummy %k,g" ../start-tor-browser.desktop
+sed -i -e "s,^Exec=.*,Exec=sh -c '\"$PWD/start-tor-browser\" --detach || ([ ! -x \"$PWD/start-tor-browser\" ] \&\& \"\$(dirname \"\$*\")\"/Browser/start-tor-browser --detach)' dummy %k,g" ../start-tor-browser.desktop
if [ "$register_desktop_app" -eq 1 ]; then
mkdir -p "$HOME/.local/share/applications/"
@@ -292,33 +342,29 @@ setControlPortPasswd ${TOR_CONTROL_PASSWD:='"secret"'}
cd "${HOME}"
-# We pass all command-line arguments we got (except --debug) to Firefox. Use
-# at your own risk!
+# We pass all additional command-line arguments we get to Firefox.
#
# The --class parameter was added to fix bug 11102.
-#
-# When passed the --debug option, we log all the output that goes to the
-# parent terminal stdout and stderr to a file ('tor-browser-debug.log' in Tor
-# Browser's $HOME directory).
+
if [ "$show_usage" -eq 1 ]; then
+ # Display Firefox help, then our help
TOR_CONTROL_PASSWD=${TOR_CONTROL_PASSWD} ./firefox --class "Tor Browser" \
- -profile TorBrowser/Data/Browser/profile.default "${@}" 2>/dev/null
- printf "\nTor Browser Script Options\n"
- printf " --debug Display Tor and Firefox output and record in tor-browser-debug.log\n"
- printf " --register-app Register Tor Browser as a desktop app for this user\n"
- printf " --unregister-app Unregister Tor Browser as a desktop app for this user\n"
-elif [ "$debug" -ne 1 ] ; then
+ -profile TorBrowser/Data/Browser/profile.default --help 2>/dev/null
+ tbb_usage
+elif [ "$detach" -eq 1 ] ; then
TOR_CONTROL_PASSWD=${TOR_CONTROL_PASSWD} ./firefox --class "Tor Browser" \
- -profile TorBrowser/Data/Browser/profile.default "${@}" > /dev/null 2>&1 </dev/null &
+ -profile TorBrowser/Data/Browser/profile.default "${@}" > "$logfile" 2>&1 </dev/null &
disown "$!"
+elif [ "$log_output" -eq 1 -a "$show_output" -eq 1 ]; then
+ TOR_CONTROL_PASSWD=${TOR_CONTROL_PASSWD} ./firefox --class "Tor Browser" \
+ -profile TorBrowser/Data/Browser/profile.default "${@}" 2>&1 </dev/null | \
+ tee "$logfile"
+elif [ "$show_output" -eq 1 ]; then
+ TOR_CONTROL_PASSWD=${TOR_CONTROL_PASSWD} ./firefox --class "Tor Browser" \
+ -profile TorBrowser/Data/Browser/profile.default "${@}" < /dev/null
else
- # Place logfile in the tbb root dir.
- logfile=../tor-browser-debug.log
- printf "Launching Tor Browser for Linux in ${HOME}...\n"
- printf "Logging Tor Browser debug information to file: %s\n" "$logfile"
TOR_CONTROL_PASSWD=${TOR_CONTROL_PASSWD} ./firefox --class "Tor Browser" \
- -profile TorBrowser/Data/Browser/profile.default "${@}" -jsconsole 2>&1 </dev/null | \
- tee $logfile
+ -profile TorBrowser/Data/Browser/profile.default "${@}" > "$logfile" 2>&1 </dev/null
fi
exit $?
diff --git a/RelativeLink/start-tor-browser.desktop b/RelativeLink/start-tor-browser.desktop
index c8be973..d6c1c63 100755
--- a/RelativeLink/start-tor-browser.desktop
+++ b/RelativeLink/start-tor-browser.desktop
@@ -3,21 +3,24 @@
# This file is a self-modifying .desktop file that can be run from the shell.
# It preserves arguments and environment for the start-tor-browser script.
#
-# When run, it will update itself with the absolute path to the current TBB
-# location. It is therefore possible to install/relocate this file after first
-# run (for example, by copying it to ~/.local/share/applications/ so that Tor
-# Browser will appear in your desktop applications menu).
+# Run './start-tor-browser.desktop --help' to display the full set of options.
+#
+# When invoked from the shell, this file must always be in a Tor Browser root
+# directory. When run from the file manager or desktop GUI, it is relocatable.
+#
+# After first invocation, it will update itself with the absolute path to the
+# current TBB location, to support relocation of this .desktop file for GUI
+# invocation. You can also add Tor Browser to your desktop's application menu
+# by running './start-tor-browser.desktop --register-app'
+#
+# If you use --register-app, and then relocate your TBB directory, Tor Browser
+# will no longer launch from your desktop's app launcher/dock. However, if you
+# re-run --register-app from inside that new directory, the script
+# will correct the absolute paths and re-register itself.
#
# This file will also still function if the path changes when TBB is used as a
# portable app, so long as it is run directly from that new directory, either
# via the shell or via the file manager.
-#
-# If you installed this file to ~/.local/share/applications/ and then relocate
-# your TBB directory, Tor Browser will no longer launch from your desktop's
-# app launcher/dock. However, if you re-run this file from inside that new
-# directory, it will correct the absolute paths, and you can then copy it back
-# into ~/.local/share/applications/ again to restore desktop launch
-# functionality.
[Desktop Entry]
Type=Application
@@ -25,6 +28,6 @@ Name=Tor Browser Setup
GenericName=Web Browser
Comment=Tor Browser is +1 for privacy and -1 for mass surveillance
Categories=Network;WebBrowser;Security;
-Exec=sh -c '"$(dirname "$*")"/Browser/start-tor-browser || ([ ! -x "$(dirname "$*")"/Browser/start-tor-browser ] && "$(dirname "$*")"/start-tor-browser)' dummy %k
-X-TorBrowser-ExecShell=./Browser/start-tor-browser
+Exec=sh -c '"$(dirname "$*")"/Browser/start-tor-browser --detach || ([ ! -x "$(dirname "$*")"/Browser/start-tor-browser ] && "$(dirname "$*")"/start-tor-browser --detach)' dummy %k
+X-TorBrowser-ExecShell=./Browser/start-tor-browser --detach
Icon=web-browser
More information about the tbb-commits
mailing list