#!/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 # [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="${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}" clear 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}" clear 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}" clear 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}" clear 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}" clear 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}" clear exit 1 fi } # Función para verificar si gh está instalado check_gh() { if command -v gh &> /dev/null; then # Mostrar versión actual local current_version=$(gh --version | head -n 1) # Preguntar si se desea reinstalar o actualizar usando dialog dialog_yesno "${ghmsg_015}\n${ghmsg_016}\n${current_version}\n\n${ghmsg_017}" if [ $? -ne 0 ]; then dialog_error_box "${head_info}" "${ghmsg_018}" exit 0 fi fi } # Función principal main() { # Verificar que 'dialog' esté instalado if ! command -v dialog &>/dev/null; then echo "${head_001}" exit 1 fi # 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 ;; *) dialog_error_box "${head_error}" "${ghmsg_019} $DISTRO\n\n${ghmsg_020}" exit 1 ;; esac # Verificar la instalación if command -v gh &> /dev/null; then local current_version=$(gh --version | head -n 1) # Mostrar mensaje de éxito y sugerir autenticación usando dialog dialog_error_box "${head_success}" "${ghmsg_008}\n\n${current_version}\n\n${ghmsg_021}\ngh auth login\n\n${ghmsg_022}" else dialog_error_box "${head_error}" "${ghmsg_023}" exit 1 fi clear } # Ejecutar función principal main "$@" exit 0