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.

133 lines
3.8 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://storage.googleapis.com/golang/go1.12.linux-amd64.tar.gz
  10. tar -xvf go1.12.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. source ~/.profile
  19. ## get the code and move into repo
  20. REPO=github.com/tendermint/tendermint
  21. go get $REPO
  22. cd $GOPATH/src/$REPO
  23. ## build
  24. make get_tools
  25. make build
  26. # generate an ssh key
  27. ssh-keygen -f $HOME/.ssh/id_rsa -t rsa -N ''
  28. echo "export SSH_KEY_FILE=\"\$HOME/.ssh/id_rsa.pub\"" >> ~/.profile
  29. source ~/.profile
  30. # install terraform
  31. wget https://releases.hashicorp.com/terraform/0.11.7/terraform_0.11.7_linux_amd64.zip
  32. unzip terraform_0.11.7_linux_amd64.zip -d /usr/bin/
  33. # install ansible
  34. sudo apt-get update -y
  35. sudo apt-add-repository ppa:ansible/ansible -y
  36. sudo apt-get update -y
  37. sudo apt-get install ansible -y
  38. # required by ansible
  39. pip install dopy
  40. # the next two commands are directory sensitive
  41. cd $GOPATH/src/github.com/tendermint/tendermint/networks/remote/terraform
  42. terraform init
  43. terraform apply -var DO_API_TOKEN="$DO_API_TOKEN" -var SSH_KEY_FILE="$SSH_KEY_FILE" -auto-approve
  44. # let the droplets boot
  45. sleep 60
  46. # get the IPs
  47. ip0=`terraform output -json public_ips | jq '.value[0]'`
  48. ip1=`terraform output -json public_ips | jq '.value[1]'`
  49. ip2=`terraform output -json public_ips | jq '.value[2]'`
  50. ip3=`terraform output -json public_ips | jq '.value[3]'`
  51. # to remove quotes
  52. strip() {
  53. opt=$1
  54. temp="${opt%\"}"
  55. temp="${temp#\"}"
  56. echo $temp
  57. }
  58. ip0=$(strip $ip0)
  59. ip1=$(strip $ip1)
  60. ip2=$(strip $ip2)
  61. ip3=$(strip $ip3)
  62. # all the ansible commands are also directory specific
  63. cd $GOPATH/src/github.com/tendermint/tendermint/networks/remote/ansible
  64. # create config dirs
  65. tendermint testnet
  66. ansible-playbook -i inventory/digital_ocean.py -l sentrynet install.yml
  67. 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
  68. sleep 10
  69. # get each nodes ID then populate the ansible file
  70. id0=`curl $ip0:26657/status | jq .result.node_info.id`
  71. id1=`curl $ip1:26657/status | jq .result.node_info.id`
  72. id2=`curl $ip2:26657/status | jq .result.node_info.id`
  73. id3=`curl $ip3:26657/status | jq .result.node_info.id`
  74. id0=$(strip $id0)
  75. id1=$(strip $id1)
  76. id2=$(strip $id2)
  77. id3=$(strip $id3)
  78. # remove file we'll re-write to with new info
  79. old_ansible_file=$GOPATH/src/github.com/tendermint/tendermint/networks/remote/ansible/roles/install/templates/systemd.service.j2
  80. rm $old_ansible_file
  81. # need to populate the `--p2p.persistent_peers` flag
  82. echo "[Unit]
  83. Description={{service}}
  84. Requires=network-online.target
  85. After=network-online.target
  86. [Service]
  87. Restart=on-failure
  88. User={{service}}
  89. Group={{service}}
  90. PermissionsStartOnly=true
  91. ExecStart=/usr/bin/tendermint node --proxy_app=kvstore --p2p.persistent_peers=$id0@$ip0:26656,$id1@$ip1:26656,$id2@$ip2:26656,$id3@$ip3:26656
  92. ExecReload=/bin/kill -HUP \$MAINPID
  93. KillSignal=SIGTERM
  94. [Install]
  95. WantedBy=multi-user.target
  96. " >> $old_ansible_file
  97. # now, we can re-run the install command
  98. ansible-playbook -i inventory/digital_ocean.py -l sentrynet install.yml
  99. # and finally restart it all
  100. ansible-playbook -i inventory/digital_ocean.py -l sentrynet restart.yml
  101. echo "congratulations, your testnet is now running :)"