1
- #! /usr/bin/env bash
1
+ #! /usr/bin/env sh
2
2
3
3
# Shamelessly copied from https://github.com/technosophos/helm-template
4
4
5
5
PROJECT_NAME=" helm-diff"
6
6
PROJECT_GH=" databus23/$PROJECT_NAME "
7
- GREP_COLOR=" never"
7
+ export GREP_COLOR=" never"
8
8
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
10
14
11
15
# Convert the HELM_PLUGIN_DIR to unix if cygpath is
12
16
# available. This is the case when using MSYS2 or Cygwin
13
17
# on Windows where helm returns a Windows path but we
14
18
# need a Unix path
15
19
16
- if type cygpath > /dev/null 2>&1 ; then
20
+ if type cygpath > /dev/null 2>&1 ; then
17
21
HELM_PLUGIN_DIR=$( cygpath -u $HELM_PLUGIN_DIR )
18
22
fi
19
23
20
- if [[ $SKIP_BIN_INSTALL == " 1" ] ]; then
24
+ if [ " $SKIP_BIN_INSTALL " = " 1" ]; then
21
25
echo " Skipping binary install"
22
26
exit
23
27
fi
26
30
initArch () {
27
31
ARCH=$( uname -m)
28
32
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" ;;
37
41
esac
38
42
}
39
43
40
44
# initOS discovers the operating system for this system.
41
45
initOS () {
42
- OS=$( echo ` uname` | tr ' [:upper:]' ' [:lower:]' )
46
+ OS=$( uname | tr ' [:upper:]' ' [:lower:]' )
43
47
44
48
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' ;;
50
54
esac
51
55
}
52
56
53
57
# verifySupported checks that the os/arch combination is supported for
54
58
# binary builds.
55
59
verifySupported () {
56
- local supported=" linux-amd64\nfreebsd-amd64\nmacos-amd64\nwindows-amd64"
60
+ supported=" linux-amd64\nfreebsd-amd64\nmacos-amd64\nwindows-amd64"
57
61
if ! echo " ${supported} " | grep -q " ${OS} -${ARCH} " ; then
58
62
echo " No prebuild binary for ${OS} -${ARCH} ."
59
63
exit 1
60
64
fi
61
65
62
- if ! type " curl" > /dev/null && ! type " wget" > /dev/null; then
66
+ if ! type " curl" > /dev/null && ! type " wget" > /dev/null; then
63
67
echo " Either curl or wget is required"
64
68
exit 1
65
69
fi
66
70
}
67
71
68
72
# getDownloadURL checks the latest available version.
69
73
getDownloadURL () {
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)
71
75
if [ -n " $version " ]; then
72
76
DOWNLOAD_URL=" https://github.com/$PROJECT_GH /releases/download/$version /helm-diff-$OS .tgz"
73
77
else
74
78
# 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
77
81
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
79
83
DOWNLOAD_URL=$( wget -q -O - $url | grep $OS | awk ' /\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}' )
80
84
fi
81
85
fi
@@ -86,9 +90,9 @@ getDownloadURL() {
86
90
downloadFile () {
87
91
PLUGIN_TMP_FILE=" /tmp/${PROJECT_NAME} .tgz"
88
92
echo " Downloading $DOWNLOAD_URL "
89
- if type " curl" > /dev/null; then
93
+ if type " curl" > /dev/null; then
90
94
curl -L " $DOWNLOAD_URL " -o " $PLUGIN_TMP_FILE "
91
- elif type " wget" > /dev/null; then
95
+ elif type " wget" > /dev/null; then
92
96
wget -q -O " $PLUGIN_TMP_FILE " " $DOWNLOAD_URL "
93
97
fi
94
98
}
@@ -110,7 +114,7 @@ fail_trap() {
110
114
result=$?
111
115
if [ " $result " != " 0" ]; then
112
116
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 '
114
118
fi
115
119
exit $result
116
120
}
0 commit comments