diff --git a/newt/config.yaml b/newt/config.yaml index e995546..d77c2f2 100644 --- a/newt/config.yaml +++ b/newt/config.yaml @@ -1,5 +1,5 @@ name: "Newt Add-on" -version: "1.0.7" # Incremented to force update +version: "1.0.8" slug: "newt" description: "Runs the Newt container inside Home Assistant using Supervisor API" arch: @@ -7,12 +7,10 @@ arch: - armv7 - armhf - aarch64 -startup: "system" -boot: "auto" +startup: system +boot: auto host_network: true -privileged: - - SYS_ADMIN - - NET_ADMIN +privileged: true options: PANGOLIN_ENDPOINT: "https://example.com" NEWT_ID: "your_newt_id" @@ -24,4 +22,4 @@ schema: hassio_api: true homeassistant_api: true auth_api: true -hassio_role: "admin" \ No newline at end of file +hassio_role: "admin" diff --git a/newt/run.sh b/newt/run.sh index 941507c..141f135 100644 --- a/newt/run.sh +++ b/newt/run.sh @@ -1,17 +1,22 @@ #!/usr/bin/env bash -set -e # Stop the script on errors +set -e # Stop script on errors echo "🔹 Starting Newt container using Home Assistant Supervisor API..." -echo "🔹 Checking Docker availability..." -if ! docker info >/dev/null 2>&1; then - echo "❌ ERROR: Docker is NOT available inside Home Assistant OS!" +# Check if Supervisor API is available +if ! curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" "http://supervisor/info"; then + echo "❌ ERROR: Home Assistant Supervisor API is not accessible!" exit 22 fi -echo "✅ Docker is available!" +echo "✅ Supervisor API is available!" -echo "🔹 Checking environment variables..." +# Set 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 " PANGOLIN_ENDPOINT=$PANGOLIN_ENDPOINT" echo " NEWT_ID=$NEWT_ID" echo " NEWT_SECRET=$NEWT_SECRET" @@ -23,23 +28,23 @@ curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" \ curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" \ -X POST "http://supervisor/docker/containers/newt/remove" || echo "❗ Warning: Could not remove container" -# Start a new Newt container -echo "🔹 Starting new Newt container..." +# Create and start a new Newt container using the Supervisor API +echo "🔹 Creating and starting new Newt container via Supervisor API..." curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" \ - -X POST "http://supervisor/docker/containers/create" \ + -X POST "http://supervisor/docker/containers/run" \ -H "Content-Type: application/json" \ -d '{ - "Image": "fosrl/newt", - "HostConfig": { - "RestartPolicy": {"Name": "unless-stopped"}, - "Env": [ - "PANGOLIN_ENDPOINT='"$PANGOLIN_ENDPOINT"'", - "NEWT_ID='"$NEWT_ID"'", - "NEWT_SECRET='"$NEWT_SECRET"'" - ] - }, - "Name": "newt" - }' || { echo "❌ ERROR: Failed to create Newt container"; exit 22; } + "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; } -echo "✅ Newt container should now be running!" -exec tail -f /dev/null # Keep container running +echo "✅ Newt container started successfully!" + +# Keep add-on running +exec tail -f /dev/null