From 7d0e8ba7bbce78519785c477ea3782c6691cf59f Mon Sep 17 00:00:00 2001 From: Grant Labutis <46079274+glabutis@users.noreply.github.com> Date: Mon, 16 Mar 2026 18:55:09 -0400 Subject: [PATCH] fix: exit 1 on missing install, robust JSON parsing via python3 --- ct/companion.sh | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) diff --git a/ct/companion.sh b/ct/companion.sh index f0c03115..6e0cbf88 100644 --- a/ct/companion.sh +++ b/ct/companion.sh @@ -34,19 +34,32 @@ function update_script() { if [[ ! -f /opt/companion/companion_headless.sh ]]; then msg_error "No ${APP} Installation Found!" - exit + exit 1 fi RELEASE_JSON=$(curl -fsSL "https://api.bitfocus.io/v1/product/companion/packages?limit=20") - RELEASE=$(echo "$RELEASE_JSON" | grep -o '"version":"[^"]*","target":"linux-tgz"' | head -1 | awk -F'"' '{print $4}') + RELEASE=$(echo "$RELEASE_JSON" | python3 -c " +import sys, json +data = json.load(sys.stdin) +for pkg in data.get('packages', data if isinstance(data, list) else []): + if pkg.get('target') == 'linux-tgz': + print(pkg.get('version', '')) + break +") + ASSET_URL=$(echo "$RELEASE_JSON" | python3 -c " +import sys, json +data = json.load(sys.stdin) +for pkg in data.get('packages', data if isinstance(data, list) else []): + if pkg.get('target') == 'linux-tgz': + print(pkg.get('uri', '')) + break +") if [[ "${RELEASE}" == "$(cat /opt/companion_version.txt 2>/dev/null)" ]]; then msg_ok "No update required. ${APP} is already at v${RELEASE}" exit fi - ASSET_URL=$(echo "$RELEASE_JSON" | grep -o '"uri":"[^"]*linux-x64[^"]*"' | head -1 | awk -F'"' '{print $4}') - msg_info "Stopping ${APP}" systemctl stop companion msg_ok "Stopped ${APP}"