install_gh.sh 644 B

12345678910111213141516171819202122
  1. #!/usr/bin/env bash
  2. set -ex
  3. GH_ARCH="amd64"
  4. TAG=$( curl --retry 12 --retry-delay 30 "https://api.github.com/repos/cli/cli/releases/latest" 2>/dev/null | jq --raw-output '.tag_name' )
  5. if [[ $? -ne 0 ]] || [[ "${TAG}" == "null" ]]; then
  6. echo "Error: Failed to retrieve the latest tag from GitHub CLI releases."
  7. exit 1
  8. fi
  9. VERSION="${TAG#v}"
  10. 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"
  11. tar xf "gh_${VERSION}_linux_${GH_ARCH}.tar.gz"
  12. cp "gh_${VERSION}_linux_${GH_ARCH}/bin/gh" /usr/local/bin/
  13. gh --version