Skip to content

Instantly share code, notes, and snippets.

@apolloclark
Created November 18, 2021 20:09
Show Gist options
  • Save apolloclark/be5cfab2fa4daf104d0c3fca92597446 to your computer and use it in GitHub Desktop.
Save apolloclark/be5cfab2fa4daf104d0c3fca92597446 to your computer and use it in GitHub Desktop.
Upgrade JQ (JSON Query)
#!/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