From c3e800d2daea182189a98b798099e153891328e8 Mon Sep 17 00:00:00 2001 From: thomas Date: Tue, 1 Jul 2025 16:51:24 +0200 Subject: [PATCH] inital commit --- git_gitea_upload.sh | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/git_gitea_upload.sh b/git_gitea_upload.sh index c84e3d5..83d8163 100755 --- a/git_gitea_upload.sh +++ b/git_gitea_upload.sh @@ -12,28 +12,35 @@ 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 -# 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") -if echo "$ANTWORT" | grep -q '"id"'; then - echo "Gitea-Repo $REPO_VALID wurde angelegt." +# 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") + if echo "$ANTWORT" | grep -q '"id"'; then + echo "Gitea-Repo $REPO_VALID wurde angelegt." + else + echo "Fehler beim Anlegen des Repos: $ANTWORT" + exit 1 + fi + NEWREPO=1 else - echo "Fehler beim Anlegen des Repos: $ANTWORT" - exit 1 + 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" \ No newline at end of file +# 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 \ No newline at end of file