Skip to content

Instantly share code, notes, and snippets.

@checco
Last active October 21, 2023 08:39
Show Gist options
  • Save checco/ea308d7ee37ab4066b3f4129acf0d677 to your computer and use it in GitHub Desktop.
Save checco/ea308d7ee37ab4066b3f4129acf0d677 to your computer and use it in GitHub Desktop.
[deprecated] Bash script to upgrade Vault to the latest release on Linux
#!/bin/bash
url="https://releases.hashicorp.com/vault"
latest_version=`curl -s ${url}/ | grep -A6 "<a href=\"../\">../</a>" | grep vault | cut -d '_' -f 2 | cut -d '<' -f 1`
bin="/usr/local/bin/vault"
install () {
cd /tmp && \
/bin/wget -q ${url}/${latest_version}/vault_${latest_version}_linux_amd64.zip && \
/bin/unzip -qq vault_${latest_version}_linux_amd64.zip
sudo cp vault ${bin} && sudo cp vault ${bin}-${latest_version}
}
if [ ! -f "${bin}" ]; then
echo "Installing Vault v${latest_version}"
install && echo "Vault v${latest_version} installed"
else
cur_version=`${bin} version | grep Vault | cut -d 'v' -f 2 | awk '{print $1}'`
echo "You're using Vault v${cur_version}"
if [ "${latest_version}" != "${cur_version}" ]; then
echo "A new Vault release is available: v${latest_version}"
echo -n "Do you want to install this new release (y/n)? "
read answer
if [ "$answer" != "${answer#[Yy]}" ]; then
install && echo "Vault updated to the latest release"
else
echo "Skipped the Vault update to v${latest_version} release"
fi
else
echo "You're already running the latest release"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment