Files
WeihnachtsKalenderMelly/gittea.sh
2025-11-05 09:21:47 +01:00

51 lines
2.1 KiB
Bash
Executable File
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/bin/bash
# ============================================================
# 🧰 Gitea SSH Fix Script (Version 3)
# Führt vollständige Reparatur von SSH-Keys, Hooks & Rechten durch
# ============================================================
set -euo pipefail
grn='\e[32m'; red='\e[31m'; yel='\e[33m'; nc='\e[0m'
echo -e "${grn}🔧 Starte Gitea SSH-Reparatur...${nc}"
# 1⃣ Gitea-Binary prüfen
GITEA_BIN=$(command -v gitea || echo "/usr/local/bin/gitea")
echo -e "${grn}➡ Verwende Gitea-Binary:${nc} $GITEA_BIN"
# 2⃣ Gitea stoppen
echo -e "${yel}⏹ Stoppe Gitea-Service...${nc}"
systemctl stop gitea || echo -e "${red}⚠️ Konnte Gitea nicht stoppen (evtl. nicht aktiv).${nc}"
# 3⃣ Hooks & Keys regenerieren (richtig: als Benutzer 'git')
echo -e "${grn}♻️ Regeneriere Hooks und Keys...${nc}"
sudo -u git "$GITEA_BIN" --config /etc/gitea/app.ini --work-path /var/lib/gitea admin regenerate hooks
sudo -u git "$GITEA_BIN" --config /etc/gitea/app.ini --work-path /var/lib/gitea admin regenerate keys
# 4⃣ Berechtigungen für .ssh korrigieren
echo -e "${grn}🧱 Setze Berechtigungen für .ssh...${nc}"
chown -R git:git /home/git/.ssh
chmod 700 /home/git/.ssh
chmod 600 /home/git/.ssh/authorized_keys
# 5⃣ authorized_keys prüfen
if ! grep -q "command=" /home/git/.ssh/authorized_keys; then
echo -e "${yel}⚠️ Kein 'command='-Eintrag gefunden ergänze Gitea-Zeile...${nc}"
FIRST_KEY=$(head -n 1 /home/git/.ssh/authorized_keys | awk '{print $NF}')
echo "command=\"$GITEA_BIN --config=/etc/gitea/app.ini serv key-1\",no-port-forwarding,no-agent-forwarding,no-pty ssh-ed25519 $FIRST_KEY" > /home/git/.ssh/authorized_keys
chown git:git /home/git/.ssh/authorized_keys
chmod 600 /home/git/.ssh/authorized_keys
else
echo -e "${grn}✅ authorized_keys sieht gut aus.${nc}"
fi
# 6⃣ Gitea starten
echo -e "${grn}🚀 Starte Gitea neu...${nc}"
systemctl start gitea
# 7⃣ SSH-Test lokal
echo -e "${yel}🔍 Kurzer SSH-Test (lokal)...${nc}"
sudo -u git ssh -T git@localhost || true
echo -e "\n${grn}✅ Gitea SSH-Fix abgeschlossen.${nc}"
echo -e "Teste jetzt bitte extern mit:\n ssh -T git@illg.me\noder\n git push"