Last active
March 26, 2024 14:42
-
-
Save kitos9112/2252c54fff5bde6638b340fcade9076b to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
########################################################################### | |
# Fetch and install the latest Packer version | |
# curl -Ls https://gist.githubusercontent.com/kitos9112/2252c54fff5bde6638b340fcade9076b/raw/777667f390965c6ad79e8b4e2a0c1a1ad70e2801/get-packer.sh | bash | |
########################################################################## | |
function get_latest_github_release { | |
curl -s https://api.github.com/repos/$1/$2/releases/latest | grep -oP '"tag_name": "[v]\K(.*)(?=")' | |
} | |
INSTALL_DIR='/usr/local/bin' | |
REGEX="^PATH=.*\K$INSTALL_DIR(?=.*)" | |
if [[ $(env | grep -oP $REGEX) != $INSTALL_DIR ]]; then | |
echo "Looks like your install directory $INSTALL_DIR is not in your PATH. Make sure you export it"; fi | |
INSTALLED_PACKER_VERSION=$(packer --version | grep -Poie '\d+.\d+.\d+') | |
LATEST_PACKER_RELEASE=$(get_latest_github_release hashicorp packer) | |
# Download and install Packer if there is a version mismatch | |
if [[ ${LATEST_PACKER_RELEASE} != ${INSTALLED_PACKER_VERSION} ]]; then | |
echo "Installing Packer ${LATEST_PACKER_RELEASE}..." | |
wget https://releases.hashicorp.com/packer/${LATEST_PACKER_RELEASE}/packer_${LATEST_PACKER_RELEASE}_linux_amd64.zip | |
unzip -o packer_${LATEST_PACKER_RELEASE}_linux_amd64.zip | |
rm packer_${LATEST_PACKER_RELEASE}_linux_amd64.zip | |
sudo install packer ${INSTALL_DIR}/packer | |
rm -rf packer | |
else | |
echo "Nothing done. The Latest Packr version is already installed." | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment