Created
July 20, 2017 13:41
-
-
Save hugopeixoto/8fe2e228eab9f387d1291614e4a1502d to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
set -e | |
base_url="https://releases.hashicorp.com/terraform" | |
latest_version="$(curl --silent "https://releases.hashicorp.com/terraform/" | sed -ne 's/.*<a href="\/terraform\/\(.*\)\/".*/\1/p' | grep -v "rc\|beta" | head -n1)" | |
current_version="$(terraform -v | sed -ne 's/Terraform v\(.*\)/\1/p')" | |
if [ "$latest_version" != "$current_version" ]; then | |
echo "updating from ${current_version} to ${latest_version}" | |
dir="$(mktemp -d --suffix "-terraform-upgrade")" | |
pushd "$dir" | |
curl --silent -O "${base_url}/${latest_version}/terraform_${latest_version}_SHA256SUMS" | |
curl --silent -O "${base_url}/${latest_version}/terraform_${latest_version}_SHA256SUMS.sig" | |
curl --silent -O "${base_url}/${latest_version}/terraform_${latest_version}_linux_amd64.zip" | |
gpg --verify "terraform_${latest_version}_SHA256SUMS.sig" "terraform_${latest_version}_SHA256SUMS" | |
shasum -a 256 -c <(grep "_linux_amd64" "terraform_${latest_version}_SHA256SUMS") | |
unzip -o "terraform_${latest_version}_linux_amd64.zip" "terraform" -d ~/bin/ | |
popd | |
rm -r "$dir" | |
else | |
echo "up to date (${latest_version})" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment