From be1329ae05be8c3b837d4fe42e3a9a84036d20b5 Mon Sep 17 00:00:00 2001 From: Colin Seymour Date: Sun, 14 Jun 2026 15:21:52 +0000 Subject: [PATCH] Better handle onboarded instance --- .devcontainer/setup-ha.sh | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/.devcontainer/setup-ha.sh b/.devcontainer/setup-ha.sh index 5962db1..c8ea38d 100755 --- a/.devcontainer/setup-ha.sh +++ b/.devcontainer/setup-ha.sh @@ -144,8 +144,12 @@ wait_for_ha() { log "Waiting for Home Assistant to be ready..." local max_attempts=60 local attempt=0 + local http_code while [ "$attempt" -lt "$max_attempts" ]; do - if curl -sf "${HA_URL}/api/onboarding" > /dev/null 2>&1; then + # 200 = onboarding pending, 404 = already onboarded; both mean HA's HTTP + # server is up and serving. A connection failure yields 000. + http_code=$(curl -s -o /dev/null -w "%{http_code}" "${HA_URL}/api/onboarding" 2>/dev/null || true) + if [ "$http_code" = "200" ] || [ "$http_code" = "404" ]; then ok "Home Assistant is ready" return 0 fi @@ -160,8 +164,18 @@ wait_for_ha() { complete_onboarding() { log "Checking onboarding status..." - local onboarding - onboarding=$(curl -sf "${HA_URL}/api/onboarding") + # Capture the body and HTTP status separately. A configured instance returns + # 404 here because the onboarding endpoints are removed once onboarding + # completes, so don't use curl -f (which would abort under set -e). + local onboarding http_code + onboarding=$(curl -s -w $'\n%{http_code}' "${HA_URL}/api/onboarding") + http_code=$(printf '%s' "$onboarding" | tail -n1) + onboarding=$(printf '%s' "$onboarding" | sed '$d') + + if [ "$http_code" = "404" ]; then + ok "Onboarding already completed (endpoint returned 404)" + return 0 + fi local user_done user_done=$(echo "$onboarding" | jq -r '.[] | select(.step == "user") | .done')