This repository has been archived by the owner on Dec 31, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
install-hashicorp-tool.sh
71 lines (56 loc) · 1.56 KB
/
install-hashicorp-tool.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#!/usr/bin/env sh
set -e
#
# Installs the given HashiCorp tool, verifying checksums and GPG signatures. Exits
# non-zero on failure.
#
# Usage:
# install_hashicorp_tool.sh terraform 0.11.5
#
# Requirements:
# - gpg, with hashicorp key trusted
# - curl
# - sha256sum
NAME="$1"
if [ -z "$NAME" ]; then
echo "Missing NAME"
exit 1
fi
VERSION="$2"
if [ -z "$VERSION" ]; then
echo "Missing VERSION"
exit
fi
OS="$3"
if [ -z "$OS" ]; then
OS="linux"
fi
ARCH="$4"
if [ -z "$ARCH" ]; then
ARCH="amd64"
fi
DOWNLOAD_ROOT="https://releases.hashicorp.com/${NAME}/${VERSION}/${NAME}_${VERSION}"
DOWNLOAD_ZIP="${DOWNLOAD_ROOT}_${OS}_${ARCH}.zip"
DOWNLOAD_SHA="${DOWNLOAD_ROOT}_SHA256SUMS"
DOWNLOAD_SIG="${DOWNLOAD_ROOT}_SHA256SUMS.sig"
echo "==> Installing ${NAME} v${VERSION}"
echo "--> Downloading SHASUM and SHASUM signatures"
curl -sfSO "${DOWNLOAD_SHA}"
curl -sfSO "${DOWNLOAD_SIG}"
echo "--> Verifying signatures file"
gpg --verify "${NAME}_${VERSION}_SHA256SUMS.sig" "${NAME}_${VERSION}_SHA256SUMS"
echo "--> Downloading ${NAME} v${VERSION} (${OS}/${ARCH})"
curl -sfSO "${DOWNLOAD_ZIP}"
echo "--> Validating SHA256SUM"
grep "${NAME}_${VERSION}_${OS}_${ARCH}.zip" "${NAME}_${VERSION}_SHA256SUMS" > "SHA256SUMS"
sha256sum -c "SHA256SUMS"
echo "--> Unpacking and installing"
mkdir -p "/software"
unzip "${NAME}_${VERSION}_${OS}_${ARCH}.zip"
mv "${NAME}" "/software/${NAME}"
chmod +x "/software/${NAME}"
echo "--> Removing temporary files"
rm "${NAME}_${VERSION}_${OS}_${ARCH}.zip"
rm "${NAME}_${VERSION}_SHA256SUMS"
rm "${NAME}_${VERSION}_SHA256SUMS.sig"
echo "--> Done!"