You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

141 lines
4.3 KiB

  1. #!/usr/bin/env bash
  2. # XXX: this script is intended to be run from a fresh Digital Ocean droplet
  3. # NOTE: you must set this manually now
  4. echo "export DO_API_TOKEN=\"yourtoken\"" >> ~/.profile
  5. sudo apt-get update -y
  6. sudo apt-get upgrade -y
  7. sudo apt-get install -y jq unzip python-pip software-properties-common make
  8. # get and unpack golang
  9. curl -O https://dl.google.com/go/go1.16.5.linux-amd64.tar.gz
  10. tar -xvf go1.16.5.linux-amd64.tar.gz
  11. ## move binary and add to path
  12. mv go /usr/local
  13. echo "export PATH=\$PATH:/usr/local/go/bin" >> ~/.profile
  14. ## create the goApps directory, set GOPATH, and put it on PATH
  15. mkdir goApps
  16. echo "export GOPATH=/root/goApps" >> ~/.profile
  17. echo "export PATH=\$PATH:\$GOPATH/bin" >> ~/.profile
  18. # **turn on the go module, default is auto. The value is off, if tendermint source code
  19. #is downloaded under $GOPATH/src directory
  20. echo "export GO111MODULE=on" >> ~/.profile
  21. source ~/.profile
  22. mkdir -p $GOPATH/src/github.com/tendermint
  23. cd $GOPATH/src/github.com/tendermint
  24. # ** use git clone instead of go get.
  25. # once go module is on, go get will download source code to
  26. # specific version directory under $GOPATH/pkg/mod the make
  27. # script will not work
  28. git clone https://github.com/tendermint/tendermint.git
  29. cd tendermint
  30. ## build
  31. make tools
  32. make build
  33. #** need to install the package, otherwise terdermint testnet will not execute
  34. make install
  35. # generate an ssh key
  36. ssh-keygen -f $HOME/.ssh/id_rsa -t rsa -N ''
  37. echo "export SSH_KEY_FILE=\"\$HOME/.ssh/id_rsa.pub\"" >> ~/.profile
  38. source ~/.profile
  39. # install terraform
  40. wget https://releases.hashicorp.com/terraform/0.11.7/terraform_0.11.7_linux_amd64.zip
  41. unzip terraform_0.11.7_linux_amd64.zip -d /usr/bin/
  42. # install ansible
  43. sudo apt-get update -y
  44. sudo apt-add-repository ppa:ansible/ansible -y
  45. sudo apt-get update -y
  46. sudo apt-get install ansible -y
  47. # required by ansible
  48. pip install dopy
  49. # the next two commands are directory sensitive
  50. cd $GOPATH/src/github.com/tendermint/tendermint/networks/remote/terraform
  51. terraform init
  52. terraform apply -var DO_API_TOKEN="$DO_API_TOKEN" -var SSH_KEY_FILE="$SSH_KEY_FILE" -auto-approve
  53. # let the droplets boot
  54. sleep 60
  55. # get the IPs
  56. ip0=`terraform output -json public_ips | jq '.value[0]'`
  57. ip1=`terraform output -json public_ips | jq '.value[1]'`
  58. ip2=`terraform output -json public_ips | jq '.value[2]'`
  59. ip3=`terraform output -json public_ips | jq '.value[3]'`
  60. # to remove quotes
  61. strip() {
  62. opt=$1
  63. temp="${opt%\"}"
  64. temp="${temp#\"}"
  65. echo $temp
  66. }
  67. ip0=$(strip $ip0)
  68. ip1=$(strip $ip1)
  69. ip2=$(strip $ip2)
  70. ip3=$(strip $ip3)
  71. # all the ansible commands are also directory specific
  72. cd $GOPATH/src/github.com/tendermint/tendermint/networks/remote/ansible
  73. # create config dirs
  74. tendermint testnet
  75. ansible-playbook -i inventory/digital_ocean.py -l sentrynet install.yml
  76. ansible-playbook -i inventory/digital_ocean.py -l sentrynet config.yml -e BINARY=$GOPATH/src/github.com/tendermint/tendermint/build/tendermint -e CONFIGDIR=$GOPATH/src/github.com/tendermint/tendermint/networks/remote/ansible/mytestnet
  77. sleep 10
  78. # get each nodes ID then populate the ansible file
  79. id0=`curl $ip0:26657/status | jq .result.node_info.id`
  80. id1=`curl $ip1:26657/status | jq .result.node_info.id`
  81. id2=`curl $ip2:26657/status | jq .result.node_info.id`
  82. id3=`curl $ip3:26657/status | jq .result.node_info.id`
  83. id0=$(strip $id0)
  84. id1=$(strip $id1)
  85. id2=$(strip $id2)
  86. id3=$(strip $id3)
  87. # remove file we'll re-write to with new info
  88. old_ansible_file=$GOPATH/src/github.com/tendermint/tendermint/networks/remote/ansible/roles/install/templates/systemd.service.j2
  89. rm $old_ansible_file
  90. # need to populate the `--p2p.persistent-peers` flag
  91. echo "[Unit]
  92. Description={{service}}
  93. Requires=network-online.target
  94. After=network-online.target
  95. [Service]
  96. Restart=on-failure
  97. User={{service}}
  98. Group={{service}}
  99. PermissionsStartOnly=true
  100. ExecStart=/usr/bin/tendermint node --mode validator --proxy-app=kvstore --p2p.persistent-peers=$id0@$ip0:26656,$id1@$ip1:26656,$id2@$ip2:26656,$id3@$ip3:26656
  101. ExecReload=/bin/kill -HUP \$MAINPID
  102. KillSignal=SIGTERM
  103. [Install]
  104. WantedBy=multi-user.target
  105. " >> $old_ansible_file
  106. # now, we can re-run the install command
  107. ansible-playbook -i inventory/digital_ocean.py -l sentrynet install.yml
  108. # and finally restart it all
  109. ansible-playbook -i inventory/digital_ocean.py -l sentrynet restart.yml
  110. echo "congratulations, your testnet is now running :)"