@ -78,16 +78,31 @@ verifySupported() {
# checkDesiredVersion checks if the desired version is available.
# checkDesiredVersion checks if the desired version is available.
checkDesiredVersion() {
checkDesiredVersion() {
# Use the GitHub releases webpage for the project to find the desired version for this project.
# 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
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
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
fi
if [ "x$TAG" == "x" ]; then
if [[ "$status_code" -ne 200 ]] ; then
echo "Cannot determine ${DESIRED_VERSION} tag."
echo "Cannot determine ${DESIRED_VERSION} tag."
exit 1
exit 1
fi
fi
TAG=$(echo $release_url | grep -oE "[^/]+$" )
}
}
# checkHelmInstalledVersion checks which version of helm is installed and
# checkHelmInstalledVersion checks which version of helm is installed and