-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathauto_vps_sync.py
More file actions
48 lines (38 loc) · 1.58 KB
/
auto_vps_sync.py
File metadata and controls
48 lines (38 loc) · 1.58 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
#!/usr/bin/env python3
"""PostToolUse hook: auto-sync VPS after git push."""
import re
import sys
sys.path.insert(0, str(__import__("pathlib").Path(__file__).parent))
from hook_base import run_hook, ssh_cmd
from vps_config import VPS_REPO
def check(tool_name, tool_input, input_data):
if tool_name != "Bash":
return False
cmd = tool_input.get("command", "")
return bool(re.search(r"git\s+push", cmd))
def action(tool_name, tool_input, input_data):
ok, out = ssh_cmd(f"cd {VPS_REPO} && git fetch origin && git reset --hard origin/main")
msg = f"VPS auto-synced after git push." if ok else f"VPS sync FAILED: {out}"
import subprocess
from pathlib import Path
scripts = Path.home() / "telegram-claude-bot" / "scripts"
# Auto-sync public extracted repos (sec-ops-guard, quality-gate, etc.)
sync_script = scripts / "sync_public_repos.py"
if sync_script.exists():
r = subprocess.run(
["python3", str(sync_script), "--sync"],
capture_output=True, text=True, timeout=60)
synced = r.stdout.count("COPIED")
if synced:
msg += f" Public repos: {synced} files synced."
# Auto-sync template (sanitized full bot copy)
template_script = scripts / "sync_template.py"
if template_script.exists():
r = subprocess.run(
["python3", str(template_script), "--sync"],
capture_output=True, text=True, timeout=60)
if "pushed" in r.stdout:
msg += " Template synced."
return msg
if __name__ == "__main__":
run_hook(check, action, "auto_vps_sync")