From f415e54d34787605815d29460d834f918125441e Mon Sep 17 00:00:00 2001 From: "Mauro Rosero P." Date: Wed, 19 Mar 2025 17:51:04 -0500 Subject: [PATCH] [IMPROVED] Agregar mensajes i18n para gladmin_install.sh MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 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 --- bin/gladmin_install.sh | 504 +++++++++++++++++++++++++++++++++++++++++ bin/msg/developers.es | 55 +++++ 2 files changed, 559 insertions(+) create mode 100755 bin/gladmin_install.sh diff --git a/bin/gladmin_install.sh b/bin/gladmin_install.sh new file mode 100755 index 0000000..0e43f91 --- /dev/null +++ b/bin/gladmin_install.sh @@ -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 +# [Generated] Created by Claude Code (claude-3-7-sonnet-20250219) +# +# Derechos de Autor (C) [2025] [Mauro Rosero P. ] +# +# 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 . + +# 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}" diff --git a/bin/msg/developers.es b/bin/msg/developers.es index 334d749..fa9f510 100644 --- a/bin/msg/developers.es +++ b/bin/msg/developers.es @@ -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_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贸." +