-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathpull_and_deploy.sh
More file actions
executable file
·52 lines (43 loc) · 1.99 KB
/
pull_and_deploy.sh
File metadata and controls
executable file
·52 lines (43 loc) · 1.99 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
42
43
44
45
46
47
48
49
50
51
52
#!/bin/bash
# Copyright (c) 2026 Nardo. AGPL-3.0 — see LICENSE
# Git pull + auto-deploy hooks if anything changed.
# Used by cron (VPS) and launchd (Mac) for auto-sync.
cd "$(dirname "$0")/.." # telegram-claude-bot root
# Capture current HEAD
OLD_HEAD=$(git rev-parse HEAD 2>/dev/null)
# Pull
git pull --ff-only origin main >> /tmp/telegram-bot-sync.log 2>&1
PULL_EXIT=$?
if [ $PULL_EXIT -ne 0 ]; then
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Pull failed (exit $PULL_EXIT)" >> /tmp/telegram-bot-sync.log
exit $PULL_EXIT
fi
NEW_HEAD=$(git rev-parse HEAD 2>/dev/null)
# If HEAD changed, check what was modified
if [ "$OLD_HEAD" != "$NEW_HEAD" ]; then
CHANGED=$(git diff --name-only "$OLD_HEAD" "$NEW_HEAD" 2>/dev/null)
# Auto-deploy hooks if hooks/ changed
if echo "$CHANGED" | grep -q "^hooks/"; then
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Hooks changed, deploying..." >> /tmp/telegram-bot-sync.log
bash hooks/deploy_hooks.sh >> /tmp/telegram-bot-sync.log 2>&1
fi
# Check if source-of-truth files changed → warn about stale templates
SOT_FILES="llm_client.py config.py start_all.sh bot_base.py sanitizer.py utils.py"
STALE_WARN=""
for sot in $SOT_FILES; do
if echo "$CHANGED" | grep -q "$sot"; then
STALE_WARN="$STALE_WARN $sot"
fi
done
if [ -n "$STALE_WARN" ]; then
echo "[$(date '+%Y-%m-%d %H:%M:%S')] SOURCE-OF-TRUTH CHANGED:$STALE_WARN — check ADMIN_HANDBOOK.md, TERMINAL_MEMORY.md, settings.template.json" >> /tmp/telegram-bot-sync.log
fi
# Auto-sync to public repos if publishable files changed (Mac only)
if [[ "$(uname)" == "Darwin" ]] && echo "$CHANGED" | grep -q "^hooks/"; then
SYNC_SCRIPT="$(pwd)/scripts/sync_public_repos.py"
if [ -f "$SYNC_SCRIPT" ]; then
echo "[$(date '+%Y-%m-%d %H:%M:%S')] Publishable hooks changed, syncing to public repos..." >> /tmp/telegram-bot-sync.log
python3 "$SYNC_SCRIPT" --sync >> /tmp/telegram-bot-sync.log 2>&1
fi
fi
fi