[tor-commits] [tor-browser-bundle/master] Bug 13375: Allow Linux users to launch TBB from either GUI or shell

mikeperry at torproject.org mikeperry at torproject.org
Thu Mar 26 21:46:41 UTC 2015


commit 3244969e9a513fb6bc2aeb34b220ba7b9a679586
Author: Mike Perry <mikeperry-git at torproject.org>
Date:   Tue Mar 17 15:15:07 2015 -0700

    Bug 13375: Allow Linux users to launch TBB from either GUI or shell
    
    Create a .desktop file that can handle relative launch, can be invoked from
    the shell, and can be relocated to the dock/launcher/desktop after first
    invocation.
    
    This is some black magic right here. Screw the FreeDesktop.org people for
    making this so difficult.
---
 RelativeLink/execdesktop                   |   14 +++++++++++++
 RelativeLink/start-tor-browser             |    7 +++++++
 RelativeLink/start-tor-browser.desktop     |   30 ++++++++++++++++++++++++++++
 gitian/descriptors/linux/gitian-bundle.yml |    2 +-
 4 files changed, 52 insertions(+), 1 deletion(-)

diff --git a/RelativeLink/execdesktop b/RelativeLink/execdesktop
new file mode 100755
index 0000000..0dc7a42
--- /dev/null
+++ b/RelativeLink/execdesktop
@@ -0,0 +1,14 @@
+#!/bin/bash
+
+TBB_START_PROG="$(grep '^X-TorBrowser-ExecShell' $1 | tail -1 | sed 's/^X-TorBrowser-ExecShell=//' | sed 's/%.//')"
+
+shift
+
+if [ "$#" -ge 1 ]
+then
+  echo "Launching '${TBB_START_PROG} $@'..."
+else
+  echo "Launching '${TBB_START_PROG}'..."
+fi
+
+eval "${TBB_START_PROG} $@"
diff --git a/RelativeLink/start-tor-browser b/RelativeLink/start-tor-browser
index 8c51f47..071c80d 100755
--- a/RelativeLink/start-tor-browser
+++ b/RelativeLink/start-tor-browser
@@ -215,6 +215,13 @@ else
 	export HOME
 fi
 
+# Fix up .desktop Icon and Exec Paths, and update the .desktop file from the
+# canonical version if it was changed by the updater.
+cp start-tor-browser.desktop ../
+sed -i -e "s,^Name=.*,Name=Tor Browser,g" ../start-tor-browser.desktop
+sed -i -e "s,^Icon=.*,Icon=$HOME/browser/icons/mozicon128.png,g" ../start-tor-browser.desktop
+sed -i -e "s,^Exec=.*,Exec=sh -c '\"$HOME/start-tor-browser\" || ([ ! -x \"$HOME/start-tor-browser\" ] \&\& \"\$(dirname \"\$*\")\"/Browser/start-tor-browser)' dummy %k,g" ../start-tor-browser.desktop
+
 SYSARCHITECTURE=$(getconf LONG_BIT)
 TORARCHITECTURE=$(expr "$(file TorBrowser/Tor/tor)" : '.*ELF \([[:digit:]]*\)')
 
diff --git a/RelativeLink/start-tor-browser.desktop b/RelativeLink/start-tor-browser.desktop
new file mode 100755
index 0000000..c8be973
--- /dev/null
+++ b/RelativeLink/start-tor-browser.desktop
@@ -0,0 +1,30 @@
+#!/usr/bin/env ./Browser/execdesktop
+#
+# 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).
+#
+# 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
+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
+Icon=web-browser
diff --git a/gitian/descriptors/linux/gitian-bundle.yml b/gitian/descriptors/linux/gitian-bundle.yml
index 9290b91..b6a4a26 100644
--- a/gitian/descriptors/linux/gitian-bundle.yml
+++ b/gitian/descriptors/linux/gitian-bundle.yml
@@ -119,7 +119,7 @@ script: |
   cp RelativeLink/* tor-browser/Browser/
   #
   cd tor-browser
-  ln -s Browser/start-tor-browser
+  cp Browser/start-tor-browser.desktop ./
   unzip ~/build/tor-browser-linux$GBUILD_BITS-gbuilt.zip
   cd Browser/TorBrowser
   unzip ~/build/tor-linux$GBUILD_BITS-gbuilt.zip





More information about the tor-commits mailing list