Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Select an option

  • Save longavailable/40df661bb53da392e5bd136fdc0481f9 to your computer and use it in GitHub Desktop.

Select an option

Save longavailable/40df661bb53da392e5bd136fdc0481f9 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Get the output of ha su info
info_output=$(ha su info)
# Parse the output and extract values
update_available=$(echo "$info_output" | grep -Eo 'update_available: (true|false)')
version_latest=$(echo "$info_output" | grep -Eo 'version_latest: .*' | cut -d ' ' -f2)
# Check if update is available
if [[ "$update_available" == "update_available: true" ]]; then
# Set the image tag to version_latest
new_image_tag="$version_latest"
echo "Update available! New image tag: $new_image_tag"
else
echo "No update available."
exit 0 # Exit with success code (no update needed)
fi
# Get the current image ID
current_image_id=$(docker images -q ghcr.io/home-assistant/amd64-hassio-supervisor:latest 2>/dev/null)
# Pull the latest Home Assistant Supervisor image
if ! docker pull m.daocloud.io/ghcr.io/home-assistant/amd64-hassio-supervisor:$new_image_tag; then
echo "Error: Failed to pull the Supervisor image. Exiting."
exit 1
fi
# Get the new image ID
new_image_id=$(docker images -q m.daocloud.io/ghcr.io/home-assistant/amd64-hassio-supervisor:$new_image_tag)
# Compare the image IDs
if [[ "$current_image_id" == "$new_image_id" ]]; then
echo "No new Supervisor image found. Skipping update."
exit 0 # Exit with success code since no action is needed
fi
# Tag the pulled image (only if a new image was pulled)
if ! docker tag m.daocloud.io/ghcr.io/home-assistant/amd64-hassio-supervisor:$new_image_tag ghcr.io/home-assistant/amd64-hassio-supervisor:$new_image_tag; then
echo "Warning: Failed to tag the Supervisor image. Skipping update."
exit 0 # Exit with success code since no action is needed
fi
# Update Home Assistant Supervisor
if ! ha su update; then
echo "Error: Failed to update Home Assistant Supervisor. Exiting."
exit 1
fi
echo "Home Assistant Supervisor update initiated."
@longavailable
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment