66 lines
2.1 KiB
Bash
Executable File
66 lines
2.1 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
GITEA_URL="https://gitea.kasimirat.de"
|
|
GITEA_USER="thomas"
|
|
GITEA_TOKEN="289ac11a4ad2938fa34e6baa29bec74bdbcbb57b"
|
|
|
|
read -p "Pfad zum lokalen Verzeichnis (z für Abbruch): " DIR
|
|
[[ "$DIR" =~ ^[zZ]$ ]] && exit 0
|
|
if [ ! -d "$DIR" ]; then
|
|
echo "Verzeichnis nicht gefunden!"
|
|
exit 1
|
|
fi
|
|
cd "$DIR"
|
|
|
|
read -p "Repo-Name auf Gitea (z für Abbruch): " REPO
|
|
[[ "$REPO" =~ ^[zZ]$ ]] && exit 0
|
|
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")
|
|
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 "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 -b main
|
|
fi
|
|
|
|
git remote remove origin 2>/dev/null
|
|
GITURL="$GITEA_URL/$GITEA_USER/$REPO_VALID.git"
|
|
git remote add origin "$GITURL"
|
|
|
|
git add .
|
|
read -p "Commit-Message: " MSG
|
|
[[ "$MSG" =~ ^[zZ]$ ]] && exit 0
|
|
git commit -m "$MSG"
|
|
|
|
git branch -M main 2>/dev/null
|
|
|
|
git push -u origin main
|
|
|
|
# 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 |