From 827d6d9e10b68f7d549c6d293216615fb2d3cb50 Mon Sep 17 00:00:00 2001 From: Kroese Date: Tue, 7 Jul 2026 12:03:58 +0200 Subject: [PATCH] fix: Status monitor exited early (#1230) --- src/print.sh | 38 ++++++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 16 deletions(-) diff --git a/src/print.sh b/src/print.sh index 930e048..03621f5 100644 --- a/src/print.sh +++ b/src/print.sh @@ -27,11 +27,16 @@ curl_err="Failed to connect to guest: curl error" jq_err="Failed to parse response from guest: jq error" exitIfShuttingDown() { + [ -f "$shutdown" ] && exit 1 + + return 0 } queryGuest() { + local rc + { json=$(curl -m 20 -sk "$url"); rc=$?; } || : exitIfShuttingDown @@ -48,8 +53,9 @@ readJsonField() { local query="$1" local result + local rc - { result=$(echo "$json" | jq -r "$query"); rc=$?; } || : + { result=$(jq -r "$query" <<< "$json"); rc=$?; } || : if (( rc != 0 )); then error "$jq_err $rc ( $json )" @@ -62,14 +68,23 @@ readJsonField() { fi printf '%s\n' "$result" + return 0 } readGuestStatus() { + local result msg rc + result=$(readJsonField '.status') || return 1 if [[ "$result" != "success" ]]; then - { msg=$(echo "$json" | jq -r '.message'); rc=$?; } || : + { msg=$(jq -r '.message // empty' <<< "$json"); rc=$?; } || : + + if (( rc != 0 )); then + error "$jq_err $rc ( $json )" + return 1 + fi + error "Guest replied $result: $msg" return 1 fi @@ -87,26 +102,14 @@ readGuestPort() { readGuestIp() { - ip=$(readJsonField ' - first( - .data.data.ip.data[] | - select(.name=="eth0" and has("ip")) | - .ip | - select(test("^[0-9]+\\.")) - ) // first( - .data.data.ip.data[] | - select(has("ip")) | - .ip | - select(test("^[0-9]+\\.")) - ) - ') || return 1 - + ip=$(readJsonField '.data.data.ip.data[] | select(.name=="eth0" and has("ip")) | .ip | select(test("^[0-9]+\\."))') || return 1 [ -z "$ip" ] && return 1 return 0 } writeDsmLocation() { + echo "$ip:$port" > "$file" return 0 @@ -132,6 +135,8 @@ pollGuestLocation() { writeDsmLocation done + + return 0 } writeDhcpPage() { @@ -174,6 +179,7 @@ buildStaticMessage() { } printLoginMessage() { + echo "" >&2 info "-----------------------------------------------------------" info " You can now login to DSM at $msg"