home *** CD-ROM | disk | FTP | other *** search
/ Clickx 115 / Clickx 115.iso / software / tools / windows / tails-i386-0.16.iso / live / filesystem.squashfs / usr / bin / usewithtor < prev    next >
Encoding:
Text File  |  2012-03-03  |  3.6 KB  |  114 lines

  1. #! /bin/sh
  2. # ***************************************************************************
  3. # *                                                                         *
  4. # *   Copyright (C) 2008-2011 Robert Hogan <robert@roberthogan.net>         *
  5. # *                                                                         *
  6. # *   This program is free software; you can redistribute it and/or modify  *
  7. # *   it under the terms of the GNU General Public License as published by  *
  8. # *   the Free Software Foundation; either version 2 of the License, or     *
  9. # *   (at your option) any later version.                                   *
  10. # *                                                                         *
  11. # *   This program is distributed in the hope that it will be useful,       *
  12. # *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
  13. # *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
  14. # *   GNU General Public License for more details.                          *
  15. # *                                                                         *
  16. # *   You should have received a copy of the GNU General Public License     *
  17. # *   along with this program; if not, write to the                         *
  18. # *   Free Software Foundation, Inc.,                                       *
  19. #*   59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.             *
  20. # ***************************************************************************
  21. # *                                                                         *
  22. # *   This is a modified version of a source file from the Tor project.     *
  23. # *   Original copyright notice from tsocks source file follows:            *
  24. # ***************************************************************************
  25.  
  26. # Wrapper script for use of the tsocks(8) transparent socksification library
  27. # See the tsocks(1) and torify(1) manpages.
  28.  
  29. # Copyright (c) 2004, 2006 Peter Palfrader
  30. # Modified by Jacob Appelbaum <jacob@appelbaum.net> April 16th 2006
  31. # Modified by Marcus Griep <marcus@griep.us> June 16 2009
  32. # May be distributed under the same terms as Tor itself
  33.  
  34.  
  35. # Define and ensure we have tsocks
  36. # XXX: what if we don't have which?
  37. TORSOCKS="`which torsocks`"
  38. PROG=
  39. VERBOSE=
  40.  
  41. usage () {
  42.     echo "Usage: $0 [-hv] <command> [<options>...]"
  43. }
  44.  
  45. not_found () {
  46.     echo "ERROR: $1 cannot be found in PATH." >&2
  47.     exit 1
  48. }
  49.  
  50. set_id () {
  51.     echo "ERROR: $1 is set${2}id. usewithtor will not work on a set${2}id executable." >&2
  52.     exit 1
  53. }
  54.  
  55. # Check for any argument list
  56. if [ "$#" = 0 ]; then
  57.     usage >&2
  58.     exit 1
  59. fi
  60.  
  61. while [ "$1" ]; do
  62.     case "$1" in
  63.         -h|--h*)
  64.             usage
  65.             exit 0
  66.             ;;
  67.         -v|--v*)
  68.             VERBOSE=YesPlease
  69.             shift
  70.             ;;
  71.         *)
  72.             break;
  73.     esac
  74. done
  75.  
  76. if ! which "$1" >/dev/null 2>&1; then
  77.     not_found $1
  78. elif [ -u `which "$1"` ]; then
  79.     set_id $1 u
  80. elif [ -g `which "$1"` ]; then
  81.     set_id $1 g
  82. fi
  83.  
  84. if [ -x "$TORSOCKS" ]; then
  85.     PROG=torsocks
  86. else
  87.     echo "$0: Unable to find torsocks in PATH." >&2
  88.     echo "    Perhaps you haven't installed it?" >&2
  89.     exit 1
  90. fi
  91.  
  92. if [ "$VERBOSE" ]; then
  93.     echo "We're armed with the following torsocks: $TORSOCKS"
  94.     echo "We're attempting to use $PROG for all tor action."
  95. fi
  96.  
  97. if [ "$PROG" = "torsocks" ]; then
  98.     # Define our torsocks config file
  99.     TORSOCKS_CONF_FILE="/etc/torsocks.conf"
  100.     export TORSOCKS_CONF_FILE
  101.  
  102.     # Check that we've got a torsocks config file
  103.     if [ -r "$TORSOCKS_CONF_FILE" ];     then
  104.         exec torsocks "$@"
  105.     else
  106.         echo "$0: Missing torsocks configuration file \"$TORSOCKS_CONF_FILE\" - torsocks will use defaults sensible for Tor." >&2
  107.         exec torsocks "$@"
  108.     fi
  109. fi
  110.  
  111. # We should have hit an exec. If we get here, we didn't exec
  112. echo "$0: failed to exec $PROG $@" >&2
  113. exit 1
  114.