[IMPROVED] Agregar mensajes i18n para gladmin_install.sh

- Añadir mensajes i18n con prefijo glmsg_ para GitLab CLI installer
- Implementar variables de mensajes localizados en todo el script
- Mantener consistencia con el estilo de otros scripts de instalación

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Mauro Rosero P. 2025-03-19 17:51:04 -05:00
parent 1b4993ea4b
commit f415e54d34
Signed by: mrosero
GPG key ID: 83BD2A5F674B7E26
2 changed files with 559 additions and 0 deletions

504
bin/gladmin_install.sh Executable file
View file

@ -0,0 +1,504 @@
#!/bin/bash
#
# Script: gladmin_install.sh
# Description: Script para instalar Gitlab Manager CLI.
# Created: 2025/03/19 11:57:08
# Modified: 2025/03/19 11:57:08
# [Author] Cortana Rosero One <cortana@rosero.one>
# [Generated] Created by Claude Code (claude-3-7-sonnet-20250219)
#
# Derechos de Autor (C) [2025] [Mauro Rosero P. <mauro@rosero.one>]
#
# Este programa es software libre: usted puede redistribuirlo y/o modificarlo
# bajo los términos de la Licencia Pública Affero General de GNU tal como
# lo publica la Free Software Foundation, ya sea la versión 3 de la licencia,
# o (a su elección) cualquier versión posterior.
#
# Este programa se distribuye con la esperanza de que sea útil,
# pero SIN NINGUNA GARANTÍA; sin siquiera la garantía implícita de
# COMERCIABILIDAD o IDONEIDAD PARA UN PROPÓSITO PARTICULAR. Consulte la
# Licencia Pública Affero General de GNU para obtener más detalles.
#
# Debería haber recibido una copia de la Licencia Pública Affero General
# junto con este programa. Si no la recibió, consulte <https://www.gnu.org/licenses/>.
# Configuración inicial
# Usar DEVELOPER_DIR de base.lib
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BIN_BASE="bin"
BIN_LIBS="lib"
BIN_MESG="msg"
BIN_CFGS="config"
# Leer DEVSPATH desde el archivo de configuración o usar "devs" por defecto
if [ -f "$SCRIPT_DIR/config/devspath.dat" ]; then
DEVSPATH=$(cat "$SCRIPT_DIR/$BIN_CFGS/devspath.dat")
else
DEVSPATH="devs"
fi
BIN_HOME="$HOME/$DEVSPATH"
VERSION=$(cat "$BIN_HOME/$BIN_BASE/$BIN_CFGS/version")
# CHECK SHELL LANGUAGE
BIN_LANG=${LANG:0:2}
# Importar bibliotecas necesarias
source "${BIN_HOME}/${BIN_BASE}/${BIN_LIBS}/base.lib"
source "${BIN_HOME}/${BIN_BASE}/${BIN_LIBS}/developers.lib"
source "${BIN_HOME}/${BIN_BASE}/${BIN_LIBS}/console.lib"
# Cargar mensajes en el idioma del sistema o español por defecto
load_messages "${BIN_HOME}/${BIN_BASE}" "${BIN_MESG}" "${BIN_LANG}" "head"
load_messages "${BIN_HOME}/${BIN_BASE}" "${BIN_MESG}" "${BIN_LANG}" "developers"
title="${head_000} ${head_002}"
apps_title="${glmsg_000}"
# Función para verificar si se está ejecutando como root
check_root() {
if [ "$(id -u)" -ne 0 ]; then
echo "${glmsg_001}"
echo "${glmsg_002}"
# Verificar si sudo está disponible
if command -v sudo &> /dev/null; then
echo "${glmsg_003}"
sudo "$0" "$@"
exit $?
elif command -v doas &> /dev/null; then
echo "${glmsg_004}"
doas "$0" "$@"
exit $?
else
echo "${glmsg_005}"
exit 1
fi
fi
}
# Función para detectar la distribución
detect_distro() {
if [ -f /etc/os-release ]; then
. /etc/os-release
DISTRO=$ID
elif type lsb_release >/dev/null 2>&1; then
DISTRO=$(lsb_release -si | tr '[:upper:]' '[:lower:]')
elif [ -f /etc/lsb-release ]; then
. /etc/lsb-release
DISTRO=$DISTRIB_ID
elif [ -f /etc/debian_version ]; then
DISTRO="debian"
else
DISTRO=$(uname -s)
fi
echo "${glmsg_006} $DISTRO"
}
# Función para instalar glab mediante Homebrew en macOS y Linux
install_glab_homebrew() {
echo "${glmsg_007}"
# Verificar si Homebrew está instalado
if ! command -v brew &> /dev/null; then
echo "${glmsg_008}"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# Verificar si la instalación fue exitosa
if ! command -v brew &> /dev/null; then
echo "${glmsg_009}"
return 1
fi
fi
# Instalar GitLab CLI
brew install gitlab-glab/tap/glab
if [ $? -eq 0 ]; then
echo "${glmsg_010}"
return 0
else
echo "${glmsg_011}"
return 1
fi
}
# Función para instalar glab en sistemas basados en Debian/Ubuntu
install_glab_debian() {
echo "${glmsg_012}"
# Verificar si curl está instalado
if ! command -v curl &> /dev/null; then
apt update && apt install -y curl
fi
# Intentar primero usando los paquetes del sistema si están disponibles
if command -v apt &> /dev/null; then
echo "${glmsg_013}"
apt-cache search --names-only "^glab$" 2>/dev/null | grep -q "^glab"
if [ $? -eq 0 ]; then
echo "${glmsg_014}"
apt update && apt install -y glab
if [ $? -eq 0 ]; then
echo "${glmsg_015}"
return 0
fi
fi
fi
# Si no está en los repositorios, usar el script oficial
if command -v gpg &> /dev/null; then
echo "${glmsg_016}"
curl -s https://gitlab.com/gitlab-org/cli/-/raw/main/scripts/install.sh | bash
if [ $? -eq 0 ]; then
echo "${glmsg_017}"
return 0
fi
fi
# Si el método anterior falla, probar con Homebrew
echo "${glmsg_018}"
install_glab_homebrew
return $?
}
# Función para instalar glab en sistemas basados en Red Hat/Fedora
install_glab_redhat() {
echo "${glmsg_019}"
# Verificar si dnf está instalado
if command -v dnf &> /dev/null; then
# Verificar si glab está disponible en los repositorios
echo "${glmsg_013}"
dnf list glab &>/dev/null
if [ $? -eq 0 ]; then
echo "${glmsg_014}"
dnf install -y glab
if [ $? -eq 0 ]; then
echo "${glmsg_015}"
return 0
fi
fi
# Si no está en los repositorios, usar el script oficial
if command -v gpg &> /dev/null; then
echo "${glmsg_020}"
curl -s https://gitlab.com/gitlab-org/cli/-/raw/main/scripts/install.sh | bash
if [ $? -eq 0 ]; then
echo "${glmsg_017}"
return 0
fi
fi
# Si el método anterior falla, probar con snap
if command -v snap &> /dev/null; then
echo "${glmsg_021}"
snap install glab
if [ $? -eq 0 ]; then
echo "${glmsg_022}"
return 0
fi
fi
# Si dnf no está disponible, pero yum sí
elif command -v yum &> /dev/null; then
# Verificar si glab está disponible en los repositorios
echo "${glmsg_013}"
yum list glab &>/dev/null
if [ $? -eq 0 ]; then
echo "${glmsg_014}"
yum install -y glab
if [ $? -eq 0 ]; then
echo "${glmsg_015}"
return 0
fi
fi
fi
# Si los métodos anteriores fallan, probar con Homebrew
echo "${glmsg_018}"
install_glab_homebrew
return $?
}
# Función para instalar glab en Arch Linux
install_glab_arch() {
echo "${glmsg_023}"
# Intentar primero usando el repositorio oficial
if command -v pacman &> /dev/null; then
# Verificar si glab está en los repositorios
if pacman -Ss glab | grep -q "^community/glab"; then
pacman -Sy --noconfirm glab
if [ $? -eq 0 ]; then
echo "${glmsg_015}"
return 0
fi
fi
# Si no está en los repositorios, intentar con yay (AUR)
if command -v yay &> /dev/null; then
yay -S --noconfirm glab
if [ $? -eq 0 ]; then
echo "${glmsg_024}"
return 0
fi
fi
fi
# Si los métodos anteriores fallan, probar con Homebrew
echo "${glmsg_018}"
install_glab_homebrew
return $?
}
# Función para instalar glab en sistemas basados en SUSE
install_glab_suse() {
echo "${glmsg_025}"
# Intentar primero usando el script oficial
if command -v gpg &> /dev/null; then
echo "${glmsg_020}"
curl -s https://gitlab.com/gitlab-org/cli/-/raw/main/scripts/install.sh | bash
if [ $? -eq 0 ]; then
echo "${glmsg_017}"
return 0
fi
fi
# Si el método anterior falla, probar con snap
if command -v snap &> /dev/null; then
echo "${glmsg_021}"
snap install glab
if [ $? -eq 0 ]; then
echo "${glmsg_022}"
return 0
fi
fi
# Si los métodos anteriores fallan, probar con Homebrew
echo "${glmsg_018}"
install_glab_homebrew
return $?
}
# Función para instalar directamente usando Go
install_glab_go() {
echo "${glmsg_026}"
# Verificar si Go está instalado
if ! command -v go &> /dev/null; then
echo "${glmsg_027}"
return 1
fi
# Instalar GitLab CLI mediante Go
go install gitlab.com/gitlab-org/cli/cmd/glab@main
if [ $? -eq 0 ]; then
echo "${glmsg_028}"
echo "${glmsg_029}"
echo "${glmsg_030}"
echo "${glmsg_031}"
return 0
else
echo "${glmsg_032}"
return 1
fi
}
# Función para instalar usando método binario genérico
install_glab_binary() {
echo "${glmsg_033}"
# Crear directorio temporal
TMP_DIR=$(mktemp -d)
cd "$TMP_DIR" || return 1
# Detectar arquitectura
ARCH=$(uname -m)
case "$ARCH" in
x86_64)
ARCH="amd64"
;;
aarch64|arm64)
ARCH="arm64"
;;
*)
echo "${glmsg_034} $ARCH"
return 1
;;
esac
# Detectar sistema operativo
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
# Obtener la última versión
LATEST_VERSION=$(curl -s https://api.github.com/repos/profclems/glab/releases/latest | grep "tag_name" | cut -d'"' -f4)
if [ -z "$LATEST_VERSION" ]; then
LATEST_VERSION="v1.25.0" # Versión de respaldo si no se puede obtener la última
fi
# Construir URL de descarga
DOWNLOAD_URL="https://github.com/profclems/glab/releases/download/${LATEST_VERSION}/glab_${LATEST_VERSION:1}_${OS}_${ARCH}.tar.gz"
echo "${glmsg_035} $DOWNLOAD_URL"
# Descargar y extraer
curl -L "$DOWNLOAD_URL" -o glab.tar.gz
if [ $? -ne 0 ]; then
echo "${glmsg_036}"
cd - > /dev/null
rm -rf "$TMP_DIR"
return 1
fi
tar xzf glab.tar.gz
if [ $? -ne 0 ]; then
echo "${glmsg_037}"
cd - > /dev/null
rm -rf "$TMP_DIR"
return 1
fi
# Instalar binario
mv bin/glab /usr/local/bin/glab
chmod +x /usr/local/bin/glab
# Limpiar
cd - > /dev/null
rm -rf "$TMP_DIR"
# Verificar instalación
if command -v glab &> /dev/null; then
echo "${glmsg_038}"
return 0
else
echo "${glmsg_039}"
return 1
fi
}
# Función para verificar si glab está instalado
check_glab() {
if command -v glab &> /dev/null; then
echo "${glmsg_040}"
echo "${glmsg_041}"
glab --version
read -p "${glmsg_042} " REINSTALL
if [[ ! "$REINSTALL" =~ ^[Ss]$ ]]; then
echo "${glmsg_043}"
exit 0
fi
fi
}
# Función principal
main() {
# Verificar si ya está instalado
check_glab
# Verificar privilegios de root (excepto en macOS)
if [ "$(uname -s)" != "Darwin" ]; then
check_root "$@"
fi
# Detectar la distribución
detect_distro
# Intentar instalar según la distribución
install_success=false
case $DISTRO in
ubuntu|debian|linuxmint|pop|elementary|raspbian)
install_glab_debian
if [ $? -eq 0 ]; then
install_success=true
fi
;;
fedora|rhel|centos|rocky|almalinux)
install_glab_redhat
if [ $? -eq 0 ]; then
install_success=true
fi
;;
arch|manjaro|endeavouros)
install_glab_arch
if [ $? -eq 0 ]; then
install_success=true
fi
;;
opensuse*|suse|sles)
install_glab_suse
if [ $? -eq 0 ]; then
install_success=true
fi
;;
darwin)
install_glab_homebrew
if [ $? -eq 0 ]; then
install_success=true
fi
;;
*)
echo "${glmsg_044} $DISTRO"
echo "${glmsg_045}"
;;
esac
# Si no se pudo instalar con el método específico para la distribución, intentar métodos alternativos
if [ "$install_success" = false ]; then
echo "${glmsg_046}"
# Intentar instalar con Go
if command -v go &> /dev/null; then
install_glab_go
if [ $? -eq 0 ]; then
install_success=true
fi
fi
# Si aún no se ha instalado, probar con binarios precompilados
if [ "$install_success" = false ]; then
install_glab_binary
if [ $? -eq 0 ]; then
install_success=true
fi
fi
# Si todos los métodos fallan
if [ "$install_success" = false ]; then
echo "${glmsg_047}"
echo "${glmsg_048}"
exit 1
fi
fi
# Verificar la instalación
if command -v glab &> /dev/null; then
echo "${glmsg_049}"
glab --version
# Sugerir autenticación
echo ""
echo "${glmsg_050}"
echo "glab auth login"
echo ""
echo "${glmsg_051}"
else
echo "${glmsg_052}"
exit 1
fi
}
# Ejecutar función principal
main "$@"
exit 0
# Importar bibliotecas necesarias
source "${BIN_HOME}/${BIN_BASE}/${BIN_LIBS}/base.lib"
# Cargar mensajes en el idioma del sistema o español por defecto
load_messages "${BIN_HOME}/${BIN_BASE}" "${BIN_MESG}" "${BIN_LANG}" "head"
# Variables globales
title="${head_000} ${head_002}"

View file

@ -138,3 +138,58 @@ ghmsg_021="Para autenticarse con GitHub, ejecute:"
ghmsg_022="Para más información, visite: https://cli.github.com/manual/" ghmsg_022="Para más información, visite: https://cli.github.com/manual/"
ghmsg_023="ERROR: La instalación de GitHub CLI falló." ghmsg_023="ERROR: La instalación de GitHub CLI falló."
# Mensajes para gladmin_install.sh
glmsg_000="INSTALADOR DE GITLAB CLI"
glmsg_001="Este script requiere privilegios de administrador."
glmsg_002="Intentando escalar privilegios..."
glmsg_003="Usando sudo para escalar privilegios..."
glmsg_004="Usando doas para escalar privilegios..."
glmsg_005="ERROR: No se encontró sudo ni doas. Por favor ejecute este script como root."
glmsg_006="Distribución detectada:"
glmsg_007="Instalando GitLab CLI mediante Homebrew..."
glmsg_008="Homebrew no está instalado. Instalando Homebrew..."
glmsg_009="ERROR: No se pudo instalar Homebrew."
glmsg_010="GitLab CLI instalado correctamente mediante Homebrew."
glmsg_011="ERROR: No se pudo instalar GitLab CLI mediante Homebrew."
glmsg_012="Instalando GitLab CLI en sistema basado en Debian/Ubuntu..."
glmsg_013="Verificando si glab está disponible en los repositorios..."
glmsg_014="GitLab CLI encontrado en los repositorios. Instalando..."
glmsg_015="GitLab CLI instalado correctamente desde los repositorios oficiales."
glmsg_016="Agregando repositorio oficial de GitLab..."
glmsg_017="GitLab CLI instalado correctamente mediante script oficial."
glmsg_018="Intentando instalar mediante Homebrew..."
glmsg_019="Instalando GitLab CLI en sistema basado en Red Hat/Fedora..."
glmsg_020="Usando script oficial de instalación..."
glmsg_021="Intentando instalar mediante snap..."
glmsg_022="GitLab CLI instalado correctamente mediante snap."
glmsg_023="Instalando GitLab CLI en Arch Linux..."
glmsg_024="GitLab CLI instalado correctamente desde AUR."
glmsg_025="Instalando GitLab CLI en sistema basado en SUSE..."
glmsg_026="Intentando instalar GitLab CLI mediante Go..."
glmsg_027="Go no está instalado. Se requiere Go para este método de instalación."
glmsg_028="GitLab CLI instalado correctamente mediante Go."
glmsg_029="Asegúrese de que $GOPATH/bin esté en su PATH."
glmsg_030="Por ejemplo, puede agregar lo siguiente a su ~/.bashrc o ~/.zshrc:"
glmsg_031="export PATH=$PATH:$HOME/go/bin"
glmsg_032="ERROR: No se pudo instalar GitLab CLI mediante Go."
glmsg_033="Instalando GitLab CLI usando binarios precompilados..."
glmsg_034="Arquitectura no soportada:"
glmsg_035="Descargando GitLab CLI desde:"
glmsg_036="ERROR: No se pudo descargar GitLab CLI."
glmsg_037="ERROR: No se pudo extraer el archivo de GitLab CLI."
glmsg_038="GitLab CLI instalado correctamente mediante binarios precompilados."
glmsg_039="ERROR: No se pudo instalar GitLab CLI mediante binarios precompilados."
glmsg_040="GitLab CLI ya está instalado."
glmsg_041="Versión actual:"
glmsg_042="¿Desea reinstalar o actualizar? (s/n):"
glmsg_043="Operación cancelada."
glmsg_044="Distribución no soportada directamente:"
glmsg_045="Intentando métodos alternativos..."
glmsg_046="Intentando métodos alternativos de instalación..."
glmsg_047="No se pudo instalar GitLab CLI con ninguno de los métodos disponibles."
glmsg_048="Por favor, visite https://gitlab.com/gitlab-org/cli para instrucciones de instalación manual."
glmsg_049="GitLab CLI instalado correctamente."
glmsg_050="Para autenticarse con GitLab, ejecute:"
glmsg_051="Para más información, visite: https://gitlab.com/gitlab-org/cli/blob/main/docs/index.md"
glmsg_052="ERROR: La instalación de GitLab CLI falló."