96 lines
2.8 KiB
Bash
Executable File
96 lines
2.8 KiB
Bash
Executable File
#!/bin/bash
|
|
set -e
|
|
|
|
# 📁 Crear directorio de scripts
|
|
mkdir -p "$HOME/.scripts"
|
|
|
|
# 📜 Copiar script principal
|
|
cat <<'EOF' > "$HOME/.scripts/git-subir.sh"
|
|
#!/bin/bash
|
|
set -e
|
|
|
|
source "$HOME/.scripts/.env"
|
|
|
|
remote_url=$(git remote get-url origin | sed 's|https://||')
|
|
auth_url="https://$GITEA_USER:$GITEA_TOKEN@$remote_url"
|
|
|
|
function marco() {
|
|
echo -e "╔════════════════════════════════╗"
|
|
echo -e "║ $1"
|
|
echo -e "╚════════════════════════════════╝"
|
|
}
|
|
|
|
# 📦 Detectar cambios sin commitear
|
|
if ! git diff-index --quiet HEAD; then
|
|
echo "📦 Se detectaron cambios sin commitear:"
|
|
git status -s
|
|
|
|
read -p "¿Querés hacer commit automático de estos cambios? (s/n): " auto_commit
|
|
if [[ "$auto_commit" == "s" ]]; then
|
|
read -p "📝 Ingresá el mensaje de commit: " mensaje
|
|
git add .
|
|
git commit -m "$mensaje"
|
|
echo "✅ Commit realizado."
|
|
fi
|
|
fi
|
|
|
|
# 🚀 Intentar push
|
|
echo "🚀 Subiendo archivos al repositorio remoto..."
|
|
if ! git push "$auth_url"; then
|
|
echo "⚠️ Push fallido. Intentando pull con --allow-unrelated-histories..."
|
|
git pull "$auth_url" --allow-unrelated-histories || true
|
|
|
|
conflictos=$(git diff --name-only --diff-filter=U)
|
|
if [[ -n "$conflictos" ]]; then
|
|
echo "🚨 Conflictos detectados:"
|
|
echo "$conflictos"
|
|
read -p "¿Hacer merge automático? (s/n): " merge_auto
|
|
if [[ "$merge_auto" == "s" ]]; then
|
|
git add .
|
|
git commit -m "🔀 Merge automático"
|
|
else
|
|
echo "❌ Merge cancelado. Resolvé los conflictos manualmente."
|
|
exit 1
|
|
fi
|
|
fi
|
|
|
|
git push "$auth_url"
|
|
fi
|
|
|
|
echo "🎉 Push completado."
|
|
EOF
|
|
|
|
chmod +x "$HOME/.scripts/git-subir.sh"
|
|
|
|
# 🔗 Crear alias ejecutable
|
|
echo "Creando alias git-subir..."
|
|
cat <<EOF | sudo tee /usr/local/bin/git-subir > /dev/null
|
|
#!/bin/bash
|
|
exec "$HOME/.scripts/git-subir.sh" "\$@"
|
|
EOF
|
|
|
|
sudo chmod +x /usr/local/bin/git-subir
|
|
|
|
# 🔐 Credenciales
|
|
echo "🔐 Configurando credenciales de Gitea..."
|
|
read -p "Usuario de Gitea: " GITEA_USER
|
|
read -s -p "Contraseña o Token: " GITEA_TOKEN
|
|
echo ""
|
|
|
|
echo "🔎 Verificando credenciales..."
|
|
response=$(curl -s -u "$GITEA_USER:$GITEA_TOKEN" https://gitea.espaciomemoria.ar/api/v1/user)
|
|
|
|
if echo "$response" | grep -q '"login":"'"$GITEA_USER"'"'; then
|
|
echo "✅ Credenciales válidas."
|
|
echo "GITEA_USER=$GITEA_USER" > "$HOME/.scripts/.env"
|
|
echo "GITEA_TOKEN=$GITEA_TOKEN" >> "$HOME/.scripts/.env"
|
|
chmod 600 "$HOME/.scripts/.env"
|
|
else
|
|
echo "❌ Credenciales inválidas. Abortando instalación."
|
|
sudo rm -f /usr/local/bin/git-subir
|
|
rm -rf "$HOME/.scripts/git-subir.sh"
|
|
exit 1
|
|
fi
|
|
|
|
echo "✅ Instalación completa. Usá el comando: git subir"
|