Fix Docker access by using Supervisor API - version 1.0.5
This commit is contained in:
parent
de355f1ced
commit
cdf4287818
2 changed files with 37 additions and 27 deletions
|
@ -1,7 +1,7 @@
|
|||
name: "Newt Add-on"
|
||||
version: "1.0.4"
|
||||
version: "1.0.5"
|
||||
slug: "newt"
|
||||
description: "Runs the Newt container inside Home Assistant"
|
||||
description: "Runs the Newt container inside Home Assistant using Supervisor API"
|
||||
arch:
|
||||
- amd64
|
||||
- armv7
|
||||
|
@ -10,10 +10,7 @@ arch:
|
|||
startup: system
|
||||
boot: auto
|
||||
host_network: true
|
||||
privileged:
|
||||
- SYS_ADMIN
|
||||
- NET_ADMIN
|
||||
- DAC_READ_SEARCH
|
||||
privileged: true
|
||||
options:
|
||||
PANGOLIN_ENDPOINT: "https://example.com"
|
||||
NEWT_ID: "your_newt_id"
|
||||
|
@ -22,7 +19,6 @@ schema:
|
|||
PANGOLIN_ENDPOINT: "str?"
|
||||
NEWT_ID: "str?"
|
||||
NEWT_SECRET: "str?"
|
||||
environment:
|
||||
PANGOLIN_ENDPOINT: "$PANGOLIN_ENDPOINT"
|
||||
NEWT_ID: "$NEWT_ID"
|
||||
NEWT_SECRET: "$NEWT_SECRET"
|
||||
homeassistant: true
|
||||
hassio_api: true
|
||||
hassio_role: "admin"
|
48
newt/run.sh
48
newt/run.sh
|
@ -1,34 +1,48 @@
|
|||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
echo "Starting Newt container..."
|
||||
echo "Starting Newt container using Home Assistant Supervisor API..."
|
||||
|
||||
# Load config from environment variables
|
||||
PANGOLIN_ENDPOINT=${PANGOLIN_ENDPOINT:-"https://example.com"}
|
||||
NEWT_ID=${NEWT_ID:-"default_id"}
|
||||
NEWT_SECRET=${NEWT_SECRET:-"default_secret"}
|
||||
|
||||
# Check if Docker is available
|
||||
if ! docker info >/dev/null 2>&1; then
|
||||
echo "Docker is not available inside Home Assistant OS!"
|
||||
# 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
|
||||
|
||||
# Stop and remove any existing Newt container
|
||||
if docker ps -a --format '{{.Names}}' | grep -q "newt"; then
|
||||
docker stop newt
|
||||
docker rm newt
|
||||
fi
|
||||
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
|
||||
|
||||
# Run 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
|
||||
# Start a new Newt container using the Supervisor API
|
||||
echo "Starting new Newt container..."
|
||||
curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" \
|
||||
-X POST "${SUPERVISOR_API}/containers/create" \
|
||||
-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 "Newt container is running!"
|
||||
echo "Newt container started successfully!"
|
||||
|
||||
# Keep the script running
|
||||
# Keep the script running to prevent add-on from exiting
|
||||
exec tail -f /dev/null
|
Loading…
Add table
Add a link
Reference in a new issue