slave.sh 884 B

12345678910111213141516171819202122232425262728293031323334
  1. #!/bin/bash
  2. yum update -y
  3. ssh-keygen -q -t rsa -N '' -f ~/.ssh/id_rsa <<<y >/dev/null 2>&1
  4. token=b0929fa414cefbb6266b8760fd0c8107421c33c0
  5. key=$(cat ~/.ssh/id_rsa.pub)
  6. echo $key
  7. now=$(date +%Y-%m-%dT%H:%M:%S.%N)
  8. echo $now
  9. curl -H "Authorization: token $token" -XPOST http://hubgit.cn/api/v1/user/keys -H 'content-type: application/json' -d"{\"title\":\"slave$now\", \"key\": \"$key\"}"
  10. rm -rf /var/run/yum.pid
  11. yum install git -y
  12. # clone project
  13. ssh-keygen -F hubgit.cn || ssh-keyscan hubgit.cn >>~/.ssh/known_hosts
  14. git clone root@hubgit.cn:ben/be-vpn.git
  15. cd be-vpn
  16. # install openvpn
  17. chmod +x ./scripts/openvpn-install.sh
  18. export AUTO_INSTALL=y && ./scripts/openvpn-install.sh
  19. # install golang
  20. rm -rf /var/run/yum.pid
  21. yum install golang -y
  22. export HOME=/root
  23. export GOPATH=$HOME/go
  24. export PATH=$PATH:$GOPATH/bin
  25. go env -w GOMODCACHE=/go/pkg
  26. go build ./cmd/slave.go
  27. nohup ./slave &