Created
November 18, 2021 20:10
-
-
Save apolloclark/c2ac20cce7f5b5debb4f371bc90d0b97 to your computer and use it in GitHub Desktop.
Upgrade HashiCorp tools in Ubuntu
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash -eu | |
PACKAGE_LIST="terraform packer sentinel vagrant"; | |
for PACKAGE in $PACKAGE_LIST; do | |
# retrieve a link to the latest version | |
VERSION_LATEST=$(curl -sSLk https://releases.hashicorp.com/index.json \ | |
| jq ".${PACKAGE}.versions | keys | .[]" | tr -d '"' \ | |
| grep -v 'alpha\|beta\|rc\|oci\|ent' | sort --version-sort | tail -n1); | |
echo "VERSION_LATEST = ${VERSION_LATEST}"; | |
# get the currently installed version | |
VERSION_CURRENT=$(${PACKAGE} -v | grep -Po "([0-9]|\.)*" | head -n1); | |
echo "VERSION_CURRENT = ${VERSION_CURRENT}"; | |
# check if the latest version matches the currently installed version | |
if [ "$VERSION_LATEST" = "$VERSION_CURRENT" ]; then | |
echo "Already running the latest version of ${PACKAGE} == ${VERSION_CURRENT}" | |
continue; | |
fi | |
# generate the download URL | |
URL=$(echo 'https://releases.hashicorp.com/'${PACKAGE}'/'"${VERSION_LATEST}"'/'${PACKAGE}'_'"${VERSION_LATEST}"'_linux_amd64.zip') | |
echo "URL = ${URL}"; | |
# get the file, install it | |
cd /tmp | |
wget -q "${URL}" | |
unzip ./${PACKAGE}_*.zip | |
mv ./${PACKAGE} ~/bin | |
${PACKAGE} --version | grep -F "${VERSION_LATEST}" | |
rm -rf /tmp/${PACKAGE}* | |
done | |
vagrant plugin update |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment