install_gh.sh 759 B

1234567891011121314151617181920212223242526272829303132
  1. #!/usr/bin/env bash
  2. set -ex
  3. GH_ARCH="amd64"
  4. for i in {1..5}; do
  5. TAG=$( curl --retry 12 --retry-delay 30 "https://api.github.com/repos/cli/cli/releases/latest" 2>/dev/null | jq --raw-output '.tag_name' )
  6. if [[ $? == 0 && "${TAG}" != "null" ]]; then
  7. break
  8. fi
  9. if [[ $i == 5 ]]; then
  10. echo "GH install failed too many times" >&2
  11. exit 1
  12. fi
  13. echo "GH install failed $i, trying again..."
  14. sleep $(( 15 * (i + 1)))
  15. done
  16. VERSION="${TAG#v}"
  17. curl --retry 12 --retry-delay 120 -sSL "https://github.com/cli/cli/releases/download/${TAG}/gh_${VERSION}_linux_${GH_ARCH}.tar.gz" -o "gh_${VERSION}_linux_${GH_ARCH}.tar.gz"
  18. tar xf "gh_${VERSION}_linux_${GH_ARCH}.tar.gz"
  19. cp "gh_${VERSION}_linux_${GH_ARCH}/bin/gh" /usr/local/bin/
  20. gh --version