Fix: Run Newt container directly in Home Assistant OS - v1.1.7

This commit is contained in:
Jørgen Ferdinand 2025-03-07 23:12:39 +01:00
parent 34ba54aa97
commit c4b7f4da90
2 changed files with 29 additions and 30 deletions

View file

@ -1,5 +1,5 @@
name: "Newt Add-on" name: "Newt Add-on"
version: "1.1.6" version: "1.1.7"
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:

View file

@ -1,41 +1,40 @@
#!/usr/bin/env bash #!/usr/bin/env bash
source /usr/lib/bashio/bashio.sh set -e # Stop the script on errors
set -e # Stop script on errors echo "🔹 Starting Newt container using Home Assistant OS..."
echo "🔹 Starting Newt container using Home Assistant Supervisor API..." # Check if Docker is available
if ! command -v docker &> /dev/null; then
# Load config from Home Assistant options echo "❌ ERROR: Docker is NOT available inside Home Assistant OS!"
PANGOLIN_ENDPOINT=${PANGOLIN_ENDPOINT:-"https://eample.com"}
NEWT_ID=${NEWT_ID:-"123456789"}
NEWT_SECRET=${NEWT_SECRET:-"waytolongsecret"}
if [[ -z "$PANGOLIN_ENDPOINT" || -z "$NEWT_ID" || -z "$NEWT_SECRET" ]]; then
echo "❌ ERROR: Missing configuration values!"
exit 1 exit 1
fi fi
echo "✅ Docker is available!"
echo "✅ Configuration Loaded:" # Retrieve environment variables
PANGOLIN_ENDPOINT=${PANGOLIN_ENDPOINT:-"https://dash.opland.net"}
NEWT_ID=${NEWT_ID:-"ru32vsg8ls5lx93"}
NEWT_SECRET=${NEWT_SECRET:-"5rbqgpc292989uk9kz52hmypoyz6u9jf7k670fqja8p4un8o"}
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"
# Use Home Assistant Supervisor API to run the Newt container # Remove old Newt container if it exists
echo "🔹 Creating and starting Newt container via Supervisor API..." if docker ps -a --format '{{.Names}}' | grep -q "newt"; then
curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" \ echo "🔹 Stopping and removing existing Newt container..."
-X POST "http://supervisor/docker/containers/run" \ docker stop newt
-H "Content-Type: application/json" \ docker rm newt
-d '{ fi
"name": "newt",
"image": "fosrl/newt", # Run the Newt container
"restart_policy": "unless-stopped", echo "🔹 Starting Newt container..."
"env": [ docker run -d --restart unless-stopped \
"PANGOLIN_ENDPOINT='"$PANGOLIN_ENDPOINT"'", --name newt \
"NEWT_ID='"$NEWT_ID"'", -e PANGOLIN_ENDPOINT="$PANGOLIN_ENDPOINT" \
"NEWT_SECRET='"$NEWT_SECRET"'" -e NEWT_ID="$NEWT_ID" \
] -e NEWT_SECRET="$NEWT_SECRET" \
}' || { echo "❌ ERROR: Failed to start Newt container via Supervisor API"; exit 22; } fosrl/newt || { echo "❌ ERROR: Failed to start Newt container"; exit 22; }
echo "✅ Newt container started successfully!" echo "✅ Newt container started successfully!"
exec tail -f /dev/null exec tail -f /dev/null # Keep the add-on running