Add debug logs to run.sh - version 1.0.7

This commit is contained in:
Jørgen Ferdinand 2025-03-07 22:45:17 +01:00
parent e0c019e69b
commit b45f98f1e8
2 changed files with 26 additions and 29 deletions

View file

@ -1,5 +1,5 @@
name: "Newt Add-on" name: "Newt Add-on"
version: "1.0.6" # Incremented to force update version: "1.0.7" # Incremented to force update
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,33 +1,32 @@
#!/usr/bin/env bash #!/usr/bin/env bash
set -e set -e # Stop the script on errors
echo "Starting Newt container using Home Assistant Supervisor API..." echo "🔹 Starting Newt container using Home Assistant Supervisor API..."
echo "🔹 Checking Docker availability..."
# Load config from environment variables if ! docker info >/dev/null 2>&1; then
PANGOLIN_ENDPOINT=${PANGOLIN_ENDPOINT:-"https://example.com"} echo "❌ ERROR: Docker is NOT available inside Home Assistant OS!"
NEWT_ID=${NEWT_ID:-"default_id"} exit 22
NEWT_SECRET=${NEWT_SECRET:-"default_secret"}
# Define the Supervisor API endpoint
SUPERVISOR_API="http://supervisor/docker"
# Check if we have access to the Home Assistant Supervisor API
if ! curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" "${SUPERVISOR_API}/info"; then
echo "Supervisor API is not accessible. Ensure the add-on has access to the Supervisor API."
exit 1
fi fi
# Stop and remove any existing Newt container echo "✅ Docker is available!"
echo "Stopping and removing any existing Newt container..."
curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" \
-X POST "${SUPERVISOR_API}/containers/newt/stop" || true
curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" \
-X POST "${SUPERVISOR_API}/containers/newt/remove" || true
# Start a new Newt container using the Supervisor API echo "🔹 Checking environment variables..."
echo "Starting new Newt container..." echo " PANGOLIN_ENDPOINT=$PANGOLIN_ENDPOINT"
echo " NEWT_ID=$NEWT_ID"
echo " NEWT_SECRET=$NEWT_SECRET"
# Stop and remove any existing Newt container
echo "🔹 Stopping and removing any existing Newt container..."
curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" \ curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" \
-X POST "${SUPERVISOR_API}/containers/create" \ -X POST "http://supervisor/docker/containers/newt/stop" || echo "❗ Warning: Could not stop container"
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..."
curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" \
-X POST "http://supervisor/docker/containers/create" \
-H "Content-Type: application/json" \ -H "Content-Type: application/json" \
-d '{ -d '{
"Image": "fosrl/newt", "Image": "fosrl/newt",
@ -40,9 +39,7 @@ curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" \
] ]
}, },
"Name": "newt" "Name": "newt"
}' }' || { echo "❌ ERROR: Failed to create Newt container"; exit 22; }
echo "Newt container started successfully!" echo "✅ Newt container should now be running!"
exec tail -f /dev/null # Keep container running
# Keep the script running to prevent add-on from exiting
exec tail -f /dev/null