Fix Docker access by using Supervisor API - v1.0.8
This commit is contained in:
parent
b45f98f1e8
commit
42bc50328f
2 changed files with 32 additions and 29 deletions
|
@ -1,5 +1,5 @@
|
||||||
name: "Newt Add-on"
|
name: "Newt Add-on"
|
||||||
version: "1.0.7" # Incremented to force update
|
version: "1.0.8"
|
||||||
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:
|
||||||
|
@ -7,12 +7,10 @@ arch:
|
||||||
- armv7
|
- armv7
|
||||||
- armhf
|
- armhf
|
||||||
- aarch64
|
- aarch64
|
||||||
startup: "system"
|
startup: system
|
||||||
boot: "auto"
|
boot: auto
|
||||||
host_network: true
|
host_network: true
|
||||||
privileged:
|
privileged: true
|
||||||
- SYS_ADMIN
|
|
||||||
- NET_ADMIN
|
|
||||||
options:
|
options:
|
||||||
PANGOLIN_ENDPOINT: "https://example.com"
|
PANGOLIN_ENDPOINT: "https://example.com"
|
||||||
NEWT_ID: "your_newt_id"
|
NEWT_ID: "your_newt_id"
|
||||||
|
@ -24,4 +22,4 @@ schema:
|
||||||
hassio_api: true
|
hassio_api: true
|
||||||
homeassistant_api: true
|
homeassistant_api: true
|
||||||
auth_api: true
|
auth_api: true
|
||||||
hassio_role: "admin"
|
hassio_role: "admin"
|
||||||
|
|
49
newt/run.sh
49
newt/run.sh
|
@ -1,17 +1,22 @@
|
||||||
#!/usr/bin/env bash
|
#!/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 "🔹 Starting Newt container using Home Assistant Supervisor API..."
|
||||||
echo "🔹 Checking Docker availability..."
|
|
||||||
|
|
||||||
if ! docker info >/dev/null 2>&1; then
|
# Check if Supervisor API is available
|
||||||
echo "❌ ERROR: Docker is NOT available inside Home Assistant OS!"
|
if ! curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" "http://supervisor/info"; then
|
||||||
|
echo "❌ ERROR: Home Assistant Supervisor API is not accessible!"
|
||||||
exit 22
|
exit 22
|
||||||
fi
|
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 " PANGOLIN_ENDPOINT=$PANGOLIN_ENDPOINT"
|
||||||
echo " NEWT_ID=$NEWT_ID"
|
echo " NEWT_ID=$NEWT_ID"
|
||||||
echo " NEWT_SECRET=$NEWT_SECRET"
|
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}" \
|
curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" \
|
||||||
-X POST "http://supervisor/docker/containers/newt/remove" || echo "❗ Warning: Could not remove container"
|
-X POST "http://supervisor/docker/containers/newt/remove" || echo "❗ Warning: Could not remove container"
|
||||||
|
|
||||||
# Start a new Newt container
|
# Create and start a new Newt container using the Supervisor API
|
||||||
echo "🔹 Starting new Newt container..."
|
echo "🔹 Creating and starting new Newt container via Supervisor API..."
|
||||||
curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" \
|
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" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{
|
-d '{
|
||||||
"Image": "fosrl/newt",
|
"name": "newt",
|
||||||
"HostConfig": {
|
"image": "fosrl/newt",
|
||||||
"RestartPolicy": {"Name": "unless-stopped"},
|
"restart_policy": "unless-stopped",
|
||||||
"Env": [
|
"env": [
|
||||||
"PANGOLIN_ENDPOINT='"$PANGOLIN_ENDPOINT"'",
|
"PANGOLIN_ENDPOINT='"$PANGOLIN_ENDPOINT"'",
|
||||||
"NEWT_ID='"$NEWT_ID"'",
|
"NEWT_ID='"$NEWT_ID"'",
|
||||||
"NEWT_SECRET='"$NEWT_SECRET"'"
|
"NEWT_SECRET='"$NEWT_SECRET"'"
|
||||||
]
|
]
|
||||||
},
|
}' || { echo "❌ ERROR: Failed to start Newt container via Supervisor API"; exit 22; }
|
||||||
"Name": "newt"
|
|
||||||
}' || { echo "❌ ERROR: Failed to create Newt container"; exit 22; }
|
|
||||||
|
|
||||||
echo "✅ Newt container should now be running!"
|
echo "✅ Newt container started successfully!"
|
||||||
exec tail -f /dev/null # Keep container running
|
|
||||||
|
# Keep add-on running
|
||||||
|
exec tail -f /dev/null
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue