Fix Supervisor API requests and correct privileged field - version 1.0.9
This commit is contained in:
parent
e9db09a459
commit
8dc24ed333
2 changed files with 20 additions and 27 deletions
|
@ -1,5 +1,5 @@
|
||||||
name: "Newt Add-on"
|
name: "Newt Add-on"
|
||||||
version: "1.0.8"
|
version: "1.0.9"
|
||||||
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:
|
||||||
|
@ -13,6 +13,7 @@ host_network: true
|
||||||
privileged:
|
privileged:
|
||||||
- SYS_ADMIN
|
- SYS_ADMIN
|
||||||
- NET_ADMIN
|
- NET_ADMIN
|
||||||
|
- DAC_READ_SEARCH
|
||||||
options:
|
options:
|
||||||
PANGOLIN_ENDPOINT: "https://example.com"
|
PANGOLIN_ENDPOINT: "https://example.com"
|
||||||
NEWT_ID: "your_newt_id"
|
NEWT_ID: "your_newt_id"
|
||||||
|
|
42
newt/run.sh
42
newt/run.sh
|
@ -3,15 +3,14 @@ set -e # Stop script on errors
|
||||||
|
|
||||||
echo "🔹 Starting Newt container using Home Assistant Supervisor API..."
|
echo "🔹 Starting Newt container using Home Assistant Supervisor API..."
|
||||||
|
|
||||||
# Check if Supervisor API is available
|
# Ensure the Supervisor API is accessible
|
||||||
if ! curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" "http://supervisor/info"; then
|
if ! curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" "http://supervisor/info"; then
|
||||||
echo "❌ ERROR: Home Assistant Supervisor API is not accessible!"
|
echo "❌ ERROR: Home Assistant Supervisor API is not accessible!"
|
||||||
exit 22
|
exit 22
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "✅ Supervisor API is available!"
|
echo "✅ Supervisor API is available!"
|
||||||
|
|
||||||
# Set environment variables
|
# Retrieve and display add-on environment variables
|
||||||
PANGOLIN_ENDPOINT=${PANGOLIN_ENDPOINT:-"https://example.com"}
|
PANGOLIN_ENDPOINT=${PANGOLIN_ENDPOINT:-"https://example.com"}
|
||||||
NEWT_ID=${NEWT_ID:-"default_id"}
|
NEWT_ID=${NEWT_ID:-"default_id"}
|
||||||
NEWT_SECRET=${NEWT_SECRET:-"default_secret"}
|
NEWT_SECRET=${NEWT_SECRET:-"default_secret"}
|
||||||
|
@ -21,30 +20,23 @@ 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"
|
||||||
|
|
||||||
# Stop and remove any existing Newt container
|
# Send the environment variables to Home Assistant
|
||||||
echo "🔹 Stopping and removing any existing Newt container..."
|
echo "🔹 Setting environment variables for the add-on..."
|
||||||
curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" \
|
curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" \
|
||||||
-X POST "http://supervisor/docker/containers/newt/stop" || echo "❗ Warning: Could not stop container"
|
-X POST "http://supervisor/addons/self/options" \
|
||||||
curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" \
|
|
||||||
-X POST "http://supervisor/docker/containers/newt/remove" || echo "❗ Warning: Could not remove 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/run" \
|
|
||||||
-H "Content-Type: application/json" \
|
-H "Content-Type: application/json" \
|
||||||
-d '{
|
-d '{
|
||||||
"name": "newt",
|
"options": {
|
||||||
"image": "fosrl/newt",
|
"PANGOLIN_ENDPOINT": "'"$PANGOLIN_ENDPOINT"'",
|
||||||
"restart_policy": "unless-stopped",
|
"NEWT_ID": "'"$NEWT_ID"'",
|
||||||
"env": [
|
"NEWT_SECRET": "'"$NEWT_SECRET"'"
|
||||||
"PANGOLIN_ENDPOINT='"$PANGOLIN_ENDPOINT"'",
|
}
|
||||||
"NEWT_ID='"$NEWT_ID"'",
|
}' || { echo "❌ ERROR: Failed to set environment variables"; exit 22; }
|
||||||
"NEWT_SECRET='"$NEWT_SECRET"'"
|
|
||||||
]
|
|
||||||
}' || { echo "❌ ERROR: Failed to start Newt container via Supervisor API"; exit 22; }
|
|
||||||
|
|
||||||
echo "✅ Newt container started successfully!"
|
# Start the add-on
|
||||||
|
echo "🔹 Starting the add-on..."
|
||||||
|
curl --silent --fail --header "Authorization: Bearer ${SUPERVISOR_TOKEN}" \
|
||||||
|
-X POST "http://supervisor/addons/self/start" || { echo "❌ ERROR: Failed to start add-on"; exit 22; }
|
||||||
|
|
||||||
# Keep add-on running
|
echo "✅ Newt add-on started successfully!"
|
||||||
exec tail -f /dev/null
|
exec tail -f /dev/null # Keep the add-on running
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue