fix(script): follow redirected URL of github latest release

When checking version and desired version is not set, we follow
redirected URL of github latest release to get the latest tag instead of
trying to get the tag value from html content.

Closes #5480

Signed-off-by: Arief Hidayat <mr.arief.hidayat@gmail.com>
pull/5491/head
Arief Hidayat 6 years ago
parent c85f9ee8a3
commit 7cb03fb562

@ -78,16 +78,31 @@ verifySupported() {
# checkDesiredVersion checks if the desired version is available.
checkDesiredVersion() {
# Use the GitHub releases webpage for the project to find the desired version for this project.
local release_url="https://github.com/helm/helm/releases/${DESIRED_VERSION:-latest}"
local latest_release_url="https://github.com/helm/helm/releases/latest"
local release_url
if [ "x$DESIRED_VERSION" == "x" ]; then
if type "curl" > /dev/null; then
release_url=$(curl -Ls -o /dev/null -w %{url_effective} $latest_release_url)
elif type "wget" > /dev/null; then
release_url=$(wget $latest_release_url --server-response -O /dev/null 2>&1 | awk '/^ Location: /{DEST=$2} END{ print DEST}')
fi
else
release_url="https://github.com/helm/helm/releases/${DESIRED_VERSION}"
fi
local status_code
if type "curl" > /dev/null; then
TAG=$(curl -SsL $release_url | awk '/\/tag\//' | grep -v no-underline | grep "<a href=\"/helm/helm/releases" | head -n 1 | cut -d '"' -f 2 | awk '{n=split($NF,a,"/");print a[n]}' | awk 'a !~ $0{print}; {a=$0}')
status_code=$(curl --write-out %{http_code} --silent --output /dev/null $release_url)
elif type "wget" > /dev/null; then
TAG=$(wget -q -O - $release_url | awk '/\/tag\//' | grep -v no-underline | grep "<a href=\"/helm/helm/releases" | head -n 1 | cut -d '"' -f 2 | awk '{n=split($NF,a,"/");print a[n]}' | awk 'a !~ $0{print}; {a=$0}')
status_code=$(wget --spider -S $release_url -O /dev/null 2>&1 | grep "HTTP/" | awk '{print $2}')
fi
if [ "x$TAG" == "x" ]; then
if [[ "$status_code" -ne 200 ]] ; then
echo "Cannot determine ${DESIRED_VERSION} tag."
exit 1
fi
TAG=$(echo $release_url | grep -oE "[^/]+$" )
}
# checkHelmInstalledVersion checks which version of helm is installed and

Loading…
Cancel
Save