Se modifico la instalacion y desistalacion se creo .env para guardar credenciales del usuario
This commit is contained in:
@ -1,100 +1,95 @@
|
||||
#!/bin/bash
|
||||
set -e
|
||||
|
||||
# ╔════════════════════════════════════════════════════╗
|
||||
# ║ VERIFICACIÓN DE REPOSITORIO GIT ║
|
||||
# ╚════════════════════════════════════════════════════╝
|
||||
# 📁 Crear directorio de scripts
|
||||
mkdir -p "$HOME/.scripts"
|
||||
|
||||
if ! git rev-parse --is-inside-work-tree > /dev/null 2>&1; then
|
||||
echo ""
|
||||
echo "🛑 Este comando debe ejecutarse dentro de un repositorio Git."
|
||||
# 📜 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
|
||||
|
||||
BRANCH="main"
|
||||
|
||||
# ╔════════════════════════════════════════════════════╗
|
||||
# ║ INGRESO DE CREDENCIALES ║
|
||||
# ╚════════════════════════════════════════════════════╝
|
||||
|
||||
echo ""
|
||||
echo "🔐 Ingresá tu usuario de Gitea:"
|
||||
echo "╔════════════════╗"
|
||||
read -p "║ Usuario: " USER
|
||||
echo "╚════════════════╝"
|
||||
|
||||
echo ""
|
||||
echo "🔐 Ingresá tu contraseña o token de Gitea:"
|
||||
echo "╔════════════════════════════════╗"
|
||||
read -s -p "║ Contraseña/Token: " TOKEN
|
||||
echo ""
|
||||
echo "╚════════════════════════════════╝"
|
||||
|
||||
# ╔════════════════════════════════════════════════════╗
|
||||
# ║ DETECCIÓN DE CAMBIOS SIN COMMITEAR ║
|
||||
# ╚════════════════════════════════════════════════════╝
|
||||
|
||||
CHANGES=$(git status --porcelain)
|
||||
|
||||
if [ -n "$CHANGES" ]; then
|
||||
echo ""
|
||||
echo "📦 Se detectaron cambios sin commitear:"
|
||||
echo "$CHANGES"
|
||||
read -p "¿Querés hacer commit automático de estos cambios? (s/n): " COMMIT_RESP
|
||||
|
||||
if [ "$COMMIT_RESP" == "s" ]; then
|
||||
echo ""
|
||||
read -p "📝 Ingresá el mensaje de commit: " COMMIT_MSG
|
||||
git add .
|
||||
git commit -m "$COMMIT_MSG"
|
||||
echo "✅ Commit realizado."
|
||||
else
|
||||
echo "🛑 No se hizo commit. Continuando sin cambios."
|
||||
fi
|
||||
fi
|
||||
|
||||
# ╔════════════════════════════════════════════════════╗
|
||||
# ║ INICIO DE SUBIDA DE ARCHIVOS ║
|
||||
# ╚════════════════════════════════════════════════════╝
|
||||
|
||||
echo ""
|
||||
echo "🚀 Subiendo archivos al repositorio remoto..."
|
||||
echo ""
|
||||
|
||||
REPO_URL=$(git config --get remote.origin.url)
|
||||
|
||||
git config --global credential.helper store
|
||||
echo "${REPO_URL/https:\/\//https://$USER:$TOKEN@}" > ~/.git-credentials
|
||||
|
||||
git push origin $BRANCH
|
||||
if [ $? -ne 0 ]; then
|
||||
echo ""
|
||||
echo "⚠️ Push fallido. Intentando pull con --allow-unrelated-histories..."
|
||||
git pull --no-rebase origin $BRANCH --allow-unrelated-histories
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo ""
|
||||
echo "✅ Pull exitoso. Reintentando push..."
|
||||
git push origin $BRANCH
|
||||
else
|
||||
echo ""
|
||||
echo "⚠️ Verificando conflictos..."
|
||||
CONFLICTS=$(git diff --name-only --diff-filter=U)
|
||||
|
||||
if [ -n "$CONFLICTS" ]; then
|
||||
echo ""
|
||||
echo "🚨 Conflictos detectados:"
|
||||
echo "$CONFLICTS"
|
||||
read -p "¿Hacer merge automático? (s/n): " RESP
|
||||
if [ "$RESP" == "s" ]; then
|
||||
git add .
|
||||
git commit -m "🔀 Merge automático"
|
||||
git push origin $BRANCH
|
||||
echo "🎉 Push completado después del merge."
|
||||
else
|
||||
echo "🛑 Merge cancelado. Resolvé manualmente."
|
||||
fi
|
||||
else
|
||||
echo "❌ Pull falló por otro motivo."
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
echo "✅ Instalación completa. Usá el comando: git subir"
|
||||
|
Reference in New Issue
Block a user