1- #! /usr/bin/env bash
1+ #! /usr/bin/env sh
22
33# Shamelessly copied from https://github.com/technosophos/helm-template
44
55PROJECT_NAME=" helm-diff"
66PROJECT_GH=" databus23/$PROJECT_NAME "
7- GREP_COLOR=" never"
7+ export GREP_COLOR=" never"
88
9- : ${HELM_PLUGIN_DIR:= " $( helm home --debug=false) /plugins/helm-diff" }
9+ HELM_MAJOR_VERSION=$( helm version --client --short | awk -F ' .' ' {print $1}' )
10+
11+ if [ " $HELM_MAJOR_VERSION " = " Client: v2" ]; then
12+ : ${HELM_PLUGIN_DIR:= " $( helm home --debug=false) /plugins/helm-diff" }
13+ fi
1014
1115# Convert the HELM_PLUGIN_DIR to unix if cygpath is
1216# available. This is the case when using MSYS2 or Cygwin
1317# on Windows where helm returns a Windows path but we
1418# need a Unix path
1519
16- if type cygpath > /dev/null 2>&1 ; then
20+ if type cygpath > /dev/null 2>&1 ; then
1721 HELM_PLUGIN_DIR=$( cygpath -u $HELM_PLUGIN_DIR )
1822fi
1923
20- if [[ $SKIP_BIN_INSTALL == " 1" ] ]; then
24+ if [ " $SKIP_BIN_INSTALL " = " 1" ]; then
2125 echo " Skipping binary install"
2226 exit
2327fi
2630initArch () {
2731 ARCH=$( uname -m)
2832 case $ARCH in
29- armv5* ) ARCH=" armv5" ;;
30- armv6* ) ARCH=" armv6" ;;
31- armv7* ) ARCH=" armv7" ;;
32- aarch64) ARCH=" arm64" ;;
33- x86) ARCH=" 386" ;;
34- x86_64) ARCH=" amd64" ;;
35- i686) ARCH=" 386" ;;
36- i386) ARCH=" 386" ;;
33+ armv5* ) ARCH=" armv5" ;;
34+ armv6* ) ARCH=" armv6" ;;
35+ armv7* ) ARCH=" armv7" ;;
36+ aarch64) ARCH=" arm64" ;;
37+ x86) ARCH=" 386" ;;
38+ x86_64) ARCH=" amd64" ;;
39+ i686) ARCH=" 386" ;;
40+ i386) ARCH=" 386" ;;
3741 esac
3842}
3943
4044# initOS discovers the operating system for this system.
4145initOS () {
42- OS=$( echo ` uname` | tr ' [:upper:]' ' [:lower:]' )
46+ OS=$( uname | tr ' [:upper:]' ' [:lower:]' )
4347
4448 case " $OS " in
45- # Msys support
46- msys* ) OS=' windows' ;;
47- # Minimalist GNU for Windows
48- mingw* ) OS=' windows' ;;
49- darwin) OS=' macos' ;;
49+ # Msys support
50+ msys* ) OS=' windows' ;;
51+ # Minimalist GNU for Windows
52+ mingw* ) OS=' windows' ;;
53+ darwin) OS=' macos' ;;
5054 esac
5155}
5256
5357# verifySupported checks that the os/arch combination is supported for
5458# binary builds.
5559verifySupported () {
56- local supported=" linux-amd64\nfreebsd-amd64\nmacos-amd64\nwindows-amd64"
60+ supported=" linux-amd64\nfreebsd-amd64\nmacos-amd64\nwindows-amd64"
5761 if ! echo " ${supported} " | grep -q " ${OS} -${ARCH} " ; then
5862 echo " No prebuild binary for ${OS} -${ARCH} ."
5963 exit 1
6064 fi
6165
62- if ! type " curl" > /dev/null && ! type " wget" > /dev/null; then
66+ if ! type " curl" > /dev/null && ! type " wget" > /dev/null; then
6367 echo " Either curl or wget is required"
6468 exit 1
6569 fi
6670}
6771
6872# getDownloadURL checks the latest available version.
6973getDownloadURL () {
70- local version=$( git -C $HELM_PLUGIN_DIR describe --tags --exact-match 2> /dev/null)
74+ version=$( git -C " $HELM_PLUGIN_DIR " describe --tags --exact-match 2> /dev/null)
7175 if [ -n " $version " ]; then
7276 DOWNLOAD_URL=" https://github.com/$PROJECT_GH /releases/download/$version /helm-diff-$OS .tgz"
7377 else
7478 # Use the GitHub API to find the download url for this project.
75- local url=" https://api.github.com/repos/$PROJECT_GH /releases/latest"
76- if type " curl" > /dev/null; then
79+ url=" https://api.github.com/repos/$PROJECT_GH /releases/latest"
80+ if type " curl" > /dev/null; then
7781 DOWNLOAD_URL=$( curl -s $url | grep $OS | awk ' /\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}' )
78- elif type " wget" > /dev/null; then
82+ elif type " wget" > /dev/null; then
7983 DOWNLOAD_URL=$( wget -q -O - $url | grep $OS | awk ' /\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}' )
8084 fi
8185 fi
@@ -86,9 +90,9 @@ getDownloadURL() {
8690downloadFile () {
8791 PLUGIN_TMP_FILE=" /tmp/${PROJECT_NAME} .tgz"
8892 echo " Downloading $DOWNLOAD_URL "
89- if type " curl" > /dev/null; then
93+ if type " curl" > /dev/null; then
9094 curl -L " $DOWNLOAD_URL " -o " $PLUGIN_TMP_FILE "
91- elif type " wget" > /dev/null; then
95+ elif type " wget" > /dev/null; then
9296 wget -q -O " $PLUGIN_TMP_FILE " " $DOWNLOAD_URL "
9397 fi
9498}
@@ -110,7 +114,7 @@ fail_trap() {
110114 result=$?
111115 if [ " $result " != " 0" ]; then
112116 echo " Failed to install $PROJECT_NAME "
113- echo " \tFor support, go to https://github.com/databus23/helm-diff."
117+ printf ' \tFor support, go to https://github.com/databus23/helm-diff.\n '
114118 fi
115119 exit $result
116120}
0 commit comments