inital commit
This commit is contained in:
parent
adcaceb7ac
commit
c3e800d2da
|
|
@ -12,28 +12,35 @@ if [ ! -d "$DIR" ]; then
|
||||||
fi
|
fi
|
||||||
cd "$DIR"
|
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" =~ ^[zZ]$ ]] && exit 0
|
||||||
# Repo-Name validieren (wie im Menü)
|
|
||||||
REPO_VALID=$(echo "$REPO" | sed 's/ /-/g')
|
REPO_VALID=$(echo "$REPO" | sed 's/ /-/g')
|
||||||
if [[ ! "$REPO_VALID" =~ ^[A-Za-z0-9._-]+$ ]]; then
|
if [[ ! "$REPO_VALID" =~ ^[A-Za-z0-9._-]+$ ]]; then
|
||||||
echo "Ungültiger Repo-Name! Nur Buchstaben, Zahlen, Bindestrich (-), Unterstrich (_) und Punkt (.) sind erlaubt."
|
echo "Ungültiger Repo-Name! Nur Buchstaben, Zahlen, Bindestrich (-), Unterstrich (_) und Punkt (.) sind erlaubt."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Repo per API anlegen
|
# Prüfe, ob das Repo schon existiert
|
||||||
ANTWORT=$(curl -s -X POST -H "Content-Type: application/json" -H "Authorization: token $GITEA_TOKEN" \
|
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")
|
-d '{"name":"'$REPO_VALID'","private":false}' "$GITEA_URL/api/v1/user/repos")
|
||||||
if echo "$ANTWORT" | grep -q '"id"'; then
|
if echo "$ANTWORT" | grep -q '"id"'; then
|
||||||
echo "Gitea-Repo $REPO_VALID wurde angelegt."
|
echo "Gitea-Repo $REPO_VALID wurde angelegt."
|
||||||
else
|
else
|
||||||
echo "Fehler beim Anlegen des Repos: $ANTWORT"
|
echo "Fehler beim Anlegen des Repos: $ANTWORT"
|
||||||
exit 1
|
exit 1
|
||||||
|
fi
|
||||||
|
NEWREPO=1
|
||||||
|
else
|
||||||
|
echo "Repo $REPO_VALID existiert bereits, es wird ein Commit & Push durchgeführt."
|
||||||
|
NEWREPO=0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Git-Repo initialisieren (falls noch nicht vorhanden)
|
# Git-Repo initialisieren (falls noch nicht vorhanden)
|
||||||
if [ ! -d .git ]; then
|
if [ ! -d .git ]; then
|
||||||
git init
|
git init -b main
|
||||||
fi
|
fi
|
||||||
|
|
||||||
git remote remove origin 2>/dev/null
|
git remote remove origin 2>/dev/null
|
||||||
|
|
@ -49,4 +56,11 @@ git branch -M main 2>/dev/null
|
||||||
|
|
||||||
git push -u origin main
|
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
|
||||||
Loading…
Reference in New Issue