1+ #! /usr/bin/env bash
2+
3+ # Copied from https://github.com/technosophos/helm-template
4+ # Combination of the Glide and Helm scripts, with my own tweaks.
5+
6+ PROJECT_NAME=" helm-ssm"
7+ PROJECT_GH=" codacy/$PROJECT_NAME "
8+ $( helm env)
9+
10+ # Convert the HELM_PLUGIN to unix if cygpath is
11+ # available. This is the case when using MSYS2 or Cygwin
12+ # on Windows where helm returns a Windows path but we
13+ # need a Unix path
14+ if type cygpath > /dev/null; then
15+ HELM_PLUGIN=$( cygpath -u " $HELM_PLUGIN " )
16+ fi
17+
18+ if [[ $SKIP_BIN_INSTALL == " 1" ]]; then
19+ echo " Skipping binary install"
20+ exit
21+ fi
22+
23+ # initArch discovers the architecture for this system.
24+ initArch () {
25+ ARCH=$( uname -m)
26+ case $ARCH in
27+ armv5* ) ARCH=" armv5" ;;
28+ armv6* ) ARCH=" armv6" ;;
29+ armv7* ) ARCH=" armv7" ;;
30+ aarch64) ARCH=" arm64" ;;
31+ x86) ARCH=" 386" ;;
32+ x86_64) ARCH=" amd64" ;;
33+ i686) ARCH=" 386" ;;
34+ i386) ARCH=" 386" ;;
35+ esac
36+ }
37+
38+ # initOS discovers the operating system for this system.
39+ initOS () {
40+ OS=$( echo $( uname) | tr ' [:upper:]' ' [:lower:]' )
41+ case " $OS " in
42+ # Msys support
43+ msys* ) OS=' windows' ;;
44+ # Minimalist GNU for Windows
45+ mingw* ) OS=' windows' ;;
46+ darwin) OS=' macos' ;;
47+ esac
48+ }
49+
50+ # verifySupported checks that the os/arch combination is supported for
51+ # binary builds.
52+ verifySupported () {
53+ local supported=" linux-amd64\nmacos-amd64\nwindows-amd64"
54+ if ! echo " ${supported} " | grep -q " ${OS} -${ARCH} " ; then
55+ echo " No prebuild binary for ${OS} -${ARCH} ."
56+ exit 1
57+ fi
58+
59+ if ! type " curl" > /dev/null && ! type " wget" > /dev/null; then
60+ echo " Either curl or wget is required"
61+ exit 1
62+ fi
63+ }
64+
65+ # getDownloadURL checks the latest available version.
66+ getDownloadURL () {
67+ # Use the GitHub API to find the latest version for this project.
68+ local latest_url=" https://api.github.com/repos/$PROJECT_GH /releases/latest"
69+ if type " curl" > /dev/null; then
70+ DOWNLOAD_URL=$( curl -s $latest_url | grep $OS | awk ' /\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}' )
71+ elif type " wget" > /dev/null; then
72+ DOWNLOAD_URL=$( wget -q -O - $latest_url | awk ' /\"browser_download_url\":/{gsub( /[,\"]/,"", $2); print $2}' )
73+ fi
74+ }
75+
76+ # downloadFile downloads the latest binary package and also the checksum
77+ # for that binary.
78+ downloadFile () {
79+ PLUGIN_TMP_FILE=" /tmp/${PROJECT_NAME} .tgz"
80+ echo " Downloading $DOWNLOAD_URL "
81+ if type " curl" > /dev/null; then
82+ curl -L " $DOWNLOAD_URL " -o " $PLUGIN_TMP_FILE "
83+ elif type " wget" > /dev/null; then
84+ wget -q -O " $PLUGIN_TMP_FILE " " $DOWNLOAD_URL "
85+ fi
86+ }
87+
88+ # installFile verifies the SHA256 for the file, then unpacks and
89+ # installs it.
90+ installFile () {
91+ HELM_TMP=" /tmp/$PROJECT_NAME "
92+ mkdir -p " $HELM_TMP "
93+ tar xf " $PLUGIN_TMP_FILE " -C " $HELM_TMP "
94+ echo " $HELM_TMP "
95+ HELM_TMP_BIN=" $HELM_TMP /helm-ssm"
96+ echo " Preparing to install into ${HELM_PLUGIN} "
97+ # Use * to also copy the file withe the exe suffix on Windows
98+ cp " $HELM_TMP_BIN " * " $HELM_PLUGIN "
99+ }
100+
101+ # fail_trap is executed if an error occurs.
102+ fail_trap () {
103+ result=$?
104+ if [ " $result " != " 0" ]; then
105+ echo " Failed to install $PROJECT_NAME "
106+ echo " For support, go to https://github.com/codacy/helm-ssm."
107+ fi
108+ exit $result
109+ }
110+
111+ # testVersion tests the installed client to make sure it is working.
112+ testVersion () {
113+ set +e
114+ echo " $PROJECT_NAME installed into $HELM_PLUGIN /$PROJECT_NAME "
115+ # To avoid to keep track of the Windows suffix,
116+ # call the plugin assuming it is in the PATH
117+ PATH=$PATH :$HELM_PLUGIN
118+ helm-ssm -h
119+ set -e
120+ }
121+
122+ # Execution
123+
124+ # Stop execution on any error
125+ trap " fail_trap" EXIT
126+ set -e
127+ initArch
128+ initOS
129+ verifySupported
130+ getDownloadURL
131+ downloadFile
132+ installFile
133+ testVersion
0 commit comments