Skip to content

Commit

Permalink
Upgrade kustomize install script
Browse files Browse the repository at this point in the history
  • Loading branch information
sbidoul committed Jul 19, 2023
1 parent ac1c8db commit b26b992
Showing 1 changed file with 32 additions and 11 deletions.
43 changes: 32 additions & 11 deletions install/get-kustomize
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,18 @@ function readlink_f {
echo "$RESULT"
}

where="$(readlink_f $where)/"
function find_release_url() {
local releases=$1
local opsys=$2
local arch=$3

echo "${releases}" |\
grep "browser_download.*${opsys}_${arch}" |\
cut -d '"' -f 4 |\
sort -V | tail -n 1
}

where="$(readlink_f "$where")/"

if [ -f "${where}kustomize" ]; then
echo "${where}kustomize exists. Remove it first."
Expand All @@ -83,7 +94,7 @@ elif [ -d "${where}kustomize" ]; then
exit 1
fi

tmpDir=`mktemp -d`
tmpDir=$(mktemp -d)
if [[ ! "$tmpDir" || ! -d "$tmpDir" ]]; then
echo "Could not create temp dir."
exit 1
Expand All @@ -109,7 +120,7 @@ case $(uname -m) in
x86_64)
arch=amd64
;;
arm64)
arm64|aarch64)
arch=arm64
;;
ppc64le)
Expand All @@ -123,31 +134,41 @@ s390x)
;;
esac

releases=$(curl -s $release_url)
# You can authenticate by exporting the GITHUB_TOKEN in the environment
if [[ -z "${GITHUB_TOKEN}" ]]; then
releases=$(curl -s "$release_url")
else
releases=$(curl -s "$release_url" --header "Authorization: Bearer ${GITHUB_TOKEN}")
fi

if [[ $releases == *"API rate limit exceeded"* ]]; then
echo "Github rate-limiter failed the request. Either authenticate or wait a couple of minutes."
exit 1
fi

RELEASE_URL=$(echo "${releases}" |\
grep browser_download.*${opsys}_${arch} |\
cut -d '"' -f 4 |\
sort -V | tail -n 1)
RELEASE_URL="$(find_release_url "$releases" "$opsys" "$arch")"

if [[ "$arch" == "arm64" ]] && [[ -z "$RELEASE_URL" ]] ; then
# fallback to the old behavior of downloading amd64 binaries on aarch64 systems.
# People might have qemu-binfmt-misc installed, so it worked for them previously.
echo "Version $version does not exist for ${opsys}/arm64, trying ${opsys}/amd64 instead."
arch=amd64
RELEASE_URL="$(find_release_url "$releases" "$opsys" "amd64")"
fi

if [ ! -n "$RELEASE_URL" ]; then
if [[ -z "$RELEASE_URL" ]]; then
echo "Version $version does not exist or is not available for ${opsys}/${arch}."
exit 1
fi

curl -sLO $RELEASE_URL
curl -sLO "$RELEASE_URL"

tar xzf ./kustomize_v*_${opsys}_${arch}.tar.gz

cp ./kustomize "$where"

popd >& /dev/null

${where}kustomize version
"${where}kustomize" version

echo "kustomize installed to ${where}kustomize"

0 comments on commit b26b992

Please sign in to comment.