Ensure configuration is loaded properly in run.sh - v1.1.0

This commit is contained in:
Jørgen Ferdinand 2025-03-07 22:58:28 +01:00
parent 8dc24ed333
commit 427ca7abdc
2 changed files with 24 additions and 36 deletions

View file

@ -1,5 +1,5 @@
name: "Newt Add-on" name: "Newt Add-on"
version: "1.0.9" version: "1.1.0"
slug: "newt" slug: "newt"
description: "Runs the Newt container inside Home Assistant using Supervisor API" description: "Runs the Newt container inside Home Assistant using Supervisor API"
arch: arch:
@ -16,12 +16,12 @@ privileged:
- DAC_READ_SEARCH - DAC_READ_SEARCH
options: options:
PANGOLIN_ENDPOINT: "https://example.com" PANGOLIN_ENDPOINT: "https://example.com"
NEWT_ID: "your_newt_id" NEWT_ID: ""
NEWT_SECRET: "your_newt_secret" NEWT_SECRET: ""
schema: schema:
PANGOLIN_ENDPOINT: "str?" PANGOLIN_ENDPOINT: "str"
NEWT_ID: "str?" NEWT_ID: "str"
NEWT_SECRET: "str?" NEWT_SECRET: "str"
hassio_api: true hassio_api: true
homeassistant_api: true homeassistant_api: true
auth_api: true auth_api: true

View file

@ -3,40 +3,28 @@ set -e # Stop script on errors
echo "🔹 Starting Newt container using Home Assistant Supervisor API..." echo "🔹 Starting Newt container using Home Assistant Supervisor API..."
# Ensure the Supervisor API is accessible # Load config from Home Assistant options
if ! curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" "http://supervisor/info"; then PANGOLIN_ENDPOINT=$(bashio::config 'PANGOLIN_ENDPOINT')
echo "❌ ERROR: Home Assistant Supervisor API is not accessible!" NEWT_ID=$(bashio::config 'NEWT_ID')
exit 22 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 fi
echo "✅ Supervisor API is available!"
# Retrieve and display add-on environment variables echo "✅ Configuration Loaded:"
PANGOLIN_ENDPOINT=${PANGOLIN_ENDPOINT:-"https://example.com"}
NEWT_ID=${NEWT_ID:-"default_id"}
NEWT_SECRET=${NEWT_SECRET:-"default_secret"}
echo "🔹 Environment Variables:"
echo " PANGOLIN_ENDPOINT=$PANGOLIN_ENDPOINT" echo " PANGOLIN_ENDPOINT=$PANGOLIN_ENDPOINT"
echo " NEWT_ID=$NEWT_ID" echo " NEWT_ID=$NEWT_ID"
echo " NEWT_SECRET=$NEWT_SECRET" echo " NEWT_SECRET=$NEWT_SECRET"
# Send the environment variables to Home Assistant # Run Newt container
echo "🔹 Setting environment variables for the add-on..." docker run -d --restart unless-stopped \
curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" \ --name newt \
-X POST "http://supervisor/addons/self/options" \ -e PANGOLIN_ENDPOINT="$PANGOLIN_ENDPOINT" \
-H "Content-Type: application/json" \ -e NEWT_ID="$NEWT_ID" \
-d '{ -e NEWT_SECRET="$NEWT_SECRET" \
"options": { fosrl/newt
"PANGOLIN_ENDPOINT": "'"$PANGOLIN_ENDPOINT"'",
"NEWT_ID": "'"$NEWT_ID"'",
"NEWT_SECRET": "'"$NEWT_SECRET"'"
}
}' || { echo "❌ ERROR: Failed to set environment variables"; exit 22; }
# Start the add-on echo "✅ Newt container started successfully!"
echo "🔹 Starting the add-on..." exec tail -f /dev/null
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