Commit automático a - 2025-09-07 14:31:34
This commit is contained in:
@ -1,32 +1,53 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "🧹 Desinstalando git subir..."
|
||||
echo "🗑️ Desinstalando git-subir..."
|
||||
|
||||
BIN="$HOME/.local/bin/git-subir"
|
||||
# Archivos a eliminar
|
||||
CONFIG="$HOME/.config/git-subir.conf"
|
||||
BIN="$HOME/.local/bin/git-subir"
|
||||
LOG="$HOME/.config/git-subir.log"
|
||||
|
||||
# Eliminar script
|
||||
if [[ -f "$BIN" ]]; then
|
||||
rm "$BIN"
|
||||
echo "✅ Script eliminado: $BIN"
|
||||
# Eliminar configuración
|
||||
if [[ -f "$CONFIG" ]]; then
|
||||
rm -f "$CONFIG"
|
||||
echo "✅ Configuración eliminada: $CONFIG"
|
||||
else
|
||||
echo "⚠️ Script no encontrado en $BIN"
|
||||
echo "⚠️ Archivo de configuración no encontrado: $CONFIG"
|
||||
fi
|
||||
|
||||
# Eliminar alias
|
||||
# Eliminar log si existe
|
||||
if [[ -f "$LOG" ]]; then
|
||||
rm -f "$LOG"
|
||||
echo "✅ Log eliminado: $LOG"
|
||||
fi
|
||||
|
||||
# Eliminar binario
|
||||
if [[ -f "$BIN" ]]; then
|
||||
rm -f "$BIN"
|
||||
echo "✅ Ejecutable eliminado: $BIN"
|
||||
else
|
||||
echo "⚠️ Ejecutable no encontrado: $BIN"
|
||||
fi
|
||||
|
||||
# Eliminar alias de git
|
||||
if git config --global --get alias.subir >/dev/null; then
|
||||
git config --global --unset alias.subir
|
||||
echo "✅ Alias 'git subir' eliminado"
|
||||
else
|
||||
echo "⚠️ Alias 'git subir' no estaba configurado"
|
||||
echo "⚠️ Alias 'git subir' no estaba configurado"
|
||||
fi
|
||||
|
||||
# Eliminar configuración
|
||||
if [[ -f "$CONFIG" ]]; then
|
||||
rm "$CONFIG"
|
||||
echo "✅ Configuración eliminada: $CONFIG"
|
||||
else
|
||||
echo "⚠️ Archivo de configuración no encontrado en $CONFIG"
|
||||
# Eliminar PATH de .local/bin si no hay otros archivos
|
||||
if [[ -d "$HOME/.local/bin" ]]; then
|
||||
if [[ -z "$(ls -A "$HOME/.local/bin")" ]]; then
|
||||
for rc_file in "$HOME/.bashrc" "$HOME/.zshrc"; do
|
||||
if [[ -f "$rc_file" ]]; then
|
||||
sed -i '/export PATH="\$HOME\/.local\/bin:\$PATH"/d' "$rc_file"
|
||||
echo "✅ Línea PATH eliminada de: $rc_file"
|
||||
fi
|
||||
done
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "🎉 Desinstalación completa."
|
||||
echo "🎉 Desinstalación completada"
|
||||
echo "💡 Reiniciá tu terminal para aplicar los cambios"
|
||||
|
@ -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."
|
||||
|
189
instalar-subir.sh.back
Executable file
189
instalar-subir.sh.back
Executable file
@ -0,0 +1,189 @@
|
||||
#!/bin/bash
|
||||
|
||||
echo "🚀 Instalando comando git subir..."
|
||||
|
||||
CONFIG="$HOME/.config/git-subir.conf"
|
||||
BIN="$HOME/.local/bin/git-subir"
|
||||
|
||||
mkdir -p "$(dirname "$CONFIG")"
|
||||
mkdir -p "$(dirname "$BIN")"
|
||||
|
||||
# Solicitar credenciales
|
||||
read -p "👤 Usuario de Gitea: " usuario
|
||||
read -s -p "🔑 Token o contraseña: " token
|
||||
echo ""
|
||||
read -p "🌐 URL base de la API de Gitea: " url
|
||||
|
||||
# Validar autenticación
|
||||
resp=$(curl -s -u "$usuario:$token" "$url/api/v1/user")
|
||||
if echo "$resp" | grep -q "\"login\":\"$usuario\""; then
|
||||
echo "✅ Autenticación exitosa con $url/api/v1/user"
|
||||
else
|
||||
echo "❌ Falló la autenticación. Abortando."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Cifrado opcional
|
||||
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")
|
||||
else
|
||||
cred_cifrada="$usuario:$token"
|
||||
salt=""
|
||||
fi
|
||||
|
||||
# Guardar configuración
|
||||
cat > "$CONFIG" <<EOF
|
||||
URL=$url
|
||||
CRED=$cred_cifrada
|
||||
SALT=$salt
|
||||
EOF
|
||||
|
||||
# Generar script git-subir con commit interactivo
|
||||
cat > "$BIN" <<'EOF'
|
||||
#!/bin/bash
|
||||
CONFIG="$HOME/.config/git-subir.conf"
|
||||
mkdir -p "$(dirname "$CONFIG")"
|
||||
source "$CONFIG"
|
||||
|
||||
guardar_config() {
|
||||
cat > "$CONFIG" <<EOF2
|
||||
URL=$URL
|
||||
CRED=$CRED
|
||||
SALT=$SALT
|
||||
EOF2
|
||||
}
|
||||
|
||||
# Reconfigurar credenciales
|
||||
if [[ "$1" == "--reconfigurar" ]]; then
|
||||
echo "🔄 Reconfigurando credenciales..."
|
||||
read -p "👤 Usuario de Gitea: " usuario
|
||||
read -s -p "🔑 Token o contraseña: " token
|
||||
echo ""
|
||||
read -p "🌐 URL base de la API de Gitea: " URL
|
||||
resp=$(curl -s -u "$usuario:$token" "$URL/api/v1/user")
|
||||
if echo "$resp" | grep -q "\"login\":\"$usuario\""; then
|
||||
echo "✅ Autenticación exitosa con $URL/api/v1/user"
|
||||
else
|
||||
echo "❌ Falló la autenticación. Abortando."
|
||||
exit 1
|
||||
fi
|
||||
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=$(echo -n "$usuario:$token" | openssl enc -aes-256-cbc -a -pbkdf2 -salt -pass pass:"$pass")
|
||||
else
|
||||
CRED="$usuario:$token"
|
||||
SALT=""
|
||||
fi
|
||||
guardar_config
|
||||
echo "✅ Reconfiguración completa."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Cambiar solo la clave de cifrado
|
||||
if [[ "$1" == "--cambiar-clave" ]]; then
|
||||
echo "🔐 Cambiando contraseña de cifrado..."
|
||||
if [[ -z "$SALT" ]]; then
|
||||
echo "⚠️ Las credenciales no están cifradas. No se puede cambiar la clave."
|
||||
exit 1
|
||||
fi
|
||||
read -s -p "🔑 Contraseña actual: " oldpass
|
||||
echo ""
|
||||
cred_descifrada=$(echo "$CRED" | openssl enc -aes-256-cbc -a -d -pbkdf2 -salt -pass pass:"$oldpass" 2>/dev/null)
|
||||
if [[ -z "$cred_descifrada" ]]; then
|
||||
echo "❌ Contraseña incorrecta. Abortando."
|
||||
exit 1
|
||||
fi
|
||||
read -s -p "🔑 Nueva contraseña: " newpass
|
||||
echo ""
|
||||
SALT=$(openssl rand -hex 16)
|
||||
CRED=$(echo -n "$cred_descifrada" | openssl enc -aes-256-cbc -a -pbkdf2 -salt -pass pass:"$newpass")
|
||||
guardar_config
|
||||
echo "✅ Contraseña de cifrado actualizada."
|
||||
exit 0
|
||||
fi
|
||||
|
||||
# Descifrar credenciales si es necesario
|
||||
if [[ -n "$SALT" ]]; then
|
||||
read -s -p "🔑 Contraseña para descifrado: " pass
|
||||
echo ""
|
||||
CRED=$(echo "$CRED" | openssl enc -aes-256-cbc -a -d -pbkdf2 -salt -pass pass:"$pass" 2>/dev/null)
|
||||
if [[ -z "$CRED" ]]; then
|
||||
echo "❌ Contraseña incorrecta. Abortando."
|
||||
exit 1
|
||||
fi
|
||||
fi
|
||||
|
||||
usuario=$(echo "$CRED" | cut -d: -f1)
|
||||
token=$(echo "$CRED" | cut -d: -f2)
|
||||
|
||||
echo "📤 Subiendo cambios como $usuario a $URL..."
|
||||
|
||||
# Verificar si es repo git
|
||||
if ! git rev-parse --is-inside-work-tree >/dev/null 2>&1; then
|
||||
echo "📁 No estás en un repositorio git. Inicializando..."
|
||||
git init
|
||||
read -p "🌐 URL del remoto origin: " remote_url
|
||||
git remote add origin "$remote_url"
|
||||
fi
|
||||
|
||||
# Detectar cambios sin commitear
|
||||
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"
|
||||
fi
|
||||
git add -A
|
||||
git commit -m "$mensaje"
|
||||
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)
|
||||
|
||||
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"
|
||||
else
|
||||
git push
|
||||
fi
|
||||
EOF
|
||||
|
||||
chmod +x "$BIN"
|
||||
|
||||
# Validar PATH
|
||||
SHELL_RC="$HOME/.bashrc"
|
||||
[[ "$SHELL" == */zsh ]] && SHELL_RC="$HOME/.zshrc"
|
||||
grep -q "$HOME/.local/bin" <<< "$PATH" || echo 'export PATH="$HOME/.local/bin:$PATH"' >> "$SHELL_RC"
|
||||
|
||||
# Configurar alias
|
||||
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"
|
Reference in New Issue
Block a user