From 73898114ca74c2ed548257f5c71136bc993cd3ed Mon Sep 17 00:00:00 2001 From: Andrew Basson Date: Wed, 22 Sep 2021 00:22:48 +0200 Subject: [PATCH] fix(upgrade): fix upgrade logic in install script --- install-binary.sh | 34 ++++++++++++++++++++++++---------- plugin.yaml | 2 +- 2 files changed, 25 insertions(+), 11 deletions(-) diff --git a/install-binary.sh b/install-binary.sh index 7fb33382..1d58a8ef 100755 --- a/install-binary.sh +++ b/install-binary.sh @@ -24,6 +24,12 @@ if [ "$SKIP_BIN_INSTALL" = "1" ]; then exit fi +# which mode is the common installer script running in +SCRIPT_MODE="install" +if [ "$1" = "-u" ]; then + SCRIPT_MODE="update" +fi + # initArch discovers the architecture for this system. initArch() { ARCH=$(uname -m) @@ -67,19 +73,27 @@ verifySupported() { fi } +getLatestDownloadURL(){ + # Use the GitHub API to find the download url for this project. + url="https://api.github.com/repos/$PROJECT_GH/releases/latest" + if type "curl" >/dev/null; then + DOWNLOAD_URL=$(curl -s $url | grep $OS | awk '/\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}') + elif type "wget" >/dev/null; then + DOWNLOAD_URL=$(wget -q -O - $url | grep $OS | awk '/\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}') + fi +} + # getDownloadURL checks the latest available version. getDownloadURL() { - version=$(git -C "$HELM_PLUGIN_DIR" describe --tags --exact-match 2>/dev/null || :) - if [ -n "$version" ]; then - DOWNLOAD_URL="https://github.com/$PROJECT_GH/releases/download/$version/helm-diff-$OS.tgz" - else - # Use the GitHub API to find the download url for this project. - url="https://api.github.com/repos/$PROJECT_GH/releases/latest" - if type "curl" >/dev/null; then - DOWNLOAD_URL=$(curl -s $url | grep $OS | awk '/\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}') - elif type "wget" >/dev/null; then - DOWNLOAD_URL=$(wget -q -O - $url | grep $OS | awk '/\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}') + if [ "$SCRIPT_MODE" = "install" ]; then + version=$(git -C "$HELM_PLUGIN_DIR" describe --tags --exact-match 2>/dev/null || :) + if [ -n "$version" ]; then + DOWNLOAD_URL="https://github.com/$PROJECT_GH/releases/download/$version/helm-diff-$OS.tgz" + else + getLatestDownloadURL fi + else + getLatestDownloadURL fi } diff --git a/plugin.yaml b/plugin.yaml index a6483a90..0064e8ba 100644 --- a/plugin.yaml +++ b/plugin.yaml @@ -8,4 +8,4 @@ useTunnel: true command: "$HELM_PLUGIN_DIR/bin/diff" hooks: install: "$HELM_PLUGIN_DIR/install-binary.sh" - update: "$HELM_PLUGIN_DIR/install-binary.sh" + update: "$HELM_PLUGIN_DIR/install-binary.sh -u"