bootstrap-network.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/bin/sh
  2. #
  3. # 1. potentially stop running network
  4. # 2. bootstrap a network from scratch as quickly as possible
  5. # 3. tail -F all the tor log files
  6. #
  7. # NOTE: leaves debris around by renaming directory net/nodes
  8. # and creating a new net/nodes
  9. #
  10. # Usage:
  11. # tools/bootstrap-network.sh [network-flavour]
  12. # network-flavour: one of the files in the networks directory,
  13. # (default: 'basic')
  14. #
  15. # Get a working chutney path
  16. if [ ! -d "$CHUTNEY_PATH" -o ! -x "$CHUTNEY_PATH/chutney" ]; then
  17. # looks like a broken path: use the path to this tool instead
  18. TOOLS_PATH=`dirname "$0"`
  19. export CHUTNEY_PATH=`dirname "$TOOLS_PATH"`
  20. fi
  21. if [ -d "$PWD/$CHUTNEY_PATH" -a -x "$PWD/$CHUTNEY_PATH/chutney" ]; then
  22. # looks like a relative path: make chutney path absolute
  23. export CHUTNEY_PATH="$PWD/$CHUTNEY_PATH"
  24. fi
  25. # Get a working net path
  26. if [ ! -d "$CHUTNEY_DATA_DIR" ]; then
  27. # looks like a broken path: use the chutney path as a base
  28. export CHUTNEY_DATA_DIR="$CHUTNEY_PATH/net"
  29. fi
  30. if [ -d "$PWD/$CHUTNEY_DATA_DIR" ]; then
  31. # looks like a relative path: make chutney path absolute
  32. export CHUTNEY_DATA_DIR="$PWD/$CHUTNEY_DATA_DIR"
  33. fi
  34. VOTING_OFFSET=6
  35. CHUTNEY="$CHUTNEY_PATH/chutney"
  36. myname=$(basename "$0")
  37. [ -d "$CHUTNEY_PATH" ] || \
  38. { echo "$myname: missing chutney directory: $CHUTNEY_PATH"; exit 1; }
  39. [ -x "$CHUTNEY" ] || \
  40. { echo "$myname: missing chutney: $CHUTNEY"; exit 1; }
  41. flavour=basic; [ -n "$1" ] && { flavour=$1; shift; }
  42. export CHUTNEY_NETWORK="$CHUTNEY_PATH/networks/$NETWORK_FLAVOUR"
  43. [ -e "$CHUTNEY_NETWORK" ] || \
  44. { echo "$myname: missing network file: $CHUTNEY_NETWORK"; exit 1; }
  45. "$CHUTNEY" stop "$CHUTNEY_NETWORK"
  46. echo "$myname: bootstrapping network: $flavour"
  47. "$CHUTNEY" configure "$CHUTNEY_NETWORK"
  48. # TODO: Make 'chutney configure' take an optional offset argument and
  49. # use the templating system in Chutney to set this instead of editing
  50. # files like this.
  51. offset=$(expr \( $(date +%s) + $VOTING_OFFSET \) % 300)
  52. CONFOPT="TestingV3AuthVotingStartOffset"
  53. for file in "$CHUTNEY_DATA_DIR"/nodes/*a/torrc ; do
  54. sed -i.bak -e "s/^${CONFOPT}.*$/${CONFOPT} $offset/1" $file
  55. done
  56. "$CHUTNEY" start "$CHUTNEY_NETWORK"
  57. sleep 1
  58. "$CHUTNEY" status "$CHUTNEY_NETWORK"
  59. #echo "tail -F net/nodes/*/notice.log"