fix: separate reachability check from version detection in get-lnbits-key.sh
Some checks failed
CI / Typecheck & Lint (pull_request) Failing after 1s
Some checks failed
CI / Typecheck & Lint (pull_request) Failing after 1s
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) <noreply@anthropic.com>
This commit is contained in:
@@ -67,9 +67,15 @@ print_export_template() {
|
|||||||
# ─── Step 1: Confirm LNbits is reachable ─────────────────────────────────────
|
# ─── Step 1: Confirm LNbits is reachable ─────────────────────────────────────
|
||||||
|
|
||||||
info "Checking LNbits at $LNBITS_LOCAL …"
|
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 "LNbits is not reachable at $LNBITS_LOCAL (is it running?)."
|
||||||
warn "Showing manual setup instructions — run this script again once LNbits is up."
|
warn "Showing manual setup instructions — run this script again once LNbits is up."
|
||||||
echo ""
|
echo ""
|
||||||
@@ -80,18 +86,30 @@ if [[ -z "$HEALTH_JSON" ]]; then
|
|||||||
exit 0
|
exit 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
ok "LNbits is reachable at $LNBITS_LOCAL"
|
||||||
|
|
||||||
# ─── Step 2: Detect LNbits version ───────────────────────────────────────────
|
# ─── 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=""
|
LNBITS_VERSION=""
|
||||||
if command -v python3 &>/dev/null; then
|
if [[ -n "$HEALTH_JSON" ]] && command -v python3 &>/dev/null; then
|
||||||
LNBITS_VERSION="$(echo "$HEALTH_JSON" \
|
LNBITS_VERSION="$(echo "$HEALTH_JSON" \
|
||||||
| python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('server_version',''))" \
|
| python3 -c "import sys,json; d=json.load(sys.stdin); print(d.get('server_version',''))" \
|
||||||
2>/dev/null || true)"
|
2>/dev/null || true)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [[ -z "$LNBITS_VERSION" ]]; then
|
if [[ -z "$LNBITS_VERSION" ]]; then
|
||||||
warn "Could not parse server_version from health endpoint — assuming modern LNbits (>= 0.12)."
|
if [[ -z "$HEALTH_JSON" ]]; then
|
||||||
LNBITS_VERSION="0.12.0"
|
# 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
|
fi
|
||||||
|
|
||||||
info "LNbits version: ${LNBITS_VERSION}"
|
info "LNbits version: ${LNBITS_VERSION}"
|
||||||
|
|||||||
Reference in New Issue
Block a user