torify 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #! /bin/sh
  2. # This script used to call (the now deprecated) tsocks as a fallback in case
  3. # torsocks wasn't installed.
  4. # Now, it's just a backwards compatible shim around torsocks with reasonable
  5. # behavior if -v/--verbose or -h/--help arguments are passed.
  6. #
  7. # Copyright (c) 2004, 2006, 2009 Peter Palfrader
  8. # Modified by Jacob Appelbaum <jacob@appelbaum.net> April 16th 2006
  9. # Stripped of all the tsocks cruft by ugh on February 22nd 2012
  10. # May be distributed under the same terms as Tor itself
  11. compat() {
  12. echo "torify is now just a wrapper around torsocks(1) for backwards compatibility."
  13. }
  14. usage() {
  15. compat
  16. echo "Usage: $0 [-hv] <command> [<options>...]"
  17. }
  18. case $# in 0)
  19. usage >&2
  20. exit 1
  21. esac
  22. case $# in 1)
  23. case $1 in -h|--help)
  24. usage
  25. exit 0
  26. esac
  27. esac
  28. case $1 in -v|--verbose)
  29. compat >&2
  30. shift
  31. esac
  32. # taken from Debian's Developer's Reference, 6.4
  33. pathfind() {
  34. OLDIFS="$IFS"
  35. IFS=:
  36. for p in $PATH; do
  37. if [ -x "$p/$*" ]; then
  38. IFS="$OLDIFS"
  39. return 0
  40. fi
  41. done
  42. IFS="$OLDIFS"
  43. return 1
  44. }
  45. if pathfind torsocks; then
  46. exec torsocks "$@"
  47. echo "$0: Failed to exec torsocks $@" >&2
  48. exit 1
  49. else
  50. echo "$0: torsocks not found in your PATH. Perhaps it isn't installed? (tsocks is no longer supported, for security reasons.)" >&2
  51. fi