From 427ca7abdce20be30ab41fbe394766f85a6268e7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Ferdinand?= Date: Fri, 7 Mar 2025 22:58:28 +0100 Subject: [PATCH] Ensure configuration is loaded properly in run.sh - v1.1.0 --- newt/config.yaml | 12 ++++++------ newt/run.sh | 48 ++++++++++++++++++------------------------------ 2 files changed, 24 insertions(+), 36 deletions(-) diff --git a/newt/config.yaml b/newt/config.yaml index 9eb07b4..38b30b0 100644 --- a/newt/config.yaml +++ b/newt/config.yaml @@ -1,5 +1,5 @@ name: "Newt Add-on" -version: "1.0.9" +version: "1.1.0" slug: "newt" description: "Runs the Newt container inside Home Assistant using Supervisor API" arch: @@ -16,12 +16,12 @@ privileged: - DAC_READ_SEARCH options: PANGOLIN_ENDPOINT: "https://example.com" - NEWT_ID: "your_newt_id" - NEWT_SECRET: "your_newt_secret" + NEWT_ID: "" + NEWT_SECRET: "" schema: - PANGOLIN_ENDPOINT: "str?" - NEWT_ID: "str?" - NEWT_SECRET: "str?" + PANGOLIN_ENDPOINT: "str" + NEWT_ID: "str" + NEWT_SECRET: "str" hassio_api: true homeassistant_api: true auth_api: true diff --git a/newt/run.sh b/newt/run.sh index f75ed98..29ef782 100644 --- a/newt/run.sh +++ b/newt/run.sh @@ -3,40 +3,28 @@ set -e # Stop script on errors echo "🔹 Starting Newt container using Home Assistant Supervisor API..." -# Ensure the Supervisor API is accessible -if ! curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" "http://supervisor/info"; then - echo "❌ ERROR: Home Assistant Supervisor API is not accessible!" - exit 22 +# Load config from Home Assistant options +PANGOLIN_ENDPOINT=$(bashio::config 'PANGOLIN_ENDPOINT') +NEWT_ID=$(bashio::config 'NEWT_ID') +NEWT_SECRET=$(bashio::config 'NEWT_SECRET') + +if [[ -z "$PANGOLIN_ENDPOINT" || -z "$NEWT_ID" || -z "$NEWT_SECRET" ]]; then + echo "❌ ERROR: Missing configuration values!" + exit 1 fi -echo "✅ Supervisor API is available!" -# Retrieve and display add-on environment variables -PANGOLIN_ENDPOINT=${PANGOLIN_ENDPOINT:-"https://example.com"} -NEWT_ID=${NEWT_ID:-"default_id"} -NEWT_SECRET=${NEWT_SECRET:-"default_secret"} - -echo "🔹 Environment Variables:" +echo "✅ Configuration Loaded:" echo " PANGOLIN_ENDPOINT=$PANGOLIN_ENDPOINT" echo " NEWT_ID=$NEWT_ID" echo " NEWT_SECRET=$NEWT_SECRET" -# Send the environment variables to Home Assistant -echo "🔹 Setting environment variables for the add-on..." -curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" \ - -X POST "http://supervisor/addons/self/options" \ - -H "Content-Type: application/json" \ - -d '{ - "options": { - "PANGOLIN_ENDPOINT": "'"$PANGOLIN_ENDPOINT"'", - "NEWT_ID": "'"$NEWT_ID"'", - "NEWT_SECRET": "'"$NEWT_SECRET"'" - } - }' || { echo "❌ ERROR: Failed to set environment variables"; exit 22; } +# Run Newt container +docker run -d --restart unless-stopped \ + --name newt \ + -e PANGOLIN_ENDPOINT="$PANGOLIN_ENDPOINT" \ + -e NEWT_ID="$NEWT_ID" \ + -e NEWT_SECRET="$NEWT_SECRET" \ + fosrl/newt -# Start the add-on -echo "🔹 Starting the add-on..." -curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" \ - -X POST "http://supervisor/addons/self/start" || { echo "❌ ERROR: Failed to start add-on"; exit 22; } - -echo "✅ Newt add-on started successfully!" -exec tail -f /dev/null # Keep the add-on running +echo "✅ Newt container started successfully!" +exec tail -f /dev/null