helm 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. #!/usr/bin/env bash
  2. # installs $(cat ./helm.rev) version of helm as $HOME/.cache/tailscale-helm
  3. set -euo pipefail
  4. if [[ "${CI:-}" == "true" ]]; then
  5. set -x
  6. fi
  7. (
  8. if [[ "${CI:-}" == "true" ]]; then
  9. set -x
  10. fi
  11. repo_root="${BASH_SOURCE%/*}/../"
  12. cd "$repo_root"
  13. cachedir="$HOME/.cache/tailscale-helm"
  14. tarball="${cachedir}.tar.gz"
  15. read -r want_rev < "$(dirname "$0")/helm.rev"
  16. got_rev=""
  17. if [[ -x "${cachedir}/helm" ]]; then
  18. got_rev=$("${cachedir}/helm" version --short)
  19. got_rev="${got_rev#v}" # trim the leading 'v'
  20. got_rev="${got_rev%+*}" # trim the trailing '+" followed by a commit SHA'
  21. fi
  22. if [[ "$want_rev" != "$got_rev" ]]; then
  23. rm -rf "$cachedir" "$tarball"
  24. if [[ -n "${IN_NIX_SHELL:-}" ]]; then
  25. nix_helm="$(which -a helm | grep /nix/store | head -1)"
  26. nix_helm="${nix_helm%/helm}"
  27. nix_helm_rev="${nix_helm##*-}"
  28. if [[ "$nix_helm_rev" != "$want_rev" ]]; then
  29. echo "Wrong helm version in Nix, got $nix_helm_rev want $want_rev" >&2
  30. exit 1
  31. fi
  32. ln -sf "$nix_helm" "$cachedir"
  33. else
  34. # works for linux and darwin
  35. # https://github.com/helm/helm/releases
  36. OS=$(uname -s | tr A-Z a-z)
  37. ARCH=$(uname -m)
  38. if [ "$ARCH" = "x86_64" ]; then
  39. ARCH="amd64"
  40. fi
  41. if [ "$ARCH" = "aarch64" ]; then
  42. ARCH="arm64"
  43. fi
  44. mkdir -p "$cachedir"
  45. # When running on GitHub in CI, the below curl sometimes fails with
  46. # INTERNAL_ERROR after finishing the download. The most common cause
  47. # of INTERNAL_ERROR is glitches in intermediate hosts handling of
  48. # HTTP/2 forwarding, so forcing HTTP 1.1 often fixes the issue. See
  49. # https://github.com/tailscale/tailscale/issues/8988
  50. curl -f -L --http1.1 -o "$tarball" -sSL "https://get.helm.sh/helm-v${want_rev}-${OS}-${ARCH}.tar.gz"
  51. (cd "$cachedir" && tar --strip-components=1 -xf "$tarball")
  52. rm -f "$tarball"
  53. fi
  54. fi
  55. )
  56. export PATH="$HOME/.cache/tailscale-helm:$PATH"
  57. exec "$HOME/.cache/tailscale-helm/helm" "$@"