Skip to content

Instantly share code, notes, and snippets.

@hugopeixoto
Created July 20, 2017 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hugopeixoto/8fe2e228eab9f387d1291614e4a1502d to your computer and use it in GitHub Desktop.
Save hugopeixoto/8fe2e228eab9f387d1291614e4a1502d to your computer and use it in GitHub Desktop.
#!/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