From 4b38ced4c11cd836360ac1b7c42e736cd2c5c8ef Mon Sep 17 00:00:00 2001 From: "Mauro Rosero P." Date: Fri, 14 Mar 2025 10:03:50 -0500 Subject: [PATCH] [ADDED] Script instalador de GitHub CLI con escalamiento de privilegios MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 馃 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- bin/ghcli_install.sh | 212 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 212 insertions(+) create mode 100755 bin/ghcli_install.sh diff --git a/bin/ghcli_install.sh b/bin/ghcli_install.sh new file mode 100755 index 0000000..b840741 --- /dev/null +++ b/bin/ghcli_install.sh @@ -0,0 +1,212 @@ +#!/bin/bash +# ------------------------------------------------------------------ +# [Author] Cortana Rosero One +# [Title] ghcli_install.sh - Instalador de GitHub CLI +# [Generated] Created by Claude Code (claude-3-7-sonnet-20250219) +# +# AGPL License +# Modified date: 14/03/2025 +# ------------------------------------------------------------------ + +# Funci贸n para verificar si se est谩 ejecutando como root +check_root() { + if [ "$(id -u)" -ne 0 ]; then + echo "Este script requiere privilegios de administrador." + echo "Intentando escalar privilegios..." + + # Verificar si sudo est谩 disponible + if command -v sudo &> /dev/null; then + echo "Usando sudo para escalar privilegios..." + sudo "$0" "$@" + exit $? + elif command -v doas &> /dev/null; then + echo "Usando doas para escalar privilegios..." + doas "$0" "$@" + exit $? + else + echo "ERROR: No se encontr贸 sudo ni doas. Por favor ejecute este script como root." + 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 "Distribuci贸n detectada: $DISTRO" +} + +# Funci贸n para instalar GitHub CLI en sistemas basados en Debian/Ubuntu +install_gh_debian() { + echo "Instalando GitHub CLI en sistema basado en Debian/Ubuntu..." + + # 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 "GitHub CLI instalado correctamente." + else + echo "ERROR: No se pudo instalar GitHub CLI." + exit 1 + fi +} + +# Funci贸n para instalar GitHub CLI en sistemas basados en Red Hat/Fedora +install_gh_redhat() { + echo "Instalando GitHub CLI en sistema basado en Red Hat/Fedora..." + + # 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 "GitHub CLI instalado correctamente." + else + echo "ERROR: No se pudo instalar GitHub CLI." + exit 1 + fi +} + +# Funci贸n para instalar GitHub CLI en Arch Linux +install_gh_arch() { + echo "Instalando GitHub CLI en Arch Linux..." + + # Instalar GitHub CLI desde los repositorios oficiales + pacman -Sy --noconfirm gh + + if [ $? -eq 0 ]; then + echo "GitHub CLI instalado correctamente." + else + echo "ERROR: No se pudo instalar GitHub CLI." + exit 1 + fi +} + +# Funci贸n para instalar GitHub CLI en sistemas basados en SUSE +install_gh_suse() { + echo "Instalando GitHub CLI en sistema basado en SUSE..." + + # 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 "GitHub CLI instalado correctamente." + else + echo "ERROR: No se pudo instalar GitHub CLI." + exit 1 + fi +} + +# Funci贸n para instalar GitHub CLI en macOS +install_gh_macos() { + echo "Instalando GitHub CLI en macOS..." + + # Verificar si Homebrew est谩 instalado + if ! command -v brew &> /dev/null; then + echo "Homebrew no est谩 instalado. Instalando Homebrew..." + /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 "GitHub CLI instalado correctamente." + else + echo "ERROR: No se pudo instalar GitHub CLI." + exit 1 + fi +} + +# Funci贸n para verificar si gh est谩 instalado +check_gh() { + if command -v gh &> /dev/null; then + echo "GitHub CLI ya est谩 instalado." + echo "Versi贸n actual:" + gh --version + read -p "驴Desea reinstalar o actualizar? (s/n): " REINSTALL + if [[ ! "$REINSTALL" =~ ^[Ss]$ ]]; then + echo "Operaci贸n cancelada." + 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 "Distribuci贸n no soportada: $DISTRO" + echo "Por favor, visite https://github.com/cli/cli#installation para instrucciones de instalaci贸n manual." + exit 1 + ;; + esac + + # Verificar la instalaci贸n + if command -v gh &> /dev/null; then + echo "GitHub CLI instalado correctamente." + gh --version + + # Sugerir autenticaci贸n + echo "" + echo "Para autenticarse con GitHub, ejecute:" + echo "gh auth login" + echo "" + echo "Para m谩s informaci贸n, visite: https://cli.github.com/manual/" + else + echo "ERROR: La instalaci贸n de GitHub CLI fall贸." + exit 1 + fi +} + +# Ejecutar funci贸n principal +main "$@" + +exit 0 \ No newline at end of file