homelab-brain/scripts/deploy.sh

47 lines
1.5 KiB
Bash
Executable file

#!/bin/bash
# deploy.sh — Push zu Forgejo + sofort auf pve-hetzner synchronisieren
# CT 116 sieht Änderungen automatisch über Bind-Mount.
#
# Nutzung: ./scripts/deploy.sh "Commit-Nachricht"
# ./scripts/deploy.sh (ohne Nachricht = Auto-Message)
set -euo pipefail
cd "$(dirname "$0")/.."
source homelab.conf
MSG="${1:-Deploy: $(date +%Y-%m-%d\ %H:%M)}"
git add -A
if git diff --cached --quiet 2>/dev/null; then
echo "Nichts zu committen."
else
git commit -m "$MSG"
fi
git fetch forgejo main
git rebase forgejo/main
git push forgejo main
IS_HETZNER=false
if hostname | grep -q pve-hetzner || [ "$(hostname -I 2>/dev/null | grep -o '100\.88\.230\.59')" ]; then
IS_HETZNER=true
fi
if $IS_HETZNER; then
echo "→ Lokal auf pve-hetzner — kein SSH nötig."
echo "OK: $(git log --oneline -1)"
echo "→ Bot neu starten..."
pct exec 116 -- systemctl restart hausmeister-bot 2>/dev/null && echo "Bot restarted" || echo "Bot restart nicht nötig"
else
echo "→ Sync auf pve-hetzner..."
sshpass -p "$PW_HETZNER" ssh -o StrictHostKeyChecking=no root@$SRV_HETZNER \
'cd /opt/homelab-brain && git fetch origin main --quiet && git reset --hard FETCH_HEAD --quiet && echo "OK: $(git log --oneline -1)"'
echo "→ Bot neu starten..."
sshpass -p "$PW_HETZNER" ssh -o StrictHostKeyChecking=no root@$SRV_HETZNER \
'pct exec 116 -- systemctl restart hausmeister-bot 2>/dev/null && echo "Bot restarted" || echo "Bot restart nicht nötig"'
fi
echo "✅ Deploy fertig."