Created
November 18, 2021 20:09
-
-
Save apolloclark/be5cfab2fa4daf104d0c3fca92597446 to your computer and use it in GitHub Desktop.
Upgrade JQ (JSON Query)
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 -eux | |
# retrieve a link to the latest version of Terraform | |
JQ_VERSION_LATEST=$(curl -sSL https://github.com/stedolan/jq/releases \ | |
| grep -F '/releases/tag' | grep -v 'rc' | head -n1 | cut -d'"' -f2 | cut -d'/' -f6 | cut -d'-' -f2); | |
# get the currently installed version | |
JQ_VERSION_CURRENT=$(jq --version | cut -d'-' -f2); | |
# check if the latest version matches the currently installed version | |
if [ "$JQ_VERSION_LATEST" = "$JQ_VERSION_CURRENT" ]; then | |
echo "Already running the latest version == $JQ_VERSION_CURRENT" | |
exit 0; | |
fi | |
# generate the download URL | |
JQ_URL=$(echo 'https://github.com/stedolan/jq/releases/download/jq-'"${JQ_VERSION_LATEST}"'/jq-linux64') | |
echo $JQ_URL; | |
# get the file, install it | |
cd /tmp | |
wget -q "$JQ_URL" | |
mv ./jq-linux64 ~/bin/jq | |
chmod +x ~/bin/jq | |
jq --version | grep -F "jq-$JQ_VERSION_LATEST" | |
rm -rf /tmp/jq* |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment