create-config.sh 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. #!/usr/bin/env bash
  2. set -euo pipefail
  3. if [ -z "${NUM_GUARDIANS}" ]; then
  4. echo "Error: NUM_GUARDIANS is unset, cannot create wormchain config."
  5. exit 1
  6. fi
  7. # Get the hostname
  8. hostname=$(hostname)
  9. # # for local development/debugging, set the hostname as it would be in a devnet container
  10. # if [ ! -z "${INST}" ]; then
  11. # hostname="wormchain-$INST"
  12. # echo "set hostname with INST value: $hostname"
  13. # fi
  14. # Check if the hostname starts with "wormchain-"
  15. if [[ ! $hostname =~ ^wormchain- ]]; then
  16. # If the hostname does not start with "wormchain-", print an error message and exit
  17. echo "Error: hostname does not start with 'wormchain-'"
  18. exit 1
  19. fi
  20. # Split the hostname on "-"
  21. instance=$(echo $hostname | cut -d'-' -f2)
  22. # get the context of this script call, so it can be prepended to file paths,
  23. # so this script will work in the tilt docker container, and when run locally.
  24. pwd=$(pwd)
  25. # config dir path for the instance, which is passed to wormchaind via --home
  26. home_path="$pwd/devnet/$hostname"
  27. # copy config from devnet/base
  28. cp -r $pwd/devnet/base/* ${home_path}/
  29. # update the moniker
  30. sed -i "s/moniker = \"wormchain\"/moniker = \"$hostname\"/g" ${home_path}/config/config.toml
  31. # set the external address so wormchain peers can resolve each other
  32. sed -i "s/external_address = \"\"/external_address = \"${hostname}:26656\"/g" ${home_path}/config/config.toml
  33. if [ $instance -eq 0 ] && [ $NUM_GUARDIANS -ge 2 ]; then
  34. echo "$hostname: enabling seed mode in config.toml."
  35. sed -i "s/pex = false/pex = true/g" ${home_path}/config/config.toml
  36. sed -i "s/seed_mode = false/seed_mode = true/g" ${home_path}/config/config.toml
  37. elif [ $instance -ge 1 ]; then
  38. echo "$hostname: adding seed address to config.toml."
  39. sed -i "s/seeds = \"\"/seeds = \"90ea40bee73abfda5226a0e8ddb18b0e324d2a29@wormchain-0:26656\"/g" ${home_path}/config/config.toml
  40. sed -i "s/persistent_peers = \"\"/persistent_peers = \"90ea40bee73abfda5226a0e8ddb18b0e324d2a29@wormchain-0:26656\"/g" ${home_path}/config/config.toml
  41. fi
  42. # copy the config to tendermint's default location, ~/.{chain-id}
  43. mkdir -p /root/.wormchain && cp -r ${home_path}/* /root/.wormchain/
  44. echo "$hostname: done with create-config.sh, exiting success."