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.

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