12
12
# // See the License for the specific language governing permissions and
13
13
# // limitations under the License.
14
14
15
- # This script installs the Helm Kanvas Snapshot plugin.
15
+ #! /usr/bin/env bash
16
16
17
- #! /usr/bin/env sh
18
-
19
- echo " Installing Helm Kanvas Snapshot plugin..."
20
-
21
- CLI=" kanvas-snapshot"
22
- REPO_NAME=" helm-kanvas-snapshot"
23
- PROJECT_ORG=" ${PROJECT_ORG:- meshery} "
24
- PROJECT_GH=" $PROJECT_ORG /$REPO_NAME "
25
- HELM_BIN=" /usr/local/bin/helm"
26
- export GREP_COLOR=" never"
27
-
28
- HELM_MAJOR_VERSION=$( " ${HELM_BIN} " version --client --short | awk -F ' .' ' {print $1}' )
29
-
30
- # : ${HELM_PLUGIN_DIR:="$("${HELM_BIN}" home --debug=false)/plugins/helm-diff"}
31
-
32
- # Handle HELM_PLUGIN_DIR filepath based on OS. Use *nix-based filepathing
33
-
34
- if type cygpath > /dev/null 2>&1 ; then
35
- HELM_PLUGIN_DIR=$( cygpath -u $HELM_PLUGIN_DIR )
36
- fi
37
-
38
- if [ " $SKIP_BIN_INSTALL " = " 1" ]; then
39
- echo " Skipping binary install"
40
- exit
41
- fi
42
-
43
- # Identify systm architecture
44
- initArch () {
45
- ARCH=$( uname -m)
46
- case $ARCH in
47
- armv5* ) ARCH=" armv5" ;;
48
- armv6* ) ARCH=" armv6" ;;
49
- armv7* ) ARCH=" armv7" ;;
50
- aarch64) ARCH=" arm64" ;;
51
- x86) ARCH=" 386" ;;
52
- x86_64) ARCH=" x86_64" ;;
53
- i686) ARCH=" 386" ;;
54
- i386) ARCH=" 386" ;;
55
- esac
56
- echo " ARCH: $ARCH "
57
- }
58
-
59
- # Identify operating system
60
- initOS () {
61
- OS=$( uname | tr ' [:upper:]' ' [:lower:]' )
62
-
63
- case " $OS " in
64
- # Msys support
65
- msys* ) OS=' windows' ;;
66
- # Minimalist GNU for Windows
67
- mingw* ) OS=' windows' ;;
68
- darwin) OS=' darwin' ;;
69
- esac
70
- echo " OS: $OS "
71
- }
72
-
73
- # verifySupported checks that the os/arch combination is supported for
74
- # binary builds.
75
- verifySupported () {
76
- supported=" linux_amd64\ndarwin_x86_64\nlinux_arm64\ndarwin_arm64\nwindows_amd64"
77
- if ! echo " ${supported} " | grep -q " ${OS} _${ARCH} " ; then
78
- echo " No prebuilt binary for ${OS} _${ARCH} ."
79
- exit 1
80
- fi
81
-
82
- if ! type " curl" > /dev/null && ! type " wget" > /dev/null; then
83
- echo " Either curl or wget is required"
84
- exit 1
85
- fi
86
- }
87
-
88
- # getDownloadURL checks the latest available version.
89
- getDownloadURL () {
90
- # version=$(git -C "$HELM_PLUGIN_DIR" describe --tags --exact-match 2>/dev/null || :)
91
- echo " OS: $OS "
92
-
93
- version=" $( cat $HELM_PLUGIN_DIR /plugin.yaml | grep " version" | cut -d ' "' -f 2) "
94
- if [ -n " $version " ]; then
95
- DOWNLOAD_URL=" https://github.com/$PROJECT_GH /releases/download/v$version /$CLI_$version_$OS_$ARCH .tar.gz"
96
- echo " DOWNLOAD_URL1: $DOWNLOAD_URL "
97
- # https://github.com/meshery/helm-kanvas-snapshot/releases/download/v0.2.0/kanvas-snapshot_0.2.0_Darwin_x86_64.tar.gz
98
- else
99
- # Use the GitHub API to find the download url for this project.
100
- url=" https://api.github.com/repos/$PROJECT_GH /releases/latest"
101
- if type " curl" > /dev/null; then
102
- DOWNLOAD_URL=$( curl -s $url | grep $OS_$ARCH \" | awk ' /\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}' )
103
- echo " DOWNLOAD_URL2: $DOWNLOAD_URL "
104
-
105
- elif type " wget" > /dev/null; then
106
- DOWNLOAD_URL=$( wget -q -O - $url | grep $OS_$ARCH \" | awk ' /\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}' )
107
- echo " DOWNLOAD_URL3: $DOWNLOAD_URL "
108
-
109
- fi
110
- fi
111
-
112
- }
113
-
114
- # downloadFile downloads the latest binary package and also the checksum
115
- # for that binary.
116
- downloadFile () {
117
- BINDIR=" $HELM_PLUGIN_DIR /bin"
118
- rm -rf " $BINDIR "
119
- mkdir -p " $BINDIR "
120
- echo " Downloading $DOWNLOAD_URL "
121
- if type " curl" > /dev/null; then
122
- HTTP_CODE=$( curl -sL --write-out " %{http_code}" " $DOWNLOAD_URL " --output " $BINDIR /$CLI " )
123
- if [ ${HTTP_CODE} -ne 200 ]; then
124
- exit 1
125
- fi
126
- elif type " wget" > /dev/null; then
127
- wget -q -O " $BINDIR /$CLI " " $DOWNLOAD_URL "
128
- fi
129
-
130
- chmod +x " $BINDIR /$CLI "
131
-
132
- }
133
-
134
- # fail_trap is executed if an error occurs.
135
- fail_trap () {
136
- result=$?
137
- if [ " $result " != " 0" ]; then
138
- echo " Failed to install $CLI "
139
- printf " \tFor support, go to https://discuss.layer5.io.\n"
140
- fi
141
- exit $result
142
- }
143
-
144
- # testVersion tests the installed client to make sure it is working.
145
- testVersion () {
146
- set +e
147
- echo " $CLI installed into $HELM_PLUGIN_DIR /$CLI "
148
- " ${HELM_PLUGIN_DIR} /bin/$CLI " version
149
- echo " ` helm $CLI --help` to get started."
150
- set -e
151
- }
17
+ source scripts/utils.sh
152
18
153
19
154
20
# Execution
@@ -161,4 +27,9 @@ initOS
161
27
verifySupported
162
28
getDownloadURL
163
29
downloadFile
164
- testVersion
30
+ installFileFromZip
31
+ echo
32
+ echo " helm-kanvas-snapshot is installed at ${HELM_PLUGIN_DIR} /bin/helm-kanvas-snapshot"
33
+ echo
34
+ echo " See https://github.com/$PROJECT_GH #readme for more information on getting started."
35
+
0 commit comments