[ADDED] Script github_login.sh para autenticación con GitHub CLI
🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
29da09b48d
commit
51e681bd2c
1 changed files with 127 additions and 0 deletions
127
bin/github_login.sh
Executable file
127
bin/github_login.sh
Executable file
|
@ -0,0 +1,127 @@
|
|||
#!/bin/bash
|
||||
#Script : github_login.sh
|
||||
#Apps : MRDEVS TOOLS
|
||||
#Description : Conectar con GitHub usando tokens encriptado
|
||||
#Author : Cortana Rosero One <cortana@rosero.one>
|
||||
#Generated by : Claude Code (claude-3-7-sonnet-20250219)
|
||||
#Created : 2025/03/20 10:58:42
|
||||
#Modified : 2025/03/20 11:01:35
|
||||
#Version : 1.0.0
|
||||
#Use Notes :
|
||||
#==============================================================================
|
||||
# Derechos de Autor [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
|
||||
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/$BIN_CFGS/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")
|
||||
BIN_PATH=$BIN_HOME/$BIN_BASE
|
||||
|
||||
# CHECK SHELL LANGUAGE
|
||||
BIN_LANG=${LANG:0:2}
|
||||
|
||||
# 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"
|
||||
load_messages "${BIN_HOME}/${BIN_BASE}" "${BIN_MESG}" "${BIN_LANG}" "developers"
|
||||
|
||||
# Variables globales
|
||||
title="${head_000} INICIO DE SESIÓN EN GITHUB"
|
||||
|
||||
# Función para verificar si gh está instalado
|
||||
check_gh_installed() {
|
||||
if ! command -v gh &> /dev/null; then
|
||||
echo "Error: gh (GitHub CLI) no está instalado."
|
||||
echo "Por favor, ejecute ${BIN_HOME}/${BIN_BASE}/ghadmin_install.sh primero."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Función para verificar si SOPS está instalado
|
||||
check_sops_installed() {
|
||||
if ! command -v sops &> /dev/null; then
|
||||
echo "Error: SOPS no está instalado."
|
||||
echo "Por favor, ejecute bin/bootstrap.sh para instalar las herramientas necesarias."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
||||
# Función para iniciar sesión con token
|
||||
login() {
|
||||
# Verificar que el archivo de token encriptado existe
|
||||
if [ ! -f "${DEVELOPER_DIR}/github.sops.yaml" ]; then
|
||||
echo "Error: No se encontró el archivo de token para GitHub."
|
||||
echo "Por favor, ejecute bin/cversadm_token.sh para configurar el token primero."
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Decodificar el token de base64
|
||||
local token=$(sops -d ${DEVELOPER_DIR}/github.sops.yaml | grep -oP '(?<=token: ).*' | base64 -d)
|
||||
|
||||
# Iniciar sesión con gh
|
||||
echo "Iniciando sesión en GitHub..."
|
||||
echo "$token" | gh auth login --with-token
|
||||
local login_status=$?
|
||||
|
||||
if [ $login_status -eq 0 ]; then
|
||||
echo "Sesión iniciada correctamente en GitHub."
|
||||
else
|
||||
echo "Error al iniciar sesión en GitHub. Por favor, verifique su token."
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Función para cerrar sesión
|
||||
logout() {
|
||||
echo "Cerrando sesión de GitHub..."
|
||||
if ! gh auth status &>/dev/null; then
|
||||
echo "No hay sesión activa en GitHub."
|
||||
else
|
||||
gh auth logout -h github.com
|
||||
echo "Sesión cerrada."
|
||||
fi
|
||||
}
|
||||
|
||||
# Función principal
|
||||
main() {
|
||||
# Verificar requisitos
|
||||
check_gh_installed
|
||||
check_sops_installed
|
||||
|
||||
# Verificar parámetros
|
||||
if [ "$1" = "--logout" ]; then
|
||||
logout
|
||||
else
|
||||
login
|
||||
fi
|
||||
}
|
||||
|
||||
# Ejecutar función principal con los parámetros recibidos
|
||||
main "$@"
|
Loading…
Reference in a new issue