Simplify the math to round up to the next multiple of some value.
[tor/rransom.git] / contrib / torify.in
blob5bf7d4dbcf67f629d6d6f3acdf31838f98602ce5
1 #! /bin/sh
3 # Wrapper script for use of the tsocks(8) transparent socksification library
4 # See the tsocks(1) and torify(1) manpages.
6 # Copyright (c) 2004, 2006 Peter Palfrader
7 # Modified by Jacob Appelbaum <jacob@appelbaum.net> April 16th 2006
8 # May be distributed under the same terms as Tor itself
11 # Define and ensure we have tsocks
12 # XXX: what if we don't have which?
13 TORSOCKS="`which torsocks`"
14 TSOCKS="`which tsocks`"
15 PROG=""
16 if [ ! -x "$TSOCKS" ]
17 then
18 echo "$0: Can't find tsocks in PATH. Perhaps you haven't installed it?" >&2
19 else
20 PROG=$TSOCKS
22 if [ ! -x "$TORSOCKS" ]
23 then
24 echo "$0: Can't find torsocks in PATH. Perhaps you haven't installed it?" >&2
25 else
26 PROG=$TORSOCKS
29 if [ ! -x "$PROG" ]
30 then
31 echo "$0: Can't find the required tor helpers in our PATH. Perhaps you haven't installed them?" >&2
32 exit 1;
35 # Check for any argument list
36 if [ "$#" = 0 ]
37 then
38 echo "Usage: $0 [-hv] <command> [<options>...]" >&2
39 exit 1
41 if [ "$#" = 1 ] && ( [ "$1" = "-h" ] || [ "$1" = "--help" ] )
42 then
43 echo "Usage: $0 [-hv] <command> [<options>...]"
44 exit 0
47 if [ "$1" = "-v" ] || [ "$1" = "--verbose" ]
48 then
49 echo "We're armed with the following tsocks: $TSOCKS"
50 echo "We're armed with the following torsocks: $TORSOCKS"
51 echo "We're attempting to use $PROG for all tor action."
52 shift 1
55 if [ "$PROG" = "$TSOCKS" ]
56 then
57 # Define our tsocks config file
58 TSOCKS_CONF_FILE="/etc/tor/tor-tsocks.conf"
59 export TSOCKS_CONF_FILE
61 # Check that we've got a tsocks config file
62 if [ -r "$TSOCKS_CONF_FILE" ]
63 then
64 echo "WARNING: tsocks is known to leak DNS and UDP data." >&2
65 exec tsocks "$@"
66 echo "$0: Failed to exec tsocks $@" >&2
67 exit 1
68 else
69 echo "$0: Missing tsocks configuration file \"$TSOCKS_CONF_FILE\"." >&2
70 exit 1
73 if [ "$PROG" = "$TORSOCKS" ]
74 then
75 exec torsocks "$@"