deploy.sh: 2min-Sync + claude-config Repo + Linux-Cron Support

This commit is contained in:
Barby 2026-07-09 16:04:42 +02:00 committed by Mac-Host
parent 7e19208061
commit 186ab38081
2 changed files with 99 additions and 11 deletions

View file

@ -1,25 +1,77 @@
#!/bin/bash #!/bin/bash
# Claude Hooks Deploy — läuft auf jedem neuen Mac/Hub-Instanz einmalig # Claude Hooks + Config Sync Deploy
# Einmalig auf jedem neuen Mac/Hub ausführen:
# curl -sL https://git.consoro.eu/barby/claude-hooks/raw/branch/main/deploy.sh | bash # curl -sL https://git.consoro.eu/barby/claude-hooks/raw/branch/main/deploy.sh | bash
set -e set -e
HOOKS_REPO="https://barby:dc9a2241890acb243548342977a6c02d6dde39a7@git.consoro.eu/barby/claude-hooks.git" HOOKS_REPO="https://barby:dc9a2241890acb243548342977a6c02d6dde39a7@git.consoro.eu/barby/claude-hooks.git"
CONFIG_REPO="https://barby:dc9a2241890acb243548342977a6c02d6dde39a7@git.consoro.eu/barby/claude-config.git"
CLAUDE_DIR="$HOME/.claude" CLAUDE_DIR="$HOME/.claude"
HOOKS_DIR="$CLAUDE_DIR/hooks-v2" HOOKS_DIR="$CLAUDE_DIR/hooks-v2"
LOCAL_REPO="$HOME/git/claude-hooks" HOOKS_LOCAL="$HOME/git/claude-hooks"
CONFIG_LOCAL="$HOME/git/claude-config"
echo "=== Claude Hooks Deploy ===" echo "=== Claude Deploy ==="
mkdir -p "$HOOKS_DIR" "$LOCAL_REPO" mkdir -p "$HOOKS_DIR" "$HOOKS_LOCAL" "$CONFIG_LOCAL"
if [ ! -d "$LOCAL_REPO/.git" ]; then # 1) Hooks-Repo klonen/updaten
git clone "$HOOKS_REPO" "$LOCAL_REPO" if [ ! -d "$HOOKS_LOCAL/.git" ]; then
git clone "$HOOKS_REPO" "$HOOKS_LOCAL" -q
else else
cd "$LOCAL_REPO" && git pull origin main -q cd "$HOOKS_LOCAL" && git pull origin main -q
fi fi
# Scripts deployen # Hook-Scripts deployen
cp "$LOCAL_REPO/hooks-v2/"*.sh "$HOOKS_DIR/" 2>/dev/null cp "$HOOKS_LOCAL/hooks-v2/"*.sh "$HOOKS_DIR/" 2>/dev/null
chmod +x "$HOOKS_DIR/"*.sh chmod +x "$HOOKS_DIR/"*.sh
echo "✅ Hooks deployed: $(ls $HOOKS_DIR/*.sh | wc -l | tr -d ' ') Scripts"
echo "$(ls $HOOKS_DIR/*.sh | wc -l | tr -d ' ') Hook-Scripts deployed nach $HOOKS_DIR" # 2) Config-Repo einrichten (falls nicht vorhanden — erstmalig)
echo "Fertig — bitte Claude Code neu starten." if [ ! -d "$CONFIG_LOCAL/.git" ]; then
# Repo auf Hub erstellen falls nötig
TOKEN="dc9a2241890acb243548342977a6c02d6dde39a7"
curl -s -X POST "https://git.consoro.eu/api/v1/user/repos" \
-H "Authorization: token $TOKEN" -H "Content-Type: application/json" \
-d '{"name":"claude-config","description":"Claude Code Config Sync","private":true,"auto_init":true}' \
-o /dev/null
sleep 2
git clone "$CONFIG_REPO" "$CONFIG_LOCAL" -q 2>/dev/null || (mkdir -p "$CONFIG_LOCAL" && cd "$CONFIG_LOCAL" && git init && git remote add origin "$CONFIG_REPO")
fi
echo "✅ Config-Repo ready: $CONFIG_LOCAL"
# 3) LaunchAgent (macOS) oder Cron (Linux) für 2min-Sync installieren
OS=$(uname)
if [ "$OS" = "Darwin" ]; then
PLIST="$HOME/Library/LaunchAgents/eu.consoro.claude-sync.plist"
cat > "$PLIST" << PEOF
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key><string>eu.consoro.claude-sync</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>$HOOKS_DIR/sync-to-hub.sh</string>
</array>
<key>StartInterval</key><integer>120</integer>
<key>RunAtLoad</key><false/>
<key>StandardOutPath</key><string>/tmp/claude-sync.log</string>
<key>StandardErrorPath</key><string>/tmp/claude-sync.err</string>
</dict>
</plist>
PEOF
launchctl unload "$PLIST" 2>/dev/null || true
launchctl load "$PLIST"
echo "✅ LaunchAgent installiert (alle 2min)"
else
# Linux: crontab
(crontab -l 2>/dev/null | grep -v claude-sync; echo "*/2 * * * * bash $HOOKS_DIR/sync-to-hub.sh >> /tmp/claude-sync.log 2>&1") | crontab -
echo "✅ Cron installiert (alle 2min)"
fi
echo ""
echo "=== Deploy fertig ==="
echo "Hooks: $HOOKS_DIR"
echo "Sync: $CONFIG_LOCAL → git.consoro.eu/barby/claude-config (alle 2min)"
echo "Bitte Claude Code neu starten."

36
hooks-v2/sync-to-hub.sh Normal file
View file

@ -0,0 +1,36 @@
#!/bin/bash
# Alle 2min: lokale Claude-Änderungen → git.consoro.eu/barby/claude-config
# Synct: memory/, skills/, hooks-v2/ — KEINE Credentials/Sessions/Cache
REPO_DIR="$HOME/git/claude-config"
CLAUDE_DIR="$HOME/.claude"
[ ! -d "$REPO_DIR/.git" ] && exit 0
# Relevante Dirs kopieren (kein Cache, keine Sessions, keine Credentials)
rsync -a --delete \
--exclude="*.jsonl" \
--exclude="cache/" \
--exclude="session-env/" \
--exclude="sessions/" \
--exclude="logs/" \
--exclude="log/" \
--exclude="mcp-needs-auth-cache.json" \
--exclude=".last-update" \
"$CLAUDE_DIR/projects/" "$REPO_DIR/projects/" 2>/dev/null
rsync -a --delete "$CLAUDE_DIR/hooks-v2/" "$REPO_DIR/hooks-v2/" 2>/dev/null
rsync -a --delete "$CLAUDE_DIR/skills/" "$REPO_DIR/skills/" 2>/dev/null
# Status-Datei aus Claude_desktop falls vorhanden
STATUS_SRC="/Users/matthiaskoerner/Library/Mobile Documents/com~apple~CloudDocs/Claude_desktop/status.md"
[ -f "$STATUS_SRC" ] && cp "$STATUS_SRC" "$REPO_DIR/status.md"
cd "$REPO_DIR" || exit 1
git add -A
git diff --cached --quiet && exit 0 # nix geändert
HOSTNAME=$(hostname -s)
git commit -m "auto-sync $HOSTNAME $(date '+%H:%M:%S')" \
--author="Barby <barby@consoro.eu>" -q
git push origin main -q 2>&1 | logger -t claude-sync