-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathledbox-sync.sh
More file actions
executable file
·41 lines (34 loc) · 1.12 KB
/
ledbox-sync.sh
File metadata and controls
executable file
·41 lines (34 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/bin/bash
# Auto-sync LEDBox repo from GitHub and restart service if changed
REPO_DIR="/home/pi/LEDBox"
BRANCH="main"
SERVICE="ledbox.service"
SYSTEMD_DIR="/etc/systemd/system"
cd "$REPO_DIR" || exit 1
# Fetch latest
git fetch origin "$BRANCH" 2>/dev/null || exit 1
# Check if there are new changes
LOCAL=$(git rev-parse HEAD)
REMOTE=$(git rev-parse "origin/$BRANCH")
if [ "$LOCAL" != "$REMOTE" ]; then
echo "[$(date)] Updating from $LOCAL to $REMOTE"
git reset --hard "origin/$BRANCH"
# Install systemd units if they changed
RELOAD_NEEDED=false
for unit in ledbox.service ledbox-sync.service ledbox-sync.timer; do
if [ -f "$REPO_DIR/$unit" ]; then
if ! diff -q "$REPO_DIR/$unit" "$SYSTEMD_DIR/$unit" >/dev/null 2>&1; then
sudo cp "$REPO_DIR/$unit" "$SYSTEMD_DIR/$unit"
RELOAD_NEEDED=true
echo "[$(date)] Updated $unit"
fi
fi
done
if $RELOAD_NEEDED; then
sudo systemctl daemon-reload
fi
sudo systemctl restart "$SERVICE"
echo "[$(date)] Service restarted"
else
echo "[$(date)] Already up to date"
fi