From c4b7f4da907015d8249240cf3f3ccbdf98b18163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=B8rgen=20Ferdinand?= Date: Fri, 7 Mar 2025 23:12:39 +0100 Subject: [PATCH] Fix: Run Newt container directly in Home Assistant OS - v1.1.7 --- newt/config.yaml | 2 +- newt/run.sh | 57 ++++++++++++++++++++++++------------------------ 2 files changed, 29 insertions(+), 30 deletions(-) diff --git a/newt/config.yaml b/newt/config.yaml index 694684a..fd71273 100644 --- a/newt/config.yaml +++ b/newt/config.yaml @@ -1,5 +1,5 @@ name: "Newt Add-on" -version: "1.1.6" +version: "1.1.7" slug: "newt" description: "Runs the Newt container inside Home Assistant using Supervisor API" arch: diff --git a/newt/run.sh b/newt/run.sh index d2c1a88..5325151 100644 --- a/newt/run.sh +++ b/newt/run.sh @@ -1,41 +1,40 @@ #!/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..." - -# Load config from Home Assistant options -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!" +# Check if Docker is available +if ! command -v docker &> /dev/null; then + echo "❌ ERROR: Docker is NOT available inside Home Assistant OS!" exit 1 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 " NEWT_ID=$NEWT_ID" echo " NEWT_SECRET=$NEWT_SECRET" -# Use Home Assistant Supervisor API to run the Newt container -echo "🔹 Creating and starting Newt container via Supervisor API..." -curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" \ - -X POST "http://supervisor/docker/containers/run" \ - -H "Content-Type: application/json" \ - -d '{ - "name": "newt", - "image": "fosrl/newt", - "restart_policy": "unless-stopped", - "env": [ - "PANGOLIN_ENDPOINT='"$PANGOLIN_ENDPOINT"'", - "NEWT_ID='"$NEWT_ID"'", - "NEWT_SECRET='"$NEWT_SECRET"'" - ] - }' || { echo "❌ ERROR: Failed to start Newt container via Supervisor API"; exit 22; } +# Remove old Newt container if it exists +if docker ps -a --format '{{.Names}}' | grep -q "newt"; then + echo "🔹 Stopping and removing existing Newt container..." + docker stop newt + docker rm newt +fi + +# Run the Newt container +echo "🔹 Starting 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 || { echo "❌ ERROR: Failed to start Newt container"; exit 22; } echo "✅ Newt container started successfully!" -exec tail -f /dev/null +exec tail -f /dev/null # Keep the add-on running