Guest User

Untitled

a guest
Jul 20th, 2018
67
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.75 KB | None | 0 0
  1. #!/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 similiar features.
  5. #
  6. # To run in debug mode simply pass --debug
  7. #
  8. # Copyright 2011 The Tor Project. See LICENSE for licensing information.
  9.  
  10. complain_dialog_title="Tor Browser Bundle"
  11.  
  12. # First, make sure DISPLAY is set. If it isn't, we're hosed; scream
  13. # at stderr and die.
  14. if [ "x$DISPLAY" = "x" ]; then
  15. echo "$complain_dialog_title must be run within the X Window System." >&2
  16. echo "Exiting." >&2
  17. exit 1
  18. fi
  19.  
  20. # Determine whether we are running in a terminal. If we are, we
  21. # should send our error messages to stderr...
  22. ARE_WE_RUNNING_IN_A_TERMINAL=0
  23. if [ -t 1 -o -t 2 ]; then
  24. ARE_WE_RUNNING_IN_A_TERMINAL=1
  25. fi
  26.  
  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?)
  34. ps T 2>/dev/null |grep startx 2>/dev/null |grep -v grep 2>&1 >/dev/null
  35. not_running_in_same_terminal_as_startx="$?"
  36. ps T 2>/dev/null |grep xinit 2>/dev/null |grep -v grep 2>&1 >/dev/null
  37. not_running_in_same_terminal_as_xinit="$?"
  38.  
  39. # not_running_in_same_terminal_as_foo has the value 1 if we are *not*
  40. # running in the same terminal as foo.
  41. if [ "$not_running_in_same_terminal_as_startx" -eq 0 -o \
  42. "$not_running_in_same_terminal_as_xinit" -eq 0 ]; then
  43. ARE_WE_RUNNING_IN_A_TERMINAL=0
  44. fi
  45.  
  46. # Complain about an error, by any means necessary.
  47. # Usage: complain message
  48. # message must not begin with a dash.
  49. complain () {
  50. # Trim leading newlines, to avoid breaking formatting in some dialogs.
  51. complain_message="`echo "$1" | sed '/./,$!d'`"
  52.  
  53. # If we're being run in a terminal, complain there.
  54. if [ "$ARE_WE_RUNNING_IN_A_TERMINAL" -ne 0 ]; then
  55. echo "$complain_message" >&2
  56. return
  57. fi
  58.  
  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.
  71. zenity --error \
  72. --title="$complain_dialog_title" \
  73. --text="$complain_message"
  74. if [ "$?" -ne 127 ]; then
  75. return
  76. fi
  77.  
  78. # Try kdialog.
  79. kdialog --title "$complain_dialog_title" \
  80. --error "$complain_message"
  81. if [ "$?" -ne 127 ]; then
  82. return
  83. fi
  84.  
  85. # Try xmessage.
  86. xmessage -title "$complain_dialog_title" \
  87. -center \
  88. -buttons OK \
  89. -default OK \
  90. -xrm '*message.scrollVertical: Never' \
  91. "$complain_message"
  92. if [ "$?" -ne 127 ]; then
  93. return
  94. fi
  95.  
  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.
  101. gxmessage -title "$complain_dialog_title" \
  102. -center \
  103. -buttons GTK_STOCK_OK \
  104. -default OK \
  105. "$complain_message"
  106. if [ "$?" -ne 127 ]; then
  107. return
  108. fi
  109. }
  110.  
  111. if [ "`id -u`" -eq 0 ]; then
  112. complain "The Tor Browser Bundle should not be run as root. Exiting."
  113. exit 1
  114. fi
  115.  
  116. usage_message="usage: $0 [--debug]"
  117. if [ "$#" -eq 1 -a \( "x$1" = "x--debug" -o "x$1" = "x-debug" \) ]; then
  118. debug=1
  119. printf "\nDebug enabled.\n\n"
  120. elif [ "$#" -eq 1 -a \( "x$1" = "x--help" -o "x$1" = "x-help" \) ]; then
  121. echo "$usage_message"
  122. exit 0
  123. fi
  124.  
  125. # If XAUTHORITY is unset, set it to its default value of $HOME/.Xauthority
  126. # before we change HOME below. (See xauth(1) and #1945.) XDM and KDM rely
  127. # on applications using this default value.
  128. if [ -z "$XAUTHORITY" ]; then
  129. XAUTHORITY=~/.Xauthority
  130. export XAUTHORITY
  131. fi
  132.  
  133. # If this script is being run through a symlink, we need to know where
  134. # in the filesystem the script itself is, not where the symlink is.
  135. myname="$0"
  136. if [ -L "$myname" ]; then
  137. # XXX readlink is not POSIX, but is present in GNU coreutils
  138. # and on FreeBSD. Unfortunately, the -f option (which follows
  139. # a whole chain of symlinks until it reaches a non-symlink
  140. # path name) is a GNUism, so we have to have a fallback for
  141. # FreeBSD. Fortunately, FreeBSD has realpath instead;
  142. # unfortunately, that's also non-POSIX and is not present in
  143. # GNU coreutils.
  144. #
  145. # If this launcher were a C program, we could just use the
  146. # realpath function, which *is* POSIX. Too bad POSIX didn't
  147. # make that function accessible to shell scripts.
  148.  
  149. # If realpath is available, use it; it Does The Right Thing.
  150. possibly_my_real_name="`realpath "$myname" 2>/dev/null`"
  151. if [ "$?" -eq 0 ]; then
  152. myname="$possibly_my_real_name"
  153. else
  154. # realpath is not available; hopefully readlink -f works.
  155. myname="`readlink -f "$myname" 2>/dev/null`"
  156. if [ "$?" -ne 0 ]; then
  157. # Ugh.
  158. complain "start-tor-browser cannot be run using a symlink on this operating system."
  159. fi
  160. fi
  161. fi
  162.  
  163. # Try to be agnostic to where we're being started from, chdir to where
  164. # the script is.
  165. mydir="`dirname "$myname"`"
  166. test -d "$mydir" && cd "$mydir"
  167.  
  168. # If ${PWD} results in a zero length HOME, we can try something else...
  169. if [ ! "${PWD}" ]; then
  170. # "hacking around some braindamage"
  171. HOME="`pwd`"
  172. export HOME
  173. surveysays="This system has a messed up shell.\n"
  174. else
  175. HOME="${PWD}"
  176. export HOME
  177. fi
  178.  
  179. if ldd ./App/Firefox/firefox-bin | grep -q "libz\.so\.1.*not found"; then
  180. LD_LIBRARY_PATH="${HOME}/Lib:${HOME}/Lib/libz"
  181. else
  182. LD_LIBRARY_PATH="${HOME}/Lib"
  183. fi
  184.  
  185. LDPATH="${HOME}/Lib/"
  186. export LDPATH
  187. export LD_LIBRARY_PATH
  188. DYLD_PRINT_LIBRARIES=1
  189. export DYLD_PRINT_LIBRARIES
  190.  
  191. if [ "${debug}" ]; then
  192. printf "\nStarting Vidalia now\n"
  193. cd "${HOME}"
  194. printf "\nLaunching Vidalia from: `pwd`\n"
  195. # XXX Someday we should pass whatever command-line arguments we got
  196. # (probably filenames or URLs) to Firefox.
  197. ./App/vidalia --loglevel debug --logfile vidalia-debug-log \
  198. --datadir Data/Vidalia/
  199. printf "\nVidalia exited with the following return code: $?\n"
  200. fi
  201.  
  202. # not in debug mode, run proceed normally
  203. printf "\nLaunching Tor Browser Bundle for Linux in ${HOME}\n"
  204. cd "${HOME}"
  205. # XXX Someday we should pass whatever command-line arguments we got
  206. # (probably filenames or URLs) to Firefox.
  207. ./App/vidalia --datadir Data/Vidalia/
  208. exitcode="$?"
  209. if [ "$exitcode" -ne 0 ]; then
  210. complain "Vidalia exited abnormally. Exit code: $exitcode"
  211. exit "$exitcode"
  212. else
  213. printf '\nVidalia exited cleanly.\n'
  214. fi
Add Comment
Please, Sign In to add comment