test-network.sh 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. #!/bin/sh
  2. # This script calls the equivalent script in chutney/tools
  3. # If we already know CHUTNEY_PATH, don't bother with argument parsing
  4. TEST_NETWORK="$CHUTNEY_PATH/tools/test-network.sh"
  5. # Call the chutney version of this script, if it exists, and we can find it
  6. if [ -d "$CHUTNEY_PATH" ] && [ -x "$TEST_NETWORK" ]; then
  7. # we can't produce any output, because we might be --quiet
  8. # this preserves arguments with spaces correctly
  9. exec "$TEST_NETWORK" "$@"
  10. fi
  11. # We need to go looking for CHUTNEY_PATH
  12. # Do we output anything at all?
  13. ECHO="${ECHO:-echo}"
  14. # Output is prefixed with the name of the script
  15. myname=$(basename "$0")
  16. # We need to find CHUTNEY_PATH, so that we can call the version of this script
  17. # in chutney/tools with the same arguments. We also need to respect --quiet.
  18. CHUTNEY_PATH=$(echo "$@" | awk -F '--chutney-path ' '{sub(" .*","",$2); print $2}')
  19. TOR_DIR=$(echo "$@" | awk -F '--tor-dir ' '{sub(" .*","",$2); print $2}')
  20. if echo "$@" | grep -e "--quiet" > /dev/null; then
  21. ECHO=true
  22. fi
  23. # optional: $TOR_DIR is the tor build directory
  24. # it's used to find the location of tor binaries
  25. # if it's not set:
  26. # - set it to $BUILDDIR, or
  27. # - if $PWD looks like a tor build directory, set it to $PWD, or
  28. # - unset $TOR_DIR, and let chutney fall back to finding tor binaries in $PATH
  29. if [ ! -d "$TOR_DIR" ]; then
  30. if [ -d "$BUILDDIR/src/core/or" ] && [ -d "$BUILDDIR/src/tools" ]; then
  31. # Choose the build directory
  32. # But only if it looks like one
  33. $ECHO "$myname: \$TOR_DIR not set, trying \$BUILDDIR"
  34. TOR_DIR="$BUILDDIR"
  35. elif [ -d "$PWD/src/core/or" ] && [ -d "$PWD/src/tools" ]; then
  36. # Guess the tor directory is the current directory
  37. # But only if it looks like one
  38. $ECHO "$myname: \$TOR_DIR not set, trying \$PWD"
  39. TOR_DIR="$PWD"
  40. else
  41. $ECHO "$myname: no \$TOR_DIR, chutney will use \$PATH for tor binaries"
  42. unset TOR_DIR
  43. fi
  44. fi
  45. # mandatory: $CHUTNEY_PATH is the path to the chutney launch script
  46. # if it's not set:
  47. # - if $PWD looks like a chutney directory, set it to $PWD, or
  48. # - set it based on $TOR_DIR, expecting chutney to be next to tor, or
  49. # - fail and tell the user how to clone the chutney repository
  50. if [ ! -d "$CHUTNEY_PATH" ] || [ ! -x "$CHUTNEY_PATH/chutney" ]; then
  51. if [ -x "$PWD/chutney" ]; then
  52. $ECHO "$myname: \$CHUTNEY_PATH not valid, trying \$PWD"
  53. CHUTNEY_PATH="$PWD"
  54. elif [ -d "$TOR_DIR" ] && [ -d "$TOR_DIR/../chutney" ] && \
  55. [ -x "$TOR_DIR/../chutney/chutney" ]; then
  56. $ECHO "$myname: \$CHUTNEY_PATH not valid, trying \$TOR_DIR/../chutney"
  57. CHUTNEY_PATH="$TOR_DIR/../chutney"
  58. else
  59. $ECHO "$myname: missing 'chutney' in \$CHUTNEY_PATH ($CHUTNEY_PATH)"
  60. $ECHO "$myname: Get chutney: git clone https://git.torproject.org/\
  61. chutney.git"
  62. $ECHO "$myname: Set \$CHUTNEY_PATH to a non-standard location: export \
  63. CHUTNEY_PATH=\`pwd\`/chutney"
  64. unset CHUTNEY_PATH
  65. exit 1
  66. fi
  67. fi
  68. TEST_NETWORK="$CHUTNEY_PATH/tools/test-network.sh"
  69. # Call the chutney version of this script, if it exists, and we can find it
  70. if [ -d "$CHUTNEY_PATH" ] && [ -x "$TEST_NETWORK" ]; then
  71. $ECHO "$myname: Calling newer chutney script $TEST_NETWORK"
  72. # this may fail if some arguments have spaces in them
  73. # if so, set CHUTNEY_PATH before calling test-network.sh, and spaces
  74. # will be handled correctly
  75. exec "$TEST_NETWORK" "$@"
  76. else
  77. $ECHO "$myname: Could not find tools/test-network.sh in CHUTNEY_PATH."
  78. $ECHO "$myname: Please update your chutney using 'git pull'."
  79. # We have failed to do what the user asked
  80. exit 1
  81. fi