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"
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

View file

@ -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