Skip to content

Commit 8ee2aff

Browse files
committed
Switching all configurations to happen via Codex Agents and n8n.
Refactor HAUpdate.sh to use 'docker compose' syntax for improved compatibility and readability. Added error handling with 'set -euo pipefail' and removed unused resource cleanup commands.
1 parent c62e778 commit 8ee2aff

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

config/shell_scripts/HAUpdate.sh

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,46 @@
11
# - This script is used to update the Home Assistant Docker containers
22
# - It will pull the latest images, check if the image ID has changed, and restart the container if needed
3-
# - It will also cleanup unused resources after the update
43

54
# Original Repo: https://github.com/CCOSTAN/Home-AssistantConfig
65
# Follow me on https://www.vcloudinfo.com/click-here
76

87
#!/bin/bash
98

9+
set -euo pipefail
10+
1011
# Update system packages
1112
sudo apt-get update && sudo apt-get upgrade -y
1213

14+
DC=(docker compose)
15+
1316
# Pull the latest images
14-
docker-compose pull
17+
"${DC[@]}" pull
1518

1619
# Get list of services from docker-compose.yml
17-
EXISTING_SERVICES=$(docker-compose config --services)
20+
EXISTING_SERVICES=$("${DC[@]}" config --services)
1821

1922
# Get list of running service containers
20-
RUNNING_CONTAINERS=$(docker-compose ps --services)
23+
RUNNING_CONTAINERS=$("${DC[@]}" ps --services)
2124

2225
# Loop through each running service and check if its image has changed
2326
for service in $RUNNING_CONTAINERS; do
2427
if echo "$EXISTING_SERVICES" | grep -qw "$service"; then
2528
# Get the current running image ID (remove sha256: prefix)
2629
CURRENT_IMAGE_ID=$(docker inspect --format='{{.Image}}' "$service" 2>/dev/null | sed 's/^sha256://')
2730

28-
# Get the latest image ID from docker-compose
29-
LATEST_IMAGE_ID=$(docker-compose images -q "$service" 2>/dev/null)
31+
# Get the latest image ID from docker compose
32+
LATEST_IMAGE_ID=$("${DC[@]}" images -q "$service" 2>/dev/null)
3033

3134
# If the image ID is different, restart the container
3235
if [ "$CURRENT_IMAGE_ID" != "$LATEST_IMAGE_ID" ] && [ -n "$LATEST_IMAGE_ID" ]; then
3336
echo "Updating container: $service"
34-
docker-compose stop "$service"
35-
docker-compose rm -f "$service"
36-
docker-compose up -d "$service"
37+
"${DC[@]}" stop "$service"
38+
"${DC[@]}" rm -f "$service"
39+
"${DC[@]}" up -d "$service"
3740
else
3841
echo "No update needed for: $service"
3942
fi
4043
else
4144
echo "Skipping non-existent service: $service"
4245
fi
4346
done
44-
45-
# Cleanup unused resources
46-
docker container prune -f
47-
docker image prune -f
48-
docker volume prune -f

0 commit comments

Comments
 (0)