dirvote: Handling adding vote and signature if module is disabled
[tor.git] / src / test / test-network.sh
blob6e0f286573e9068eaf4910122b0813c6f267747f
1 #!/bin/sh
3 # This script calls the equivalent script in chutney/tools
5 # If we already know CHUTNEY_PATH, don't bother with argument parsing
6 TEST_NETWORK="$CHUTNEY_PATH/tools/test-network.sh"
7 # Call the chutney version of this script, if it exists, and we can find it
8 if [ -d "$CHUTNEY_PATH" -a -x "$TEST_NETWORK" ]; then
9 # we can't produce any output, because we might be --quiet
10 # this preserves arguments with spaces correctly
11 exec "$TEST_NETWORK" "$@"
14 # We need to go looking for CHUTNEY_PATH
16 # Do we output anything at all?
17 ECHO="${ECHO:-echo}"
18 # Output is prefixed with the name of the script
19 myname=$(basename $0)
21 # Save the arguments before we destroy them
22 # This might not preserve arguments with spaces in them
23 ORIGINAL_ARGS="$@"
25 # We need to find CHUTNEY_PATH, so that we can call the version of this script
26 # in chutney/tools with the same arguments. We also need to respect --quiet.
27 until [ -z "$1" ]
29 case "$1" in
30 --chutney-path)
31 CHUTNEY_PATH="$2"
32 shift
34 --tor-path)
35 TOR_DIR="$2"
36 shift
38 --quiet)
39 ECHO=true
42 # maybe chutney's test-network.sh can handle it
44 esac
45 shift
46 done
48 # optional: $TOR_DIR is the tor build directory
49 # it's used to find the location of tor binaries
50 # if it's not set:
51 # - set it to $BUILDDIR, or
52 # - if $PWD looks like a tor build directory, set it to $PWD, or
53 # - unset $TOR_DIR, and let chutney fall back to finding tor binaries in $PATH
54 if [ ! -d "$TOR_DIR" ]; then
55 if [ -d "$BUILDDIR/src/or" -a -d "$BUILDDIR/src/tools" ]; then
56 # Choose the build directory
57 # But only if it looks like one
58 $ECHO "$myname: \$TOR_DIR not set, trying \$BUILDDIR"
59 TOR_DIR="$BUILDDIR"
60 elif [ -d "$PWD/src/or" -a -d "$PWD/src/tools" ]; then
61 # Guess the tor directory is the current directory
62 # But only if it looks like one
63 $ECHO "$myname: \$TOR_DIR not set, trying \$PWD"
64 TOR_DIR="$PWD"
65 else
66 $ECHO "$myname: no \$TOR_DIR, chutney will use \$PATH for tor binaries"
67 unset TOR_DIR
71 # mandatory: $CHUTNEY_PATH is the path to the chutney launch script
72 # if it's not set:
73 # - if $PWD looks like a chutney directory, set it to $PWD, or
74 # - set it based on $TOR_DIR, expecting chutney to be next to tor, or
75 # - fail and tell the user how to clone the chutney repository
76 if [ ! -d "$CHUTNEY_PATH" -o ! -x "$CHUTNEY_PATH/chutney" ]; then
77 if [ -x "$PWD/chutney" ]; then
78 $ECHO "$myname: \$CHUTNEY_PATH not valid, trying \$PWD"
79 CHUTNEY_PATH="$PWD"
80 elif [ -d "$TOR_DIR" -a -d "$TOR_DIR/../chutney" -a \
81 -x "$TOR_DIR/../chutney/chutney" ]; then
82 $ECHO "$myname: \$CHUTNEY_PATH not valid, trying \$TOR_DIR/../chutney"
83 CHUTNEY_PATH="$TOR_DIR/../chutney"
84 else
85 $ECHO "$myname: missing 'chutney' in \$CHUTNEY_PATH ($CHUTNEY_PATH)"
86 $ECHO "$myname: Get chutney: git clone https://git.torproject.org/\
87 chutney.git"
88 $ECHO "$myname: Set \$CHUTNEY_PATH to a non-standard location: export \
89 CHUTNEY_PATH=\`pwd\`/chutney"
90 unset CHUTNEY_PATH
91 exit 1
95 TEST_NETWORK="$CHUTNEY_PATH/tools/test-network.sh"
96 # Call the chutney version of this script, if it exists, and we can find it
97 if [ -d "$CHUTNEY_PATH" -a -x "$TEST_NETWORK" ]; then
98 $ECHO "$myname: Calling newer chutney script $TEST_NETWORK"
99 # this may fail if some arguments have spaces in them
100 # if so, set CHUTNEY_PATH before calling test-network.sh, and spaces
101 # will be handled correctly
102 exec "$TEST_NETWORK" $ORIGINAL_ARGS
103 else
104 $ECHO "$myname: Could not find tools/test-network.sh in CHUTNEY_PATH."
105 $ECHO "$myname: Please update your chutney using 'git pull'."
106 # We have failed to do what the user asked
107 exit 1