Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
[SOLVED] How to call the portable Tor Browser from cmd line
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Networking & Security
View previous topic :: View next topic  
Author Message
vcmota
Tux's lil' helper
Tux's lil' helper


Joined: 19 Jun 2017
Posts: 145

PostPosted: Wed Sep 11, 2019 5:47 pm    Post subject: [SOLVED] How to call the portable Tor Browser from cmd line Reply with quote

My question feels very basic and it probably is, but I have not been capable of sorting it out myself. I downloaded the portable Tor Browser, and to launch it every time I need to enter its folder and run

Code:

~> cd tor-browser_en-US/
tor-browser_en-US> ./start-tor-browser.desktop
~>


This is ok, but I would love it if I could just have instead an universal command, say MyTorBrowser, which I could call from any command line. Since I use DWM with dmenu, that would be great because it could than be launched from dmenu directly without the need of opening any terminal. To do this I first tried simply to include the tor folder in my PATH, which wont work because when launching the browser searches for files inside its folder assuming you are launching it from its folder. I tried a hard link with "ln" and after a simbolic link with "ln -s" and neither worked as well.

I appreciate any help, thank you all.


Last edited by vcmota on Thu Sep 12, 2019 4:05 am; edited 1 time in total
Back to top
View user's profile Send private message
GDH-gentoo
n00b
n00b


Joined: 20 Jul 2019
Posts: 65
Location: South America

PostPosted: Wed Sep 11, 2019 7:25 pm    Post subject: Re: How to call the portable Tor Browser from cmd line Reply with quote

vcmota wrote:
Code:
~> cd tor-browser_en-US/
tor-browser_en-US> ./start-tor-browser.desktop
~>

Is start-tor-browser.desktop a shell script, or a desktop entry file? What does file start-tor-browser.desktop say?
Back to top
View user's profile Send private message
Hu
Moderator
Moderator


Joined: 06 Mar 2007
Posts: 14062

PostPosted: Thu Sep 12, 2019 1:27 am    Post subject: Re: How to call the portable Tor Browser from cmd line Reply with quote

vcmota wrote:
This is ok, but I would love it if I could just have instead an universal command, say MyTorBrowser, which I could call from any command line.
So you want a shell script to wrap those two steps for you?
Code:
#!/bin/sh
cd "$HOME/tor-browser_en-US/" && exec ./start-tor-browser.desktop
vcmota wrote:
I first tried simply to include the tor folder in my PATH, which wont work because when launching the browser searches for files inside its folder assuming you are launching it from its folder.
This is confusing. If it searches inside its directory (not folder), then how can it not find files inside its directory, since that is where it is searching? Did you mean that it assumes the current working directory is the directory in which it was installed? If so, that seems like a bug to me. Users can run a program from anywhere, and the ability to find supporting files shouldn't depend on users to start in one particular directory.
Back to top
View user's profile Send private message
Jaglover
Watchman
Watchman


Joined: 29 May 2005
Posts: 7196
Location: Saint Amant, Acadiana

PostPosted: Thu Sep 12, 2019 2:03 am    Post subject: Reply with quote

Isn't the actual command line inside of that desktop file?
_________________
Please learn how to denote units correctly!
Back to top
View user's profile Send private message
vcmota
Tux's lil' helper
Tux's lil' helper


Joined: 19 Jun 2017
Posts: 145

PostPosted: Thu Sep 12, 2019 4:00 am    Post subject: Re: How to call the portable Tor Browser from cmd line Reply with quote

GDH-gentoo wrote:
vcmota wrote:
Code:
~> cd tor-browser_en-US/
tor-browser_en-US> ./start-tor-browser.desktop
~>

Is start-tor-browser.desktop a shell script, or a desktop entry file? What does file start-tor-browser.desktop say?

Thank you GDH-gentoo for your reply. It is in fact a script:

Code:

tor-browser_en-US> file start-tor-browser.desktop
start-tor-browser.desktop: a /usr/bin/env ./Browser/execdesktop script, ASCII text executable
tor-browser_en-US>


but one which relies in running
Code:
 /usr/bin/env ./Browser/execdesktop 


Anyway, after find out it was a script I opened it and that is what it is:

Code:

tor-browser_en-US> cat start-tor-browser.desktop
#!/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.
#
# 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.

[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 --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
StartupWMClass=Tor Browser
tor-browser_en-US>


So apparently it comes with a built in solution, which is just running

Code:

tor-browser_en-US> ./start-tor-browser.desktop --register-app
Launching './Browser/start-tor-browser --detach --register-app'...
Tor Browser has been registered as a desktop app for this user in ~/.local/share/applications/
tor-browser_en-US>


but, even after adding "~/.local/share/applications/" to my PATH the problem persists unless I am inside the tor folder:


Code:

~> start-tor-browser.desktop
/usr/bin/env: ‘./Browser/execdesktop’: No such file or directory
~>



Than I noticed that the script has been modified by the command "./start-tor-browser.desktop --register-app":

Code:

tor-browser_en-US> cat start-tor-browser.desktop
#!/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.
#
# 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.

[Desktop Entry]
Type=Application
Name=Tor Browser
GenericName=Web Browser
Comment=Tor Browser is +1 for privacy and -1 for mass surveillance
Categories=Network;WebBrowser;Security;
Exec=sh -c '"/home/vinicius/tor-browser_en-US/Browser/start-tor-browser" --detach || ([ !  -x "/home/vinicius/tor-browser_en-US/Browser/start-tor-browser" ] && "$(dirname "$*")"/Browser/start-tor-browser --detach)' dummy %k
X-TorBrowser-ExecShell=./Browser/start-tor-browser --detach
Icon=/home/vinicius/tor-browser_en-US/Browser/browser/chrome/icons/default/default128.png
StartupWMClass=Tor Browser
tor-browser_en-US>


where you can see that "$(dirname "$*")" has been replaced by /home/vinicius/, so my full path. However as seen above that has not happened everywhere in the script, so I "corrected" it manually, adding the full path, and now the script reads:

Code:

~> cat ~/.local/share/applications/start-tor-browser.desktop
#!/usr/bin/env /home/vinicius/tor-browser_en-US/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.
#
# 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.

[Desktop Entry]
Type=Application
Name=Tor Browser
GenericName=Web Browser
Comment=Tor Browser is +1 for privacy and -1 for mass surveillance
Categories=Network;WebBrowser;Security;
Exec=sh -c '"/home/vinicius/tor-browser_en-US/Browser/start-tor-browser" --detach || ([ !  -x "/home/vinicius/tor-browser_en-US/Browser/start-tor-browser" ] && "/home/vinicius/tor-browser_en-US/Browser/start-tor-browser" --detach)' dummy %k
X-TorBrowser-ExecShell=/home/vinicius/tor-browser_en-US/Browser/start-tor-browser --detach
Icon=/home/vinicius/tor-browser_en-US/Browser/browser/chrome/icons/default/default128.png
StartupWMClass=Tor Browser
~>



and now it works! As you can see launching returns to errors

Code:

~> start-tor-browser.desktop
Launching '/home/vinicius/tor-browser_en-US/Browser/start-tor-browser --detach'...
~>


and Tor starts as it should, even when launching from dmenu. So besides my dumbness in the first place, it appears there is an error in their script.

Thank you all for your help!


Last edited by vcmota on Thu Sep 12, 2019 4:10 am; edited 1 time in total
Back to top
View user's profile Send private message
vcmota
Tux's lil' helper
Tux's lil' helper


Joined: 19 Jun 2017
Posts: 145

PostPosted: Thu Sep 12, 2019 4:08 am    Post subject: Re: How to call the portable Tor Browser from cmd line Reply with quote

Hu wrote:
vcmota wrote:
This is ok, but I would love it if I could just have instead an universal command, say MyTorBrowser, which I could call from any command line.
So you want a shell script to wrap those two steps for you?
Code:
#!/bin/sh
cd "$HOME/tor-browser_en-US/" && exec ./start-tor-browser.desktop
vcmota wrote:
I first tried simply to include the tor folder in my PATH, which wont work because when launching the browser searches for files inside its folder assuming you are launching it from its folder.
This is confusing. If it searches inside its directory (not folder), then how can it not find files inside its directory, since that is where it is searching? Did you mean that it assumes the current working directory is the directory in which it was installed? If so, that seems like a bug to me. Users can run a program from anywhere, and the ability to find supporting files shouldn't depend on users to start in one particular directory.


Thank you Hu for your reply. The launching script apparently was planned to do all this work. However, as you may see in my larger reply, it was buggy, but not beyond manual repair.
Back to top
View user's profile Send private message
vcmota
Tux's lil' helper
Tux's lil' helper


Joined: 19 Jun 2017
Posts: 145

PostPosted: Thu Sep 12, 2019 4:09 am    Post subject: Reply with quote

Jaglover wrote:
Isn't the actual command line inside of that desktop file?


Thank you Jag Lover for your reply. No, apparently the actual command is in a folder inside the principal tor-browser folder, and that file is a simple script.
Back to top
View user's profile Send private message
GDH-gentoo
n00b
n00b


Joined: 20 Jul 2019
Posts: 65
Location: South America

PostPosted: Fri Sep 13, 2019 3:15 am    Post subject: Re: How to call the portable Tor Browser from cmd line Reply with quote

vcmota wrote:
Anyway, after find out it was a script I opened it and that is what it is:

Code:

tor-browser_en-US> cat start-tor-browser.desktop
#!/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.
#
# 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'
...
[Desktop Entry]
Type=Application
...

Huh. So this is both a desktop entry file and a script. That's creative, and bordering on mechanism abuse :lol: It has the format of a desktop entry file (of type Application), so the Tor browser can be launched by GUI programs that look for .desktop files in the applications subdirectory of ~/.local/share (or wherever $XDG_DATA_HOME points to) and understand their format. But lines that start with '#' are comments, and the first line is also a shebang line ("#!"), so if the file is executed, the kernel will invoke execdesktop as the interpreter.

I guess dmenu does not understand .desktop files, so it cannot do "GUI invocation", but instead one just configures program invocations somewhere. As Jaglover said, the actual command line is inside the file, it is in the Exec= line, after the file has "updated itself":

Code:
Exec=sh -c '"/home/vinicius/tor-browser_en-US/Browser/start-tor-browser" --detach || ([ !  -x "/home/vinicius/tor-browser_en-US/Browser/start-tor-browser" ] && "$(dirname "$*")"/Browser/start-tor-browser --detach)' dummy %k

If you don't move the "Tor Browser root directory" (/home/vinicius/tor-browser_en-US), the command you configure dmenu with to launch the Tor browser can be shortened to:

Code:
/home/vinicius/tor-browser_en-US/Browser/start-tor-browser --detach
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Networking & Security All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum