Ticket #7266: 0001-RelativeLink.sh-Only-comments-changed.-for-comments-.patch

File 0001-RelativeLink.sh-Only-comments-changed.-for-comments-.patch, 12.3 KB (added by proper, 6 years ago)
  • src/RelativeLink/RelativeLink.sh

    From c4dd7ea5819acdfdcff683b5f9a9d5318be7e7aa Mon Sep 17 00:00:00 2001
    From: adrelanos <invalid@invalid>
    Date: Wed, 31 Oct 2012 09:28:34 +0000
    Subject: [PATCH] RelativeLink.sh: Only comments changed. ## for comments, #
     for commented out commands. Documented TOR_TRANSPROXY,
     TOR_SOCKS_HOST and TOR_SOCKS_PORT.
    
    ---
     src/RelativeLink/RelativeLink.sh |  202 ++++++++++++++++++++++----------------
     1 file changed, 120 insertions(+), 82 deletions(-)
    
    diff --git a/src/RelativeLink/RelativeLink.sh b/src/RelativeLink/RelativeLink.sh
    index 35846b1..432bcff 100755
    a b  
    11#!/bin/sh
    2 #
    3 # GNU/Linux does not really require something like RelativeLink.c
    4 # However, we do want to have the same look and feel with similar features.
    5 #
    6 # To run in debug mode simply pass --debug
    7 #
    8 # Copyright 2011 The Tor Project.  See LICENSE for licensing information.
     2
     3##############
     4## Comments ##
     5##############
     6
     7## ## are comments.
     8## # for out commented commands.
     9
     10## Copyright 2011 The Tor Project.  See LICENSE for licensing information.
     11
     12## To run in debug mode simply pass --debug
     13
     14## If you want to start multiple instances of Tor Browser without Tor/Vidalia,
     15## search the script for "-no-remote" and read the comment above.
     16
     17## Set to 1 if you want to use Tor Browser behind a transparent proxy.
     18## NOTE: If you want to deactivate it later, you have to use:
     19##    unset TOR_TRANSPROXY
     20## This was introduced in Tor Button 1.4.6.2.
     21##     https://trac.torproject.org/projects/tor/ticket/6254
     22#TOR_TRANSPROXY=0
     23
     24## You need these to specify a SOCKS host (if not transtor):
     25#TOR_SOCKS_HOST="127.0.0.1"
     26
     27## You need these to specify a SOCKS port (if not transtor):
     28#TOR_SOCKS_PORT="9050"
     29
     30##########
     31## Code ##
     32##########
     33
     34##
     35## GNU/Linux does not really require something like RelativeLink.c
     36## However, we do want to have the same look and feel with similar features.
     37##
    938
    1039complain_dialog_title="Tor Browser Bundle"
    1140
    12 # First, make sure DISPLAY is set.  If it isn't, we're hosed; scream
    13 # at stderr and die.
     41## First, make sure DISPLAY is set.  If it isn't, we're hosed; scream
     42## at stderr and die.
    1443if [ "x$DISPLAY" = "x" ]; then
    1544        echo "$complain_dialog_title must be run within the X Window System." >&2
    1645        echo "Exiting." >&2
    1746        exit 1
    1847fi
    1948
    20 # Determine whether we are running in a terminal.  If we are, we
    21 # should send our error messages to stderr...
     49## Determine whether we are running in a terminal.  If we are, we
     50## should send our error messages to stderr...
    2251ARE_WE_RUNNING_IN_A_TERMINAL=0
    2352if [ -t 1 -o -t 2 ]; then
    2453        ARE_WE_RUNNING_IN_A_TERMINAL=1
    2554fi
    2655
    27 # ...unless we're running in the same terminal as startx or xinit.  In
    28 # that case, the user is probably running us from a GUI file manager
    29 # in an X session started by typing startx at the console.
    30 #
    31 # Hopefully, the local ps command supports BSD-style options.  (The ps
    32 # commands usually used on Linux and FreeBSD do; do any other OSes
    33 # support running Linux binaries?)
     56## ...unless we're running in the same terminal as startx or xinit.  In
     57## that case, the user is probably running us from a GUI file manager
     58## in an X session started by typing startx at the console.
     59##
     60## Hopefully, the local ps command supports BSD-style options.  (The ps
     61## commands usually used on Linux and FreeBSD do; do any other OSes
     62## support running Linux binaries?)
    3463ps T 2>/dev/null |grep startx 2>/dev/null |grep -v grep 2>&1 >/dev/null
    3564not_running_in_same_terminal_as_startx="$?"
    3665ps T 2>/dev/null |grep xinit 2>/dev/null |grep -v grep 2>&1 >/dev/null
    3766not_running_in_same_terminal_as_xinit="$?"
    3867
    39 # not_running_in_same_terminal_as_foo has the value 1 if we are *not*
    40 # running in the same terminal as foo.
     68## not_running_in_same_terminal_as_foo has the value 1 if we are *not*
     69## running in the same terminal as foo.
    4170if [ "$not_running_in_same_terminal_as_startx" -eq 0 -o \
    4271     "$not_running_in_same_terminal_as_xinit" -eq 0 ]; then
    4372        ARE_WE_RUNNING_IN_A_TERMINAL=0
    4473fi
    4574
    46 # Complain about an error, by any means necessary.
    47 # Usage: complain message
    48 # message must not begin with a dash.
     75## Complain about an error, by any means necessary.
     76## Usage: complain message
     77## message must not begin with a dash.
    4978complain () {
    50         # Trim leading newlines, to avoid breaking formatting in some dialogs.
     79        ## Trim leading newlines, to avoid breaking formatting in some dialogs.
    5180        complain_message="`echo "$1" | sed '/./,$!d'`"
    5281
    53         # If we're being run in a terminal, complain there.
     82        ## If we're being run in a terminal, complain there.
    5483        if [ "$ARE_WE_RUNNING_IN_A_TERMINAL" -ne 0 ]; then
    5584                echo "$complain_message" >&2
    5685                return
    5786        fi
    5887
    59         # Otherwise, we're being run by a GUI program of some sort;
    60         # try to pop up a message in the GUI in the nicest way
    61         # possible.
    62         #
    63         # In mksh, non-existent commands return 127; I'll assume all
    64         # other shells set the same exit code if they can't run a
    65         # command.  (xmessage returns 1 if the user clicks the WM
    66         # close button, so we do need to look at the exact exit code,
    67         # not just assume the command failed to display a message if
    68         # it returns non-zero.)
    69 
    70         # First, try zenity.
     88        ## Otherwise, we're being run by a GUI program of some sort;
     89        ## try to pop up a message in the GUI in the nicest way
     90        ## possible.
     91        ##
     92        ## In mksh, non-existent commands return 127; I'll assume all
     93        ## other shells set the same exit code if they can't run a
     94        ## command.  (xmessage returns 1 if the user clicks the WM
     95        ## close button, so we do need to look at the exact exit code,
     96        ## not just assume the command failed to display a message if
     97        ## it returns non-zero.)
     98
     99        ## First, try zenity.
    71100        zenity --error \
    72101                --title="$complain_dialog_title" \
    73102                --text="$complain_message"
    complain () { 
    75104                return
    76105        fi
    77106
    78         # Try kdialog.
     107        ## Try kdialog.
    79108        kdialog --title "$complain_dialog_title" \
    80109                --error "$complain_message"
    81110        if [ "$?" -ne 127 ]; then
    82111                return
    83112        fi
    84113
    85         # Try xmessage.
     114        ## Try xmessage.
    86115        xmessage -title "$complain_dialog_title" \
    87116                -center \
    88117                -buttons OK \
    complain () { 
    93122                return
    94123        fi
    95124
    96         # Try gxmessage.  This one isn't installed by default on
    97         # Debian with the default GNOME installation, so it seems to
    98         # be the least likely program to have available, but it might
    99         # be used by one of the 'lightweight' Gtk-based desktop
    100         # environments.
     125        ## Try gxmessage.  This one isn't installed by default on
     126        ## Debian with the default GNOME installation, so it seems to
     127        ## be the least likely program to have available, but it might
     128        ## be used by one of the 'lightweight' Gtk-based desktop
     129        ## environments.
    101130        gxmessage -title "$complain_dialog_title" \
    102131                -center \
    103132                -buttons GTK_STOCK_OK \
    elif [ "$#" -eq 1 -a \( "x$1" = "x--help" -o "x$1" = "x-help" \) ]; then 
    123152        exit 0
    124153fi
    125154
    126 # If the user hasn't requested 'debug mode', close whichever of stdout
    127 # and stderr are not ttys, to keep Vidalia and the stuff loaded by/for
    128 # it (including the system's shared-library loader) from printing
    129 # messages to $HOME/.xsession-errors .  (Users wouldn't have seen
    130 # messages there anyway.)
    131 #
    132 # If the user has requested 'debug mode', don't muck with the FDs.
     155## If the user hasn't requested 'debug mode', close whichever of stdout
     156## and stderr are not ttys, to keep Vidalia and the stuff loaded by/for
     157## it (including the system's shared-library loader) from printing
     158## messages to $HOME/.xsession-errors .  (Users wouldn't have seen
     159## messages there anyway.)
     160##
     161## If the user has requested 'debug mode', don't muck with the FDs.
    133162if [ "$debug" -ne 1 ]; then
    134163  if [ '!' -t 1 ]; then
    135     # stdout is not a tty
     164    ## stdout is not a tty
    136165    exec >/dev/null
    137166  fi
    138167  if [ '!' -t 2 ]; then
    139     # stderr is not a tty
     168    ## stderr is not a tty
    140169    exec 2>/dev/null
    141170  fi
    142171fi
    143172
    144 # If XAUTHORITY is unset, set it to its default value of $HOME/.Xauthority
    145 # before we change HOME below.  (See xauth(1) and #1945.)  XDM and KDM rely
    146 # on applications using this default value.
     173## If XAUTHORITY is unset, set it to its default value of $HOME/.Xauthority
     174## before we change HOME below.  (See xauth(1) and #1945.)  XDM and KDM rely
     175## on applications using this default value.
    147176if [ -z "$XAUTHORITY" ]; then
    148177        XAUTHORITY=~/.Xauthority
    149178        export XAUTHORITY
    150179fi
    151180
    152 # If this script is being run through a symlink, we need to know where
    153 # in the filesystem the script itself is, not where the symlink is.
     181## If this script is being run through a symlink, we need to know where
     182## in the filesystem the script itself is, not where the symlink is.
    154183myname="$0"
    155184if [ -L "$myname" ]; then
    156         # XXX readlink is not POSIX, but is present in GNU coreutils
    157         # and on FreeBSD.  Unfortunately, the -f option (which follows
    158         # a whole chain of symlinks until it reaches a non-symlink
    159         # path name) is a GNUism, so we have to have a fallback for
    160         # FreeBSD.  Fortunately, FreeBSD has realpath instead;
    161         # unfortunately, that's also non-POSIX and is not present in
    162         # GNU coreutils.
    163         #
    164         # If this launcher were a C program, we could just use the
    165         # realpath function, which *is* POSIX.  Too bad POSIX didn't
    166         # make that function accessible to shell scripts.
    167 
    168         # If realpath is available, use it; it Does The Right Thing.
     185        ## XXX readlink is not POSIX, but is present in GNU coreutils
     186        ## and on FreeBSD.  Unfortunately, the -f option (which follows
     187        ## a whole chain of symlinks until it reaches a non-symlink
     188        ## path name) is a GNUism, so we have to have a fallback for
     189        ## FreeBSD.  Fortunately, FreeBSD has realpath instead;
     190        ## unfortunately, that's also non-POSIX and is not present in
     191        ## GNU coreutils.
     192        ##
     193        ## If this launcher were a C program, we could just use the
     194        ## realpath function, which *is* POSIX.  Too bad POSIX didn't
     195        ## make that function accessible to shell scripts.
     196
     197        ## If realpath is available, use it; it Does The Right Thing.
    169198        possibly_my_real_name="`realpath "$myname" 2>/dev/null`"
    170199        if [ "$?" -eq 0 ]; then
    171200                myname="$possibly_my_real_name"
    172201        else
    173                 # realpath is not available; hopefully readlink -f works.
     202                ## realpath is not available; hopefully readlink -f works.
    174203                myname="`readlink -f "$myname" 2>/dev/null`"
    175204                if [ "$?" -ne 0 ]; then
    176                         # Ugh.
     205                        ## Ugh.
    177206                        complain "start-tor-browser cannot be run using a symlink on this operating system."
    178207                fi
    179208        fi
    180209fi
    181210
    182 # Try to be agnostic to where we're being started from, chdir to where
    183 # the script is.
     211## Try to be agnostic to where we're being started from, chdir to where
     212## the script is.
    184213mydir="`dirname "$myname"`"
    185214test -d "$mydir" && cd "$mydir"
    186215
    187 # If ${PWD} results in a zero length HOME, we can try something else...
     216## If ${PWD} results in a zero length HOME, we can try something else...
    188217if [ ! "${PWD}" ]; then
    189         # "hacking around some braindamage"
     218        ## "hacking around some braindamage"
    190219        HOME="`pwd`"
    191220        export HOME
    192221        surveysays="This system has a messed up shell.\n"
    if [ "$debug" -eq 1 ]; then 
    209238        printf "\nStarting Vidalia now\n"
    210239        cd "${HOME}"
    211240        printf "\nLaunching Vidalia from: `pwd`\n"
    212         # XXX Someday we should pass whatever command-line arguments we got
    213         # (probably filenames or URLs) to Firefox.
     241        ## XXX Someday we should pass whatever command-line arguments we got
     242        ## (probably filenames or URLs) to Firefox.
    214243        ./App/vidalia --loglevel debug --logfile vidalia-debug-log \
    215244        --datadir Data/Vidalia/ -style Cleanlooks
    216245        printf "\nVidalia exited with the following return code: $?\n"
    217246        exit
    218247fi
    219248
    220 # not in debug mode, run proceed normally
     249## not in debug mode, run proceed normally
    221250printf "\nLaunching Tor Browser Bundle for Linux in ${HOME}\n"
    222251cd "${HOME}"
    223 # XXX Someday we should pass whatever command-line arguments we got
    224 # (probably filenames or URLs) to Firefox.
     252## XXX Someday we should pass whatever command-line arguments we got
     253## (probably filenames or URLs) to Firefox.
    225254./App/vidalia --datadir Data/Vidalia/ -style Cleanlooks
     255## If you want to start multiple instances of Tor Browser without Tor/Vidalia,
     256## out comment the line above and activate the line below.
     257#./App/Firefox/firefox --profile Data/profile
     258##
     259## See:
     260## - https://trac.torproject.org/projects/tor/wiki/doc/TorifyHOWTO/WebBrowsers
     261## - http://kb.mozillazine.org/Opening_a_new_instance_of_Firefox_with_another_profile
     262##
     263#./App/Firefox/firefox --profile Data/profile -no-remote
    226264exitcode="$?"
    227265if [ "$exitcode" -ne 0 ]; then
    228266        complain "Vidalia exited abnormally.  Exit code: $exitcode"