From d560a276296c4f181fa106a1bbfde50de58b2fab Mon Sep 17 00:00:00 2001 From: Alexander Whitestone Date: Sun, 22 Mar 2026 21:04:38 -0400 Subject: [PATCH] fix: separate reachability check from version detection in get-lnbits-key.sh The script used /api/v1/health for both reachability testing and version detection. Since that endpoint only exists on LNbits 0.12+, old versions were incorrectly reported as "not reachable" instead of falling through to the legacy superuser API path. Now the script: - Tests reachability via GET / (works on all LNbits versions) - Uses /api/v1/health only for version detection - If health endpoint is absent, correctly assumes pre-0.12 (legacy path) - If health endpoint exists but lacks server_version, assumes 0.12+ Fixes #19 Co-Authored-By: Claude Opus 4.6 (1M context) --- scripts/bitcoin-ln-node/get-lnbits-key.sh | 28 +++++++++++++++++++---- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/scripts/bitcoin-ln-node/get-lnbits-key.sh b/scripts/bitcoin-ln-node/get-lnbits-key.sh index 60e2195..3bbccb1 100755 --- a/scripts/bitcoin-ln-node/get-lnbits-key.sh +++ b/scripts/bitcoin-ln-node/get-lnbits-key.sh @@ -67,9 +67,15 @@ print_export_template() { # ─── Step 1: Confirm LNbits is reachable ───────────────────────────────────── info "Checking LNbits at $LNBITS_LOCAL …" -HEALTH_JSON="$(curl -sf --max-time 6 "$LNBITS_LOCAL/api/v1/health" 2>/dev/null || true)" -if [[ -z "$HEALTH_JSON" ]]; then +# Use a plain GET to the root URL to test reachability (works on all versions). +# The health endpoint (/api/v1/health) only exists on 0.12+. +LNBITS_REACHABLE=false +if curl -sf --max-time 6 -o /dev/null "$LNBITS_LOCAL/" 2>/dev/null; then + LNBITS_REACHABLE=true +fi + +if [[ "$LNBITS_REACHABLE" != "true" ]]; then warn "LNbits is not reachable at $LNBITS_LOCAL (is it running?)." warn "Showing manual setup instructions — run this script again once LNbits is up." echo "" @@ -80,18 +86,30 @@ if [[ -z "$HEALTH_JSON" ]]; then exit 0 fi +ok "LNbits is reachable at $LNBITS_LOCAL" + # ─── Step 2: Detect LNbits version ─────────────────────────────────────────── +# Try the health endpoint (available on 0.12+) to get the server version. +HEALTH_JSON="$(curl -sf --max-time 6 "$LNBITS_LOCAL/api/v1/health" 2>/dev/null || true)" + LNBITS_VERSION="" -if command -v python3 &>/dev/null; then +if [[ -n "$HEALTH_JSON" ]] && command -v python3 &>/dev/null; then LNBITS_VERSION="$(echo "$HEALTH_JSON" \ | python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('server_version',''))" \ 2>/dev/null || true)" fi if [[ -z "$LNBITS_VERSION" ]]; then - warn "Could not parse server_version from health endpoint — assuming modern LNbits (>= 0.12)." - LNBITS_VERSION="0.12.0" + if [[ -z "$HEALTH_JSON" ]]; then + # Health endpoint not found — this is a pre-0.12 LNbits that lacks /api/v1/health. + warn "Health endpoint not available — assuming legacy LNbits (< 0.12)." + LNBITS_VERSION="0.11.0" + else + # Health endpoint responded but didn't include server_version. + warn "Could not parse server_version from health endpoint — assuming modern LNbits (>= 0.12)." + LNBITS_VERSION="0.12.0" + fi fi info "LNbits version: ${LNBITS_VERSION}"