Created
February 4, 2019 21:36
-
-
Save bitmvr/a7d6a2891d572d88b4eec4d109485b6e to your computer and use it in GitHub Desktop.
A script to temporarily install jq for use in Bash scripting
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
| #!/usr/bin/env bash | |
| getjq::prep(){ | |
| TEMP_DIR="$(mktemp -d jq-download.XXXXXXXXXX)" | |
| cd $TEMP_DIR | |
| if [ $? -ne 0 ]; then | |
| echo "$0: Cannot change directory to $TEMP_DIR, exiting..." | |
| exit 1 | |
| fi | |
| } | |
| getjq::makeExecutable(){ | |
| chmod +x doctor-jq | |
| } | |
| getjq::projectRoot(){ | |
| cd - > /dev/null | |
| } | |
| getjq::download(){ | |
| # NEED TO DO -- DYNAMICALLY GET URL BASED ON OS | |
| jqURL="https://github.com/stedolan/jq/releases/download/jq-1.6/jq-osx-amd64" | |
| curl -sL -o doctor-jq "$jqURL" | |
| } | |
| getjq::install(){ | |
| getjq::prep | |
| getjq::download | |
| getjq::makeExecutable | |
| getjq::projectRoot | |
| } | |
| getjq::cleanup() { | |
| rm -rf jq-download.* | |
| } | |
| getjq::version(){ | |
| ./"$TEMP_DIR"/doctor-jq --version | |
| } | |
| getjq::init(){ | |
| getjq::cleanup | |
| getjq::install | |
| getjq::version | |
| getjq::cleanup | |
| } | |
| getjq::init |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment