test-network.sh 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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" -a -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. # Save the arguments before we destroy them
  17. # This might not preserve arguments with spaces in them
  18. ORIGINAL_ARGS="$@"
  19. # We need to find CHUTNEY_PATH, so that we can call the version of this script
  20. # in chutney/tools with the same arguments. We also need to respect --quiet.
  21. until [ -z "$1" ]
  22. do
  23. case "$1" in
  24. --chutney-path)
  25. CHUTNEY_PATH="$2"
  26. shift
  27. ;;
  28. --tor-path)
  29. TOR_DIR="$2"
  30. shift
  31. ;;
  32. --quiet)
  33. ECHO=true
  34. ;;
  35. *)
  36. # maybe chutney's test-network.sh can handle it
  37. ;;
  38. esac
  39. shift
  40. done
  41. # optional: $TOR_DIR is the tor build directory
  42. # it's used to find the location of tor binaries
  43. # if it's not set:
  44. # - set it to $BUILDDIR, or
  45. # - if $PWD looks like a tor build directory, set it to $PWD, or
  46. # - unset $TOR_DIR, and let chutney fall back to finding tor binaries in $PATH
  47. if [ ! -d "$TOR_DIR" ]; then
  48. if [ -d "$BUILDDIR/src/or" -a -d "$BUILDDIR/src/tools" ]; then
  49. # Choose the build directory
  50. # But only if it looks like one
  51. $ECHO "$myname: \$TOR_DIR not set, trying \$BUILDDIR"
  52. TOR_DIR="$BUILDDIR"
  53. elif [ -d "$PWD/src/or" -a -d "$PWD/src/tools" ]; then
  54. # Guess the tor directory is the current directory
  55. # But only if it looks like one
  56. $ECHO "$myname: \$TOR_DIR not set, trying \$PWD"
  57. TOR_DIR="$PWD"
  58. else
  59. $ECHO "$myname: no \$TOR_DIR, chutney will use \$PATH for tor binaries"
  60. unset TOR_DIR
  61. fi
  62. fi
  63. # mandatory: $CHUTNEY_PATH is the path to the chutney launch script
  64. # if it's not set:
  65. # - if $PWD looks like a chutney directory, set it to $PWD, or
  66. # - set it based on $TOR_DIR, expecting chutney to be next to tor, or
  67. # - fail and tell the user how to clone the chutney repository
  68. if [ ! -d "$CHUTNEY_PATH" -o ! -x "$CHUTNEY_PATH/chutney" ]; then
  69. if [ -x "$PWD/chutney" ]; then
  70. $ECHO "$myname: \$CHUTNEY_PATH not valid, trying \$PWD"
  71. CHUTNEY_PATH="$PWD"
  72. elif [ -d "$TOR_DIR" -a -d "$TOR_DIR/../chutney" -a \
  73. -x "$TOR_DIR/../chutney/chutney" ]; then
  74. $ECHO "$myname: \$CHUTNEY_PATH not valid, trying \$TOR_DIR/../chutney"
  75. CHUTNEY_PATH="$TOR_DIR/../chutney"
  76. else
  77. $ECHO "$myname: missing 'chutney' in \$CHUTNEY_PATH ($CHUTNEY_PATH)"
  78. $ECHO "$myname: Get chutney: git clone https://git.torproject.org/\
  79. chutney.git"
  80. $ECHO "$myname: Set \$CHUTNEY_PATH to a non-standard location: export \
  81. CHUTNEY_PATH=\`pwd\`/chutney"
  82. unset CHUTNEY_PATH
  83. exit 1
  84. fi
  85. fi
  86. TEST_NETWORK="$CHUTNEY_PATH/tools/test-network.sh"
  87. # Call the chutney version of this script, if it exists, and we can find it
  88. if [ -d "$CHUTNEY_PATH" -a -x "$TEST_NETWORK" ]; then
  89. $ECHO "$myname: Calling newer chutney script $TEST_NETWORK"
  90. # this may fail if some arguments have spaces in them
  91. # if so, set CHUTNEY_PATH before calling test-network.sh, and spaces
  92. # will be handled correctly
  93. exec "$TEST_NETWORK" $ORIGINAL_ARGS
  94. else
  95. $ECHO "$myname: Could not find tools/test-network.sh in CHUTNEY_PATH."
  96. $ECHO "$myname: Please update your chutney using 'git pull'."
  97. # We have failed to do what the user asked
  98. exit 1
  99. fi