Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 32 additions & 28 deletions install-binary.sh
Original file line number Diff line number Diff line change
@@ -1,23 +1,27 @@
#!/usr/bin/env bash
#!/usr/bin/env sh

# Shamelessly copied from https://github.com/technosophos/helm-template

PROJECT_NAME="helm-diff"
PROJECT_GH="databus23/$PROJECT_NAME"
GREP_COLOR="never"
export GREP_COLOR="never"

: ${HELM_PLUGIN_DIR:="$(helm home --debug=false)/plugins/helm-diff"}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We do use HELM_PLUGIN_DIR in installFile. Should we just revert this or just make it POSIX-compliant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mumoshu AFAIK the : denotes the line as pretty much a comment and thus would not run. As helm home is not supported in helm3

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deiga Thanks. I thought so at first, but my tiny experiment revealed that this seems to have actual side-effect of assigning the value.

$ bash -c ': ${FOO:=somevalue}; echo $FOO'
somevalue

As helm home is not supported in helm3

Good catch! Then it can be said that this can safely be removed for helm 3. Not yet sure that's alright for helm 2 though.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Right. Should I add a conditional for helm2?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@deiga That would be awesome! It will allow us to move forward without deciding if it's necessary or not right now.

HELM_MAJOR_VERSION=$(helm version --client --short | awk -F '.' '{print $1}')

if [ "$HELM_MAJOR_VERSION" = "Client: v2" ]; then
: ${HELM_PLUGIN_DIR:="$(helm home --debug=false)/plugins/helm-diff"}
fi

# Convert the HELM_PLUGIN_DIR to unix if cygpath is
# available. This is the case when using MSYS2 or Cygwin
# on Windows where helm returns a Windows path but we
# need a Unix path

if type cygpath > /dev/null 2>&1; then
if type cygpath >/dev/null 2>&1; then
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a cosmetic change, or actually required for POSIX compliance?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cosmetic change

HELM_PLUGIN_DIR=$(cygpath -u $HELM_PLUGIN_DIR)
fi

if [[ $SKIP_BIN_INSTALL == "1" ]]; then
if [ "$SKIP_BIN_INSTALL" = "1" ]; then
echo "Skipping binary install"
exit
fi
Expand All @@ -26,56 +30,56 @@ fi
initArch() {
ARCH=$(uname -m)
case $ARCH in
armv5*) ARCH="armv5";;
armv6*) ARCH="armv6";;
armv7*) ARCH="armv7";;
aarch64) ARCH="arm64";;
x86) ARCH="386";;
x86_64) ARCH="amd64";;
i686) ARCH="386";;
i386) ARCH="386";;
armv5*) ARCH="armv5" ;;
armv6*) ARCH="armv6" ;;
armv7*) ARCH="armv7" ;;
aarch64) ARCH="arm64" ;;
x86) ARCH="386" ;;
x86_64) ARCH="amd64" ;;
i686) ARCH="386" ;;
i386) ARCH="386" ;;
esac
}

# initOS discovers the operating system for this system.
initOS() {
OS=$(echo `uname`|tr '[:upper:]' '[:lower:]')
OS=$(uname | tr '[:upper:]' '[:lower:]')

case "$OS" in
# Msys support
msys*) OS='windows';;
# Minimalist GNU for Windows
mingw*) OS='windows';;
darwin) OS='macos';;
# Msys support
msys*) OS='windows' ;;
# Minimalist GNU for Windows
mingw*) OS='windows' ;;
darwin) OS='macos' ;;
esac
}

# verifySupported checks that the os/arch combination is supported for
# binary builds.
verifySupported() {
local supported="linux-amd64\nfreebsd-amd64\nmacos-amd64\nwindows-amd64"
supported="linux-amd64\nfreebsd-amd64\nmacos-amd64\nwindows-amd64"
if ! echo "${supported}" | grep -q "${OS}-${ARCH}"; then
echo "No prebuild binary for ${OS}-${ARCH}."
exit 1
fi

if ! type "curl" > /dev/null && ! type "wget" > /dev/null; then
if ! type "curl" >/dev/null && ! type "wget" >/dev/null; then
echo "Either curl or wget is required"
exit 1
fi
}

# getDownloadURL checks the latest available version.
getDownloadURL() {
local version=$(git -C $HELM_PLUGIN_DIR describe --tags --exact-match 2>/dev/null)
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.
local url="https://api.github.com/repos/$PROJECT_GH/releases/latest"
if type "curl" > /dev/null; then
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
elif type "wget" >/dev/null; then
DOWNLOAD_URL=$(wget -q -O - $url | grep $OS | awk '/\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}')
fi
fi
Expand All @@ -86,9 +90,9 @@ getDownloadURL() {
downloadFile() {
PLUGIN_TMP_FILE="/tmp/${PROJECT_NAME}.tgz"
echo "Downloading $DOWNLOAD_URL"
if type "curl" > /dev/null; then
if type "curl" >/dev/null; then
curl -L "$DOWNLOAD_URL" -o "$PLUGIN_TMP_FILE"
elif type "wget" > /dev/null; then
elif type "wget" >/dev/null; then
wget -q -O "$PLUGIN_TMP_FILE" "$DOWNLOAD_URL"
fi
}
Expand All @@ -110,7 +114,7 @@ fail_trap() {
result=$?
if [ "$result" != "0" ]; then
echo "Failed to install $PROJECT_NAME"
echo "\tFor support, go to https://github.com/databus23/helm-diff."
printf '\tFor support, go to https://github.com/databus23/helm-diff.\n'
fi
exit $result
}
Expand Down