From 33dbe1e184aeee249c49e279f36affc67dc12c75 Mon Sep 17 00:00:00 2001 From: rajat404 <404rajat@gmail.com> Date: Sat, 28 Nov 2020 14:10:41 +0530 Subject: [PATCH] Use jq in installation script if it exists on the machine --- scripts/rawinstall.sh | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/rawinstall.sh b/scripts/rawinstall.sh index b1edc84..2aaf34e 100755 --- a/scripts/rawinstall.sh +++ b/scripts/rawinstall.sh @@ -15,9 +15,14 @@ if [ "${1-}" = "--test" ] || [ "${1-}" = "-t" ]; then else echo "Looking for the latest release ..." # latest release - json=$(curl --silent "https://api.github.com/repos/curusarn/resh/releases/latest") - # not very robust but we don't want any dependencies to parse to JSON - tag=$(echo "$json" | grep '"tag_name":' | cut -d':' -f2 | tr -d ',' | cut -d'"' -f2) + if which jq >/dev/null; then + # Use `jq` if it exists on the system + tag=$(curl "https://api.github.com/repos/curusarn/resh/releases/latest" | jq .tag_name | tr -d '"' | tr -d "'") + else + json=$(curl --silent "https://api.github.com/repos/curusarn/resh/releases/latest") + # not very robust but we don't want any dependencies to parse to JSON + tag=$(echo "$json" | grep '"tag_name":' | cut -d':' -f2 | tr -d ',' | cut -d'"' -f2) + fi fi if [ ${#tag} -lt 2 ]; then