inital commit

This commit is contained in:
thomas 2025-07-01 16:51:24 +02:00
parent adcaceb7ac
commit c3e800d2da
1 changed files with 25 additions and 11 deletions

View File

@ -12,15 +12,17 @@ if [ ! -d "$DIR" ]; then
fi
cd "$DIR"
read -p "Neuer Repo-Name auf Gitea (z für Abbruch): " REPO
read -p "Repo-Name auf Gitea (z für Abbruch): " REPO
[[ "$REPO" =~ ^[zZ]$ ]] && exit 0
# Repo-Name validieren (wie im Menü)
REPO_VALID=$(echo "$REPO" | sed 's/ /-/g')
if [[ ! "$REPO_VALID" =~ ^[A-Za-z0-9._-]+$ ]]; then
echo "Ungültiger Repo-Name! Nur Buchstaben, Zahlen, Bindestrich (-), Unterstrich (_) und Punkt (.) sind erlaubt."
exit 1
fi
# Prüfe, ob das Repo schon existiert
EXISTS=$(curl -s -H "Authorization: token $GITEA_TOKEN" "$GITEA_URL/api/v1/repos/$GITEA_USER/$REPO_VALID" | grep '"id"')
if [ -z "$EXISTS" ]; then
# Repo per API anlegen
ANTWORT=$(curl -s -X POST -H "Content-Type: application/json" -H "Authorization: token $GITEA_TOKEN" \
-d '{"name":"'$REPO_VALID'","private":false}' "$GITEA_URL/api/v1/user/repos")
@ -30,10 +32,15 @@ else
echo "Fehler beim Anlegen des Repos: $ANTWORT"
exit 1
fi
NEWREPO=1
else
echo "Repo $REPO_VALID existiert bereits, es wird ein Commit & Push durchgeführt."
NEWREPO=0
fi
# Git-Repo initialisieren (falls noch nicht vorhanden)
if [ ! -d .git ]; then
git init
git init -b main
fi
git remote remove origin 2>/dev/null
@ -49,4 +56,11 @@ git branch -M main 2>/dev/null
git push -u origin main
echo "Upload abgeschlossen. Repo: $GITURL"
# Setze Standard-Branch auf main per Gitea-API (nur bei Neuanlage)
if [ "$NEWREPO" = "1" ]; then
curl -s -X PATCH -H "Content-Type: application/json" -H "Authorization: token $GITEA_TOKEN" \
-d '{"default_branch":"main"}' "$GITEA_URL/api/v1/repos/$GITEA_USER/$REPO_VALID" > /dev/null
echo "Upload abgeschlossen. Repo: $GITURL (neu angelegt, Standard-Branch: main)"
else
echo "Upload abgeschlossen. Repo: $GITURL (bestehendes Repo aktualisiert)"
fi