Skip to content

Commit dffced2

Browse files
committed
fix integration test1
1 parent e4f778c commit dffced2

2 files changed

Lines changed: 383 additions & 797 deletions

File tree

Lines changed: 347 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,347 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright The Helm Authors.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# The install script is based off of the MIT-licensed script from glide,
18+
# the package manager for Go: https://github.com/Masterminds/glide.sh/blob/master/get
19+
20+
: ${BINARY_NAME:="helm"}
21+
: ${USE_SUDO:="true"}
22+
: ${DEBUG:="false"}
23+
: ${VERIFY_CHECKSUM:="true"}
24+
: ${VERIFY_SIGNATURES:="false"}
25+
: ${HELM_INSTALL_DIR:="/usr/local/bin"}
26+
: ${GPG_PUBRING:="pubring.kbx"}
27+
28+
HAS_CURL="$(type "curl" &> /dev/null && echo true || echo false)"
29+
HAS_WGET="$(type "wget" &> /dev/null && echo true || echo false)"
30+
HAS_OPENSSL="$(type "openssl" &> /dev/null && echo true || echo false)"
31+
HAS_GPG="$(type "gpg" &> /dev/null && echo true || echo false)"
32+
HAS_GIT="$(type "git" &> /dev/null && echo true || echo false)"
33+
HAS_TAR="$(type "tar" &> /dev/null && echo true || echo false)"
34+
35+
# initArch discovers the architecture for this system.
36+
initArch() {
37+
ARCH=$(uname -m)
38+
case $ARCH in
39+
armv5*) ARCH="armv5";;
40+
armv6*) ARCH="armv6";;
41+
armv7*) ARCH="arm";;
42+
aarch64) ARCH="arm64";;
43+
x86) ARCH="386";;
44+
x86_64) ARCH="amd64";;
45+
i686) ARCH="386";;
46+
i386) ARCH="386";;
47+
esac
48+
}
49+
50+
# initOS discovers the operating system for this system.
51+
initOS() {
52+
OS=$(echo `uname`|tr '[:upper:]' '[:lower:]')
53+
54+
case "$OS" in
55+
# Minimalist GNU for Windows
56+
mingw*|cygwin*) OS='windows';;
57+
esac
58+
}
59+
60+
# runs the given command as root (detects if we are root already)
61+
runAsRoot() {
62+
if [ $EUID -ne 0 -a "$USE_SUDO" = "true" ]; then
63+
sudo "${@}"
64+
else
65+
"${@}"
66+
fi
67+
}
68+
69+
# verifySupported checks that the os/arch combination is supported for
70+
# binary builds, as well whether or not necessary tools are present.
71+
verifySupported() {
72+
local supported="darwin-amd64\ndarwin-arm64\nlinux-386\nlinux-amd64\nlinux-arm\nlinux-arm64\nlinux-ppc64le\nlinux-s390x\nlinux-riscv64\nwindows-amd64\nwindows-arm64"
73+
if ! echo "${supported}" | grep -q "${OS}-${ARCH}"; then
74+
echo "No prebuilt binary for ${OS}-${ARCH}."
75+
echo "To build from source, go to https://github.com/helm/helm"
76+
exit 1
77+
fi
78+
79+
if [ "${HAS_CURL}" != "true" ] && [ "${HAS_WGET}" != "true" ]; then
80+
echo "Either curl or wget is required"
81+
exit 1
82+
fi
83+
84+
if [ "${VERIFY_CHECKSUM}" == "true" ] && [ "${HAS_OPENSSL}" != "true" ]; then
85+
echo "In order to verify checksum, openssl must first be installed."
86+
echo "Please install openssl or set VERIFY_CHECKSUM=false in your environment."
87+
exit 1
88+
fi
89+
90+
if [ "${VERIFY_SIGNATURES}" == "true" ]; then
91+
if [ "${HAS_GPG}" != "true" ]; then
92+
echo "In order to verify signatures, gpg must first be installed."
93+
echo "Please install gpg or set VERIFY_SIGNATURES=false in your environment."
94+
exit 1
95+
fi
96+
if [ "${OS}" != "linux" ]; then
97+
echo "Signature verification is currently only supported on Linux."
98+
echo "Please set VERIFY_SIGNATURES=false or verify the signatures manually."
99+
exit 1
100+
fi
101+
fi
102+
103+
if [ "${HAS_GIT}" != "true" ]; then
104+
echo "[WARNING] Could not find git. It is required for plugin installation."
105+
fi
106+
107+
if [ "${HAS_TAR}" != "true" ]; then
108+
echo "[ERROR] Could not find tar. It is required to extract the helm binary archive."
109+
exit 1
110+
fi
111+
}
112+
113+
# checkDesiredVersion checks if the desired version is available.
114+
checkDesiredVersion() {
115+
if [ "x$DESIRED_VERSION" == "x" ]; then
116+
# Get tag from release URL
117+
local latest_release_url="https://get.helm.sh/helm-latest-version"
118+
local latest_release_response=""
119+
if [ "${HAS_CURL}" == "true" ]; then
120+
latest_release_response=$( curl -L --silent --show-error --fail "$latest_release_url" 2>&1 || true )
121+
elif [ "${HAS_WGET}" == "true" ]; then
122+
latest_release_response=$( wget "$latest_release_url" -q -O - 2>&1 || true )
123+
fi
124+
TAG=$( echo "$latest_release_response" | grep '^v[0-9]' )
125+
if [ "x$TAG" == "x" ]; then
126+
printf "Could not retrieve the latest release tag information from %s: %s\n" "${latest_release_url}" "${latest_release_response}"
127+
exit 1
128+
fi
129+
else
130+
TAG=$DESIRED_VERSION
131+
fi
132+
}
133+
134+
# checkHelmInstalledVersion checks which version of helm is installed and
135+
# if it needs to be changed.
136+
checkHelmInstalledVersion() {
137+
if [[ -f "${HELM_INSTALL_DIR}/${BINARY_NAME}" ]]; then
138+
local version=$("${HELM_INSTALL_DIR}/${BINARY_NAME}" version --template="{{ .Version }}")
139+
if [[ "$version" == "$TAG" ]]; then
140+
echo "Helm ${version} is already ${DESIRED_VERSION:-latest}"
141+
return 0
142+
else
143+
echo "Helm ${TAG} is available. Changing from version ${version}."
144+
return 1
145+
fi
146+
else
147+
return 1
148+
fi
149+
}
150+
151+
# downloadFile downloads the latest binary package and also the checksum
152+
# for that binary.
153+
downloadFile() {
154+
HELM_DIST="helm-$TAG-$OS-$ARCH.tar.gz"
155+
DOWNLOAD_URL="https://get.helm.sh/$HELM_DIST"
156+
CHECKSUM_URL="$DOWNLOAD_URL.sha256"
157+
HELM_TMP_ROOT="$(mktemp -dt helm-installer-XXXXXX)"
158+
HELM_TMP_FILE="$HELM_TMP_ROOT/$HELM_DIST"
159+
HELM_SUM_FILE="$HELM_TMP_ROOT/$HELM_DIST.sha256"
160+
echo "Downloading $DOWNLOAD_URL"
161+
if [ "${HAS_CURL}" == "true" ]; then
162+
curl -SsL "$CHECKSUM_URL" -o "$HELM_SUM_FILE"
163+
curl -SsL "$DOWNLOAD_URL" -o "$HELM_TMP_FILE"
164+
elif [ "${HAS_WGET}" == "true" ]; then
165+
wget -q -O "$HELM_SUM_FILE" "$CHECKSUM_URL"
166+
wget -q -O "$HELM_TMP_FILE" "$DOWNLOAD_URL"
167+
fi
168+
}
169+
170+
# verifyFile verifies the SHA256 checksum of the binary package
171+
# and the GPG signatures for both the package and checksum file
172+
# (depending on settings in environment).
173+
verifyFile() {
174+
if [ "${VERIFY_CHECKSUM}" == "true" ]; then
175+
verifyChecksum
176+
fi
177+
if [ "${VERIFY_SIGNATURES}" == "true" ]; then
178+
verifySignatures
179+
fi
180+
}
181+
182+
# installFile installs the Helm binary.
183+
installFile() {
184+
HELM_TMP="$HELM_TMP_ROOT/$BINARY_NAME"
185+
mkdir -p "$HELM_TMP"
186+
tar xf "$HELM_TMP_FILE" -C "$HELM_TMP"
187+
HELM_TMP_BIN="$HELM_TMP/$OS-$ARCH/helm"
188+
echo "Preparing to install $BINARY_NAME into ${HELM_INSTALL_DIR}"
189+
runAsRoot cp "$HELM_TMP_BIN" "$HELM_INSTALL_DIR/$BINARY_NAME"
190+
echo "$BINARY_NAME installed into $HELM_INSTALL_DIR/$BINARY_NAME"
191+
}
192+
193+
# verifyChecksum verifies the SHA256 checksum of the binary package.
194+
verifyChecksum() {
195+
printf "Verifying checksum... "
196+
local sum=$(openssl sha1 -sha256 ${HELM_TMP_FILE} | awk '{print $2}')
197+
local expected_sum=$(cat ${HELM_SUM_FILE})
198+
if [ "$sum" != "$expected_sum" ]; then
199+
echo "SHA sum of ${HELM_TMP_FILE} does not match. Aborting."
200+
exit 1
201+
fi
202+
echo "Done."
203+
}
204+
205+
# verifySignatures obtains the latest KEYS file from GitHub main branch
206+
# as well as the signature .asc files from the specific GitHub release,
207+
# then verifies that the release artifacts were signed by a maintainer's key.
208+
verifySignatures() {
209+
printf "Verifying signatures... "
210+
local keys_filename="KEYS"
211+
local github_keys_url="https://raw.githubusercontent.com/helm/helm/main/${keys_filename}"
212+
if [ "${HAS_CURL}" == "true" ]; then
213+
curl -SsL "${github_keys_url}" -o "${HELM_TMP_ROOT}/${keys_filename}"
214+
elif [ "${HAS_WGET}" == "true" ]; then
215+
wget -q -O "${HELM_TMP_ROOT}/${keys_filename}" "${github_keys_url}"
216+
fi
217+
local gpg_keyring="${HELM_TMP_ROOT}/keyring.gpg"
218+
local gpg_homedir="${HELM_TMP_ROOT}/gnupg"
219+
mkdir -p -m 0700 "${gpg_homedir}"
220+
local gpg_stderr_device="/dev/null"
221+
if [ "${DEBUG}" == "true" ]; then
222+
gpg_stderr_device="/dev/stderr"
223+
fi
224+
gpg --batch --quiet --homedir="${gpg_homedir}" --import "${HELM_TMP_ROOT}/${keys_filename}" 2> "${gpg_stderr_device}"
225+
gpg --batch --no-default-keyring --keyring "${gpg_homedir}/${GPG_PUBRING}" --export > "${gpg_keyring}"
226+
local github_release_url="https://github.com/helm/helm/releases/download/${TAG}"
227+
if [ "${HAS_CURL}" == "true" ]; then
228+
curl -SsL "${github_release_url}/helm-${TAG}-${OS}-${ARCH}.tar.gz.sha256.asc" -o "${HELM_TMP_ROOT}/helm-${TAG}-${OS}-${ARCH}.tar.gz.sha256.asc"
229+
curl -SsL "${github_release_url}/helm-${TAG}-${OS}-${ARCH}.tar.gz.asc" -o "${HELM_TMP_ROOT}/helm-${TAG}-${OS}-${ARCH}.tar.gz.asc"
230+
elif [ "${HAS_WGET}" == "true" ]; then
231+
wget -q -O "${HELM_TMP_ROOT}/helm-${TAG}-${OS}-${ARCH}.tar.gz.sha256.asc" "${github_release_url}/helm-${TAG}-${OS}-${ARCH}.tar.gz.sha256.asc"
232+
wget -q -O "${HELM_TMP_ROOT}/helm-${TAG}-${OS}-${ARCH}.tar.gz.asc" "${github_release_url}/helm-${TAG}-${OS}-${ARCH}.tar.gz.asc"
233+
fi
234+
local error_text="If you think this might be a potential security issue,"
235+
error_text="${error_text}\nplease see here: https://github.com/helm/community/blob/master/SECURITY.md"
236+
local num_goodlines_sha=$(gpg --verify --keyring="${gpg_keyring}" --status-fd=1 "${HELM_TMP_ROOT}/helm-${TAG}-${OS}-${ARCH}.tar.gz.sha256.asc" 2> "${gpg_stderr_device}" | grep -c -E '^\[GNUPG:\] (GOODSIG|VALIDSIG)')
237+
if [[ ${num_goodlines_sha} -lt 2 ]]; then
238+
echo "Unable to verify the signature of helm-${TAG}-${OS}-${ARCH}.tar.gz.sha256!"
239+
echo -e "${error_text}"
240+
exit 1
241+
fi
242+
local num_goodlines_tar=$(gpg --verify --keyring="${gpg_keyring}" --status-fd=1 "${HELM_TMP_ROOT}/helm-${TAG}-${OS}-${ARCH}.tar.gz.asc" 2> "${gpg_stderr_device}" | grep -c -E '^\[GNUPG:\] (GOODSIG|VALIDSIG)')
243+
if [[ ${num_goodlines_tar} -lt 2 ]]; then
244+
echo "Unable to verify the signature of helm-${TAG}-${OS}-${ARCH}.tar.gz!"
245+
echo -e "${error_text}"
246+
exit 1
247+
fi
248+
echo "Done."
249+
}
250+
251+
# fail_trap is executed if an error occurs.
252+
fail_trap() {
253+
result=$?
254+
if [ "$result" != "0" ]; then
255+
if [[ -n "$INPUT_ARGUMENTS" ]]; then
256+
echo "Failed to install $BINARY_NAME with the arguments provided: $INPUT_ARGUMENTS"
257+
help
258+
else
259+
echo "Failed to install $BINARY_NAME"
260+
fi
261+
echo -e "\tFor support, go to https://github.com/helm/helm."
262+
fi
263+
cleanup
264+
exit $result
265+
}
266+
267+
# testVersion tests the installed client to make sure it is working.
268+
testVersion() {
269+
set +e
270+
HELM="$(command -v $BINARY_NAME)"
271+
if [ "$?" = "1" ]; then
272+
echo "$BINARY_NAME not found. Is $HELM_INSTALL_DIR on your "'$PATH?'
273+
exit 1
274+
fi
275+
set -e
276+
}
277+
278+
# help provides possible cli installation arguments
279+
help () {
280+
echo "Accepted cli arguments are:"
281+
echo -e "\t[--help|-h ] ->> prints this help"
282+
echo -e "\t[--version|-v <desired_version>] . When not defined it fetches the latest release tag from the Helm CDN"
283+
echo -e "\te.g. --version v3.0.0 or -v canary"
284+
echo -e "\t[--no-sudo] ->> install without sudo"
285+
}
286+
287+
# cleanup temporary files to avoid https://github.com/helm/helm/issues/2977
288+
cleanup() {
289+
if [[ -d "${HELM_TMP_ROOT:-}" ]]; then
290+
rm -rf "$HELM_TMP_ROOT"
291+
fi
292+
}
293+
294+
# Execution
295+
296+
#Stop execution on any error
297+
trap "fail_trap" EXIT
298+
set -e
299+
300+
# Set debug if desired
301+
if [ "${DEBUG}" == "true" ]; then
302+
set -x
303+
fi
304+
305+
# Parsing input arguments (if any)
306+
export INPUT_ARGUMENTS="${@}"
307+
set -u
308+
while [[ $# -gt 0 ]]; do
309+
case $1 in
310+
'--version'|-v)
311+
shift
312+
if [[ $# -ne 0 ]]; then
313+
export DESIRED_VERSION="${1}"
314+
if [[ "$1" != "v"* ]]; then
315+
echo "Expected version arg ('${DESIRED_VERSION}') to begin with 'v', fixing..."
316+
export DESIRED_VERSION="v${1}"
317+
fi
318+
else
319+
echo -e "Please provide the desired version. e.g. --version v3.0.0 or -v canary"
320+
exit 0
321+
fi
322+
;;
323+
'--no-sudo')
324+
USE_SUDO="false"
325+
;;
326+
'--help'|-h)
327+
help
328+
exit 0
329+
;;
330+
*) exit 1
331+
;;
332+
esac
333+
shift
334+
done
335+
set +u
336+
337+
initArch
338+
initOS
339+
verifySupported
340+
checkDesiredVersion
341+
if ! checkHelmInstalledVersion; then
342+
downloadFile
343+
verifyFile
344+
installFile
345+
fi
346+
testVersion
347+
cleanup

0 commit comments

Comments
 (0)