claude-hooks/deploy.sh

78 lines
2.9 KiB
Bash

#!/bin/bash
# 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
set -e
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"
HOOKS_DIR="$CLAUDE_DIR/hooks-v2"
HOOKS_LOCAL="$HOME/git/claude-hooks"
CONFIG_LOCAL="$HOME/git/claude-config"
echo "=== Claude Deploy ==="
mkdir -p "$HOOKS_DIR" "$HOOKS_LOCAL" "$CONFIG_LOCAL"
# 1) Hooks-Repo klonen/updaten
if [ ! -d "$HOOKS_LOCAL/.git" ]; then
git clone "$HOOKS_REPO" "$HOOKS_LOCAL" -q
else
cd "$HOOKS_LOCAL" && git pull origin main -q
fi
# Hook-Scripts deployen
cp "$HOOKS_LOCAL/hooks-v2/"*.sh "$HOOKS_DIR/" 2>/dev/null
chmod +x "$HOOKS_DIR/"*.sh
echo "✅ Hooks deployed: $(ls $HOOKS_DIR/*.sh | wc -l | tr -d ' ') Scripts"
# 2) Config-Repo einrichten (falls nicht vorhanden — erstmalig)
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."