Commit automático a - 2025-09-07 14:31:34

This commit is contained in:
2025-09-07 14:31:34 -03:00
parent 7325e9c91f
commit 5bb996f9c2
3 changed files with 291 additions and 50 deletions

View File

@ -5,6 +5,7 @@ echo "🚀 Instalando comando git subir..."
CONFIG="$HOME/.config/git-subir.conf"
BIN="$HOME/.local/bin/git-subir"
# Crear directorios
mkdir -p "$(dirname "$CONFIG")"
mkdir -p "$(dirname "$BIN")"
@ -28,22 +29,21 @@ read -p "🔐 ¿Querés cifrar las credenciales? (s/n): " cifrar
if [[ "$cifrar" == "s" ]]; then
read -s -p "🔑 Contraseña para cifrado: " pass
echo ""
salt=$(openssl rand -hex 16)
cred="$usuario:$token"
cred_cifrada=$(echo -n "$cred" | openssl enc -aes-256-cbc -a -pbkdf2 -salt -pass pass:"$pass")
SALT=$(openssl rand -hex 16)
CRED=$(echo -n "$usuario:$token" | openssl enc -aes-256-cbc -a -pbkdf2 -salt -pass pass:"$pass")
else
cred_cifrada="$usuario:$token"
salt=""
CRED="$usuario:$token"
SALT=""
fi
# Guardar configuración
cat > "$CONFIG" <<EOF
URL=$url
CRED=$cred_cifrada
SALT=$salt
CRED=$CRED
SALT=$SALT
EOF
# Generar script git-subir con commit interactivo
# Generar script git-subir
cat > "$BIN" <<'EOF'
#!/bin/bash
CONFIG="$HOME/.config/git-subir.conf"
@ -112,7 +112,7 @@ fi
# Descifrar credenciales si es necesario
if [[ -n "$SALT" ]]; then
read -s -p "🔑 Contraseña para descifrado: " pass
read -s -p "🔑 Ingresá la contraseña para descifrar credenciales: " pass
echo ""
CRED=$(echo "$CRED" | openssl enc -aes-256-cbc -a -d -pbkdf2 -salt -pass pass:"$pass" 2>/dev/null)
if [[ -z "$CRED" ]]; then
@ -124,9 +124,31 @@ fi
usuario=$(echo "$CRED" | cut -d: -f1)
token=$(echo "$CRED" | cut -d: -f2)
echo "📤 Subiendo cambios como $usuario a $URL..."
# Menú interactivo
echo "📤 ¿Qué querés hacer?"
echo "1) Subir a main (Producción)"
echo "2) Subir a develop (Desarrollo)"
echo "3) 🚀 Deploy merge (merge develop → main + push)"
read -p "Seleccioná una opción (1-3): " opcion
# Verificar si es repo git
case $opcion in
1)
rama_destino="main"
;;
2)
rama_destino="develop"
;;
3)
rama_destino="main"
merge_desde="develop"
;;
*)
echo "❌ Opción inválida. Abortando."
exit 1
;;
esac
# Inicializar repo si es necesario
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
echo "📁 No estás en un repositorio git. Inicializando..."
git init
@ -134,14 +156,22 @@ if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
git remote add origin "$remote_url"
fi
# Detectar cambios sin commitear
# Merge si corresponde
if [[ -n "$merge_desde" ]]; then
git fetch origin
git checkout $rama_destino
git merge origin/$merge_desde
fi
# Detectar cambios
if [[ -n "$(git status --porcelain)" ]]; then
echo "📦 Hay cambios sin commitear."
read -p "¿Querés escribir el mensaje de commit? (s/n): " respuesta
if [[ "$respuesta" == "s" ]]; then
read -p "📝 Ingresá el mensaje de commit: " mensaje
else
mensaje="Commit automático desde git-subir"
fecha=$(date +"%Y-%m-%d %H:%M:%S")
mensaje="Commit automático a $rama_destino - $fecha"
fi
git add -A
git commit -m "$mensaje"
@ -149,19 +179,32 @@ else
echo "✅ No hay cambios pendientes. Continuando con el push..."
fi
# Verificar si la rama tiene upstream
branch=$(git rev-parse --abbrev-ref HEAD)
remote=$(git config --get branch.$branch.remote)
# Push
remote=$(git config --get branch.$rama_destino.remote)
if [[ -z "$remote" ]]; then
echo "⚠️ La rama '$branch' no tiene remoto configurado."
echo "👉 Ejecutando: git push --set-upstream origin $branch"
git push --set-upstream origin "$branch"
git push --set-upstream origin "$rama_destino"
else
git push
git push origin "$rama_destino"
fi
# Deploy local
if [[ "$rama_destino" == "main" ]]; then
destino="/var/www/html/intranet"
else
destino="/var/www/html/empleados"
fi
echo "📂 Copiando archivos a $destino..."
rsync -avz --delete ./ "$destino"/
echo "🎉 Deploy completado en $destino"
# Volver a rama original si cambió
rama_actual=$(git rev-parse --abbrev-ref HEAD)
if [[ "$rama_actual" != "$rama_destino" && "$rama_actual" != "HEAD" ]]; then
git checkout "$rama_actual"
fi
EOF
# Dar permisos de ejecución
chmod +x "$BIN"
# Validar PATH
@ -174,16 +217,4 @@ git config --global alias.subir "!git-subir"
echo "✅ Alias 'git subir' configurado."
echo "👉 Ejecutá 'source $SHELL_RC' o reiniciá la terminal para aplicar el PATH."
# Verificación final
if command -v git-subir >/dev/null; then
echo "✅ El comando 'git-subir' está disponible."
else
echo "⚠️ El comando 'git-subir' aún no está disponible."
fi
echo "🎉 Instalación completa."
echo "🛠️ Opciones disponibles para el comando:"
echo " git subir # Ejecuta git push con autenticación"
echo " git subir --reconfigurar # Cambia usuario, token, URL y clave"
echo " git subir --cambiar-clave # Cambia solo la contraseña de cifrado"
echo "🎉 Instalación completa. Ahora 'git subir' está listo para usarse."