diff --git a/install-binary.sh b/install-binary.sh index 274e1d97..b8cf349b 100755 --- a/install-binary.sh +++ b/install-binary.sh @@ -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"} +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 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 @@ -26,40 +30,40 @@ 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 @@ -67,15 +71,15 @@ verifySupported() { # 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 @@ -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 } @@ -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 }