test-network.sh 3.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. echo "CHUTNEY_PATH = $CHUTNEY_PATH"
  24. echo "TOR_DIR = $TOR_DIR"
  25. echo "ECHO = $ECHO"
  26. # optional: $TOR_DIR is the tor build directory
  27. # it's used to find the location of tor binaries
  28. # if it's not set:
  29. # - set it to $BUILDDIR, or
  30. # - if $PWD looks like a tor build directory, set it to $PWD, or
  31. # - unset $TOR_DIR, and let chutney fall back to finding tor binaries in $PATH
  32. if [ ! -d "$TOR_DIR" ]; then
  33. if [ -d "$BUILDDIR/src/core/or" ] && [ -d "$BUILDDIR/src/tools" ]; then
  34. # Choose the build directory
  35. # But only if it looks like one
  36. $ECHO "$myname: \$TOR_DIR not set, trying \$BUILDDIR"
  37. TOR_DIR="$BUILDDIR"
  38. elif [ -d "$PWD/src/core/or" ] && [ -d "$PWD/src/tools" ]; then
  39. # Guess the tor directory is the current directory
  40. # But only if it looks like one
  41. $ECHO "$myname: \$TOR_DIR not set, trying \$PWD"
  42. TOR_DIR="$PWD"
  43. else
  44. $ECHO "$myname: no \$TOR_DIR, chutney will use \$PATH for tor binaries"
  45. unset TOR_DIR
  46. fi
  47. fi
  48. # mandatory: $CHUTNEY_PATH is the path to the chutney launch script
  49. # if it's not set:
  50. # - if $PWD looks like a chutney directory, set it to $PWD, or
  51. # - set it based on $TOR_DIR, expecting chutney to be next to tor, or
  52. # - fail and tell the user how to clone the chutney repository
  53. if [ ! -d "$CHUTNEY_PATH" ] || [ ! -x "$CHUTNEY_PATH/chutney" ]; then
  54. if [ -x "$PWD/chutney" ]; then
  55. $ECHO "$myname: \$CHUTNEY_PATH not valid, trying \$PWD"
  56. CHUTNEY_PATH="$PWD"
  57. elif [ -d "$TOR_DIR" ] && [ -d "$TOR_DIR/../chutney" ] && \
  58. [ -x "$TOR_DIR/../chutney/chutney" ]; then
  59. $ECHO "$myname: \$CHUTNEY_PATH not valid, trying \$TOR_DIR/../chutney"
  60. CHUTNEY_PATH="$TOR_DIR/../chutney"
  61. else
  62. $ECHO "$myname: missing 'chutney' in \$CHUTNEY_PATH ($CHUTNEY_PATH)"
  63. $ECHO "$myname: Get chutney: git clone https://git.torproject.org/\
  64. chutney.git"
  65. $ECHO "$myname: Set \$CHUTNEY_PATH to a non-standard location: export \
  66. CHUTNEY_PATH=\`pwd\`/chutney"
  67. unset CHUTNEY_PATH
  68. exit 1
  69. fi
  70. fi
  71. TEST_NETWORK="$CHUTNEY_PATH/tools/test-network.sh"
  72. # Call the chutney version of this script, if it exists, and we can find it
  73. if [ -d "$CHUTNEY_PATH" ] && [ -x "$TEST_NETWORK" ]; then
  74. $ECHO "$myname: Calling newer chutney script $TEST_NETWORK"
  75. # this may fail if some arguments have spaces in them
  76. # if so, set CHUTNEY_PATH before calling test-network.sh, and spaces
  77. # will be handled correctly
  78. exec "$TEST_NETWORK" "$@"
  79. else
  80. $ECHO "$myname: Could not find tools/test-network.sh in CHUTNEY_PATH."
  81. $ECHO "$myname: Please update your chutney using 'git pull'."
  82. # We have failed to do what the user asked
  83. exit 1
  84. fi