[IMPROVED] Agregar mensajes i18n para ghadmin_install.sh
- Añadir mensajes i18n con prefijo ghmsg_ para GitHub CLI installer - Implementar variables de mensajes localizados en todo el script - Mantener consistencia con el estilo de otros scripts 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
31735062c2
commit
1b4993ea4b
2 changed files with 292 additions and 0 deletions
266
bin/ghadmin_install.sh
Executable file
266
bin/ghadmin_install.sh
Executable file
|
@ -0,0 +1,266 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Script: ghadmin_install.sh
|
||||
# Description: Script para instalar github 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="${ghmsg_000}"
|
||||
|
||||
# Función para verificar si se está ejecutando como root
|
||||
check_root() {
|
||||
if [ "$(id -u)" -ne 0 ]; then
|
||||
echo "${ghmsg_001}"
|
||||
echo "${ghmsg_002}"
|
||||
|
||||
# Verificar si sudo está disponible
|
||||
if command -v sudo &> /dev/null; then
|
||||
echo "${ghmsg_003}"
|
||||
sudo "$0" "$@"
|
||||
exit $?
|
||||
elif command -v doas &> /dev/null; then
|
||||
echo "${ghmsg_004}"
|
||||
doas "$0" "$@"
|
||||
exit $?
|
||||
else
|
||||
echo "${ghmsg_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 "${ghmsg_006} $DISTRO"
|
||||
}
|
||||
|
||||
# Función para instalar GitHub CLI en sistemas basados en Debian/Ubuntu
|
||||
install_gh_debian() {
|
||||
echo "${ghmsg_007}"
|
||||
|
||||
# Añadir repositorio de GitHub CLI
|
||||
type -p curl >/dev/null || apt update && apt install curl -y
|
||||
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \
|
||||
&& chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \
|
||||
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | tee /etc/apt/sources.list.d/github-cli.list > /dev/null \
|
||||
&& apt update \
|
||||
&& apt install gh -y
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "${ghmsg_008}"
|
||||
else
|
||||
echo "${ghmsg_009}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Función para instalar GitHub CLI en sistemas basados en Red Hat/Fedora
|
||||
install_gh_redhat() {
|
||||
echo "${ghmsg_010}"
|
||||
|
||||
# Añadir repositorio de GitHub CLI
|
||||
dnf install -y dnf-plugins-core
|
||||
dnf config-manager --add-repo https://cli.github.com/packages/rpm/gh-cli.repo
|
||||
dnf install -y gh
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "${ghmsg_008}"
|
||||
else
|
||||
echo "${ghmsg_009}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Función para instalar GitHub CLI en Arch Linux
|
||||
install_gh_arch() {
|
||||
echo "${ghmsg_011}"
|
||||
|
||||
# Instalar GitHub CLI desde los repositorios oficiales
|
||||
pacman -Sy --noconfirm gh
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "${ghmsg_008}"
|
||||
else
|
||||
echo "${ghmsg_009}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Función para instalar GitHub CLI en sistemas basados en SUSE
|
||||
install_gh_suse() {
|
||||
echo "${ghmsg_012}"
|
||||
|
||||
# Añadir repositorio de GitHub CLI
|
||||
zypper addrepo --refresh https://cli.github.com/packages/rpm/gh-cli.repo
|
||||
zypper install -y gh
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "${ghmsg_008}"
|
||||
else
|
||||
echo "${ghmsg_009}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Función para instalar GitHub CLI en macOS
|
||||
install_gh_macos() {
|
||||
echo "${ghmsg_013}"
|
||||
|
||||
# Verificar si Homebrew está instalado
|
||||
if ! command -v brew &> /dev/null; then
|
||||
echo "${ghmsg_014}"
|
||||
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||
fi
|
||||
|
||||
# Instalar GitHub CLI
|
||||
brew install gh
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "${ghmsg_008}"
|
||||
else
|
||||
echo "${ghmsg_009}"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Función para verificar si gh está instalado
|
||||
check_gh() {
|
||||
if command -v gh &> /dev/null; then
|
||||
echo "${ghmsg_015}"
|
||||
echo "${ghmsg_016}"
|
||||
gh --version
|
||||
read -p "${ghmsg_017} " REINSTALL
|
||||
if [[ ! "$REINSTALL" =~ ^[Ss]$ ]]; then
|
||||
echo "${ghmsg_018}"
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
}
|
||||
|
||||
# Función principal
|
||||
main() {
|
||||
# Verificar si ya está instalado
|
||||
check_gh
|
||||
|
||||
# Verificar privilegios de root (excepto en macOS)
|
||||
if [ "$(uname -s)" != "Darwin" ]; then
|
||||
check_root "$@"
|
||||
fi
|
||||
|
||||
# Detectar la distribución
|
||||
detect_distro
|
||||
|
||||
# Instalar según la distribución
|
||||
case $DISTRO in
|
||||
ubuntu|debian|linuxmint|pop|elementary)
|
||||
install_gh_debian
|
||||
;;
|
||||
fedora|rhel|centos|rocky|almalinux)
|
||||
install_gh_redhat
|
||||
;;
|
||||
arch|manjaro|endeavouros)
|
||||
install_gh_arch
|
||||
;;
|
||||
opensuse*|suse|sles)
|
||||
install_gh_suse
|
||||
;;
|
||||
darwin)
|
||||
install_gh_macos
|
||||
;;
|
||||
*)
|
||||
echo "${ghmsg_019} $DISTRO"
|
||||
echo "${ghmsg_020}"
|
||||
exit 1
|
||||
;;
|
||||
esac
|
||||
|
||||
# Verificar la instalación
|
||||
if command -v gh &> /dev/null; then
|
||||
echo "${ghmsg_008}"
|
||||
gh --version
|
||||
|
||||
# Sugerir autenticación
|
||||
echo ""
|
||||
echo "${ghmsg_021}"
|
||||
echo "gh auth login"
|
||||
echo ""
|
||||
echo "${ghmsg_022}"
|
||||
else
|
||||
echo "${ghmsg_023}"
|
||||
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}"
|
|
@ -112,3 +112,29 @@ fgmsg_013="Cerrando sesión de Forgejo..."
|
|||
fgmsg_014="No hay sesión activa en Forgejo."
|
||||
fgmsg_015="Sesión cerrada."
|
||||
|
||||
# Mensajes para ghadmin_install.sh
|
||||
ghmsg_000="INSTALADOR DE GITHUB CLI"
|
||||
ghmsg_001="Este script requiere privilegios de administrador."
|
||||
ghmsg_002="Intentando escalar privilegios..."
|
||||
ghmsg_003="Usando sudo para escalar privilegios..."
|
||||
ghmsg_004="Usando doas para escalar privilegios..."
|
||||
ghmsg_005="ERROR: No se encontró sudo ni doas. Por favor ejecute este script como root."
|
||||
ghmsg_006="Distribución detectada:"
|
||||
ghmsg_007="Instalando GitHub CLI en sistema basado en Debian/Ubuntu..."
|
||||
ghmsg_008="GitHub CLI instalado correctamente."
|
||||
ghmsg_009="ERROR: No se pudo instalar GitHub CLI."
|
||||
ghmsg_010="Instalando GitHub CLI en sistema basado en Red Hat/Fedora..."
|
||||
ghmsg_011="Instalando GitHub CLI en Arch Linux..."
|
||||
ghmsg_012="Instalando GitHub CLI en sistema basado en SUSE..."
|
||||
ghmsg_013="Instalando GitHub CLI en macOS..."
|
||||
ghmsg_014="Homebrew no está instalado. Instalando Homebrew..."
|
||||
ghmsg_015="GitHub CLI ya está instalado."
|
||||
ghmsg_016="Versión actual:"
|
||||
ghmsg_017="¿Desea reinstalar o actualizar? (s/n):"
|
||||
ghmsg_018="Operación cancelada."
|
||||
ghmsg_019="Distribución no soportada:"
|
||||
ghmsg_020="Por favor, visite https://github.com/cli/cli#installation para instrucciones de instalación manual."
|
||||
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ó."
|
||||
|
||||
|
|
Loading…
Reference in a new issue