1
0
mirror of https://github.com/home-assistant/operating-system.git synced 2025-12-20 02:18:37 +00:00

Rework /usr/sbin/hassos-supervisor script (#4248)

* Rework /usr/sbin/hassos-supervisor script:
- remove hardcoded url for image
- add get image url from updater.json/internet
- add SUPERVISOR_CHANNEL defaults to stable

Signed-off-by: Viacheslav Bocharov <adeep@lexina.in>

* Fix small catches in hassos-supervisor

Signed-off-by: Viacheslav Bocharov <adeep@lexina.in>

* Update buildroot-external/rootfs-overlay/usr/sbin/hassos-supervisor

Co-authored-by: Jan Čermák <sairon@users.noreply.github.com>

---------

Signed-off-by: Viacheslav Bocharov <adeep@lexina.in>
Co-authored-by: Jan Čermák <sairon@users.noreply.github.com>
This commit is contained in:
Viacheslav Bocharov
2025-08-25 19:00:18 +03:00
committed by GitHub
parent 62747cd622
commit 22fe9b19ee

View File

@@ -9,12 +9,14 @@ set -e
. /etc/os-release . /etc/os-release
# Init supervisor # Init supervisor
: "${SUPERVISOR_CHANNEL:=stable}" # allow env override; default to "stable"
URL_HASSIO_VERSION="https://version.home-assistant.io/${SUPERVISOR_CHANNEL}.json"
SUPERVISOR_DATA=/mnt/data/supervisor SUPERVISOR_DATA=/mnt/data/supervisor
SUPERVISOR_STARTUP_MARKER="/run/supervisor/startup-marker" SUPERVISOR_STARTUP_MARKER="/run/supervisor/startup-marker"
SUPERVISOR_STARTSCRIPT_VERSION="/mnt/data/.hassos-supervisor-version" SUPERVISOR_STARTSCRIPT_VERSION="/mnt/data/.hassos-supervisor-version"
SUPERVISOR_IMAGE="ghcr.io/home-assistant/${SUPERVISOR_ARCH}-hassio-supervisor" SUPERVISOR_IMAGE_BASE="${SUPERVISOR_ARCH}-hassio-supervisor"
SUPERVISOR_IMAGE_ID=$(docker images --no-trunc --filter "reference=${SUPERVISOR_IMAGE}:latest" --format "{{.ID}}" || echo "") SUPERVISOR_IMAGE_ID="$(docker images --no-trunc --format '{{.Repository}} {{.Tag}} {{.ID}}' | awk -v s="$SUPERVISOR_IMAGE_BASE" '($1==s || $1 ~ ("/" s "$")) && $2=="latest"{print $3; exit}' || echo "")"
SUPERVISOR_CONTAINER_ID=$(docker inspect --format='{{.Image}}' hassio_supervisor || echo "") SUPERVISOR_CONTAINER_ID=$(docker inspect --format='{{.Image}}' hassio_supervisor || echo "")
# Check if previous run left the startup-marker in place. If so, we assume the # Check if previous run left the startup-marker in place. If so, we assume the
@@ -26,7 +28,7 @@ if [ -f "${SUPERVISOR_STARTUP_MARKER}" ]; then
SUPERVISOR_CONTAINER_ID="" SUPERVISOR_CONTAINER_ID=""
# Make sure we delete all supervisor images # Make sure we delete all supervisor images
SUPERVISOR_IMAGE_IDS=$(docker images --no-trunc --filter "reference=${SUPERVISOR_IMAGE}" --format "{{.ID}}" | sort | uniq || echo "") SUPERVISOR_IMAGE_IDS="$(docker images --no-trunc --format '{{.Repository}} {{.ID}}' | awk -v s="$SUPERVISOR_IMAGE_BASE" '($1==s || $1 ~ ("/" s "$")){print $2}' | sort -u || echo "")"
# Intended splitting of SUPERVISOR_IMAGE_IDS # Intended splitting of SUPERVISOR_IMAGE_IDS
# Busybox sh doesn't support arrays # Busybox sh doesn't support arrays
# shellcheck disable=SC2086 # shellcheck disable=SC2086
@@ -37,29 +39,32 @@ fi
mkdir -p "$(dirname ${SUPERVISOR_STARTUP_MARKER})" mkdir -p "$(dirname ${SUPERVISOR_STARTUP_MARKER})"
touch ${SUPERVISOR_STARTUP_MARKER} touch ${SUPERVISOR_STARTUP_MARKER}
# Get the latest from update information
# Using updater information instead of config. If the config version is
# broken, this creates a way back (e.g., bad release).
SUPERVISOR_VERSION=$(jq -r --arg chan "$SUPERVISOR_CHANNEL" '.supervisor // $chan' "${SUPERVISOR_DATA}/updater.json" || echo "$SUPERVISOR_CHANNEL")
SUPERVISOR_IMAGE_TPL="$(jq -r '.image.supervisor // empty' "${SUPERVISOR_DATA}/updater.json" 2>/dev/null || true)"
# Get version from channel in case we have no local version
# information.
if [ -z "${SUPERVISOR_VERSION}" ] || [ "${SUPERVISOR_VERSION}" = "$SUPERVISOR_CHANNEL" ] || [ -z "${SUPERVISOR_IMAGE_TPL}" ]; then
json="$(curl -fsSL "${URL_HASSIO_VERSION}" || echo "{}")"
SUPERVISOR_VERSION="$(printf '%s' "$json" | jq -er '.supervisor')"
SUPERVISOR_IMAGE_TPL="$(printf '%s' "$json" | jq -er '.images.supervisor')"
fi
SUPERVISOR_IMAGE="$(printf '%s' "$SUPERVISOR_IMAGE_TPL" | sed "s|{arch}|${SUPERVISOR_ARCH}|g")"
# If Supervisor image is missing, pull it # If Supervisor image is missing, pull it
if [ -z "${SUPERVISOR_IMAGE_ID}" ]; then if [ -z "${SUPERVISOR_IMAGE_ID}" ]; then
# Get the latest from update information
# Using updater information instead of config. If the config version is
# broken, this creates a way back (e.g., bad release).
SUPERVISOR_VERSION=$(jq -r '.supervisor // "stable"' "${SUPERVISOR_DATA}/updater.json" || echo "stable")
# Get version from stable channel in case we have no local version
# information.
if [ "${SUPERVISOR_VERSION}" = "stable" ]; then
SUPERVISOR_VERSION="$(curl -s --location https://version.home-assistant.io/stable.json | jq -e -r '.supervisor')"
fi
echo "[WARNING] Supervisor image missing, downloading a fresh one: ${SUPERVISOR_VERSION}" echo "[WARNING] Supervisor image missing, downloading a fresh one: ${SUPERVISOR_VERSION}"
# Pull in the Supervisor # Pull in the Supervisor
if docker pull "${SUPERVISOR_IMAGE}:${SUPERVISOR_VERSION}"; then if docker pull "${SUPERVISOR_IMAGE}:${SUPERVISOR_VERSION}"; then
# Tag as latest # Tag as latest
docker tag "${SUPERVISOR_IMAGE}:${SUPERVISOR_VERSION}" "${SUPERVISOR_IMAGE}:latest" docker tag "${SUPERVISOR_IMAGE}:${SUPERVISOR_VERSION}" "${SUPERVISOR_IMAGE}:latest"
else else
# Pull failed, updater info might be corrupted or the release might have # Pull failed, updater info might be corrupted or the release might have
# been removed from the container registry, delete the updater info # been removed from the container registry, delete the updater info
# to start from scratch on next try. # to start from scratch on next try.
echo "[ERROR] Supervisor download failed." echo "[ERROR] Supervisor download failed."
rm -f "${SUPERVISOR_DATA}/updater.json" rm -f "${SUPERVISOR_DATA}/updater.json"
exit 1 exit 1