2.2 KiB
2.2 KiB
🛠️Creacion de herramienta git-publish
Git-publish es una herramienta para automatizar la creacion y publicacion de repositorios
1. Crea el script
Copia este contenido en ~/bin/git-publish (crea la carpeta ~/bin si no existe):
#!/bin/bash
set -e
ENV_FILE="${HOME}/.gitpublish.env"
if [ ! -f "$ENV_FILE" ]; then
echo "Falta archivo .env en $ENV_FILE"
exit 1
fi
source "$ENV_FILE"
REPO_NAME=$(basename "$(pwd)")
REPO_DESC="${1:-Repositorio publicado desde script}"
API_URL="$GITEA_URL/api/v1/user/repos"
echo "Inicializando git..."
git init
git checkout -b main 2>/dev/null || git checkout main
git add .
git commit -m "Primer commit" || echo "(commit ya hecho)"
echo "Creando repo remoto $REPO_NAME en Gitea..."
REPO_EXISTS=$(curl -s -H "Authorization: token $GITEA_TOKEN" "$GITEA_URL/api/v1/repos/$GITEA_USER/$REPO_NAME" | jq -r '.id // empty')
if [ -z "$REPO_EXISTS" ]; then
curl -s -X POST "$API_URL" \
-H "Authorization: token $GITEA_TOKEN" \
-H "Content-Type: application/json" \
-d "{\"name\": \"$REPO_NAME\", \"description\": \"$REPO_DESC\", \"private\": false}" \
> /dev/null
echo "Repositorio remoto creado."
else
echo "Repositorio remoto ya existe."
fi
echo "Subiendo código..."
git remote add origin "$GITEA_URL/$GITEA_USER/$REPO_NAME.git" 2>/dev/null || true
git push -u origin main
echo "✔️ Repo $REPO_NAME publicado en $GITEA_URL/$GITEA_USER/$REPO_NAME"
Hazlo ejecutable:
chmod +x ~/bin/git-publish
2. Añade ~/bin a tu PATH si no lo tienes
Edita ~/.bashrc (o ~/.zshrc si usas Zsh) y añade:
export PATH="$HOME/bin:$PATH"
Y recarga:
source ~/.bashrc
3. Crea tu .env
Archivo ~/.gitpublish.env: (crea y copia tu token en gitea)
GITEA_URL=https://git.manabo.org
GITEA_USER=xavor
GITEA_TOKEN=61a7abcb33ad7bf92454dd5a85c7bfe4becc41eb
4. Inicializa valores globales
git config --global user.email "xavor@hotmail.es"
git config --global user.name "xavor"
git config --global credential.helper store
✅ Y ahora sí: úsalo
cd ~/k3s/k8s-gitea
git-publish "Manifiestos de Gitea"