Skip to content

Instantly share code, notes, and snippets.

@longavailable
Last active December 19, 2024 00:57
Show Gist options
  • Save longavailable/44af7d42ac76ac501fe7d7e832519084 to your computer and use it in GitHub Desktop.
Save longavailable/44af7d42ac76ac501fe7d7e832519084 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Get the output of ha su info
info_output=$(ha core 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/qemux86-64-homeassistant 2>/dev/null)
# Pull the latest Home Assistant Core image
if ! docker pull m.daocloud.io/ghcr.io/home-assistant/qemux86-64-homeassistant:$new_image_tag; then
echo "Error: Failed to pull the Core image. Exiting."
exit 1
fi
# Get the new image ID
new_image_id=$(docker images -q m.daocloud.io/ghcr.io/home-assistant/qemux86-64-homeassistant:$new_image_tag)
# Compare the image IDs
if [[ "$current_image_id" == "$new_image_id" ]]; then
echo "No new Core 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/qemux86-64-homeassistant:$new_image_tag ghcr.io/home-assistant/qemux86-64-homeassistant:$new_image_tag; then
echo "Warning: Failed to tag the Core image. Skipping update."
exit 0 # Exit with success code since no action is needed
fi
# Update Home Assistant core
if ! ha core update; then
echo "Error: Failed to update Home Assistant core. Exiting."
exit 1
fi
echo "Home Assistant core update initiated."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment