- Actualizar scripts con estructura de cabecera estandarizada - Renombrar cortana_install.sh a claude_install.sh - Agregar cortana_unalias.sh para facilitar la gestión de alias - Mejorar manejo de rutas usando SCRIPT_DIR para determinar ubicaciones - Usar variables de configuración consistentes en todos los scripts - Implementar carga de mensajes estandarizada en todos los scripts - Agregar limpieza de consola al finalizar la mayoría de scripts - Eliminar scripts obsoletos y redundantes 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
175 lines
5.4 KiB
Bash
Executable file
175 lines
5.4 KiB
Bash
Executable file
#!/bin/bash
|
|
#
|
|
# Script: cortana_token.sh
|
|
# Description: Script para encriptar el token de Claude Code usando SOPS
|
|
# Created: 2025/03/12 20:26:07
|
|
# Modified: 2025/03/19 11:57:08
|
|
# [Author] Mauro Rosero P. <mauro@rosero.one>
|
|
#
|
|
# 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/>.
|
|
|
|
# Script para encriptar el token de Cortana (Claude Code) para Cortana usando SOPS
|
|
# Cortana Token se utiliza para la agente Cortana que es la asistente para los desarrolladores
|
|
|
|
# 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/$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")
|
|
|
|
# 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"
|
|
title="${head_000} ${head_002}"
|
|
|
|
check_dependencies() {
|
|
# Verificar que 'dialog' esté instalado
|
|
if ! command -v dialog &>/dev/null; then
|
|
echo "${npm_001}"
|
|
exit 1
|
|
fi
|
|
|
|
# Verificar que 'sops' esté instalado
|
|
if ! command -v sops &>/dev/null; then
|
|
dialog --backtitle "$title" --title "${head_error}" --msgbox "${npm_051}" 7 50
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
encrypt_token() {
|
|
local sops_file="$1"
|
|
local token="$2"
|
|
local token_file="/tmp/cortana_token_$$"
|
|
local output_file="${HOME}/.cortana/cortana.sops.yaml"
|
|
|
|
# Ensure directory exists
|
|
mkdir -p "${HOME}/.cortana"
|
|
|
|
# Convert token to base64
|
|
local token_base64=$(echo -n "$token" | base64)
|
|
|
|
# Create temporary file with base64 encoded token
|
|
echo "$token_base64" > "$token_file"
|
|
|
|
# Encrypt using sops
|
|
if sops --encrypt "$token_file" > "$output_file"; then
|
|
# Ensure secure permissions
|
|
chmod 600 "$output_file"
|
|
else
|
|
rm -f "$token_file"
|
|
return 1
|
|
fi
|
|
|
|
# Clean up
|
|
rm -f "$token_file"
|
|
return 0
|
|
}
|
|
|
|
main() {
|
|
check_dependencies
|
|
|
|
# Ensure directory exists
|
|
mkdir -p "${HOME}/.cortana"
|
|
|
|
# Get SOPS config file path
|
|
sops_file=$(dialog --backtitle "$title" --stdout --title "${npm_052}" \
|
|
--fselect "$HOME/.cortana/cortana.sops.yaml" 8 60)
|
|
|
|
# Check if user canceled
|
|
if [ $? -ne 0 ]; then
|
|
clear
|
|
dialog --backtitle "$title" --title "${head_canceled}" --msgbox "${npm_008}" 6 40
|
|
exit 0
|
|
fi
|
|
|
|
# Check if file exists and ask for confirmation to overwrite
|
|
if [ -f "$sops_file" ]; then
|
|
dialog --backtitle "$title" --title "${npm_031}" \
|
|
--yesno "El archivo $sops_file ${npm_053}" 7 60
|
|
|
|
if [ $? -ne 0 ]; then
|
|
clear
|
|
dialog --backtitle "$title" --title "${head_canceled}" --msgbox "${npm_008}" 6 40
|
|
exit 0
|
|
fi
|
|
fi
|
|
|
|
# Get Cortana token
|
|
while true; do
|
|
token=$(dialog --backtitle "$title" --stdout --title "${npm_000} Token" \
|
|
--passwordbox "${npm_054} ${npm_000}:" 8 60)
|
|
|
|
# Check if user canceled
|
|
if [ $? -ne 0 ]; then
|
|
clear
|
|
dialog --backtitle "$title" --title "${head_canceled}" --msgbox "${npm_008}" 6 40
|
|
exit 0
|
|
fi
|
|
|
|
# Validate token
|
|
if [ -z "$token" ]; then
|
|
dialog --backtitle "$title" --title "${head_error}" --msgbox "${npm_055}" 7 60
|
|
continue
|
|
fi
|
|
|
|
# Check token length (should be at least 64 characters)
|
|
if [ ${#token} -lt 64 ]; then
|
|
dialog --backtitle "$title" --title "${head_error}" --msgbox "${npm_056}" 7 60
|
|
continue
|
|
fi
|
|
|
|
# Check token format (should contain alphanumeric characters and some special chars)
|
|
if ! [[ "$token" =~ ^[A-Za-z0-9\#\-\_\.]+$ ]]; then
|
|
dialog --backtitle "$title" --title "${head_warning}" --msgbox "${npm_057}" 7 60
|
|
fi
|
|
|
|
# Token is valid
|
|
break
|
|
done
|
|
|
|
# Clear screen before proceeding
|
|
clear
|
|
|
|
# Encrypt the token
|
|
if encrypt_token "$sops_file" "$token"; then
|
|
dialog --backtitle "$title" --title "${npm_014}" --msgbox "${npm_058} ${HOME}/.cortana/cortana.sops.yaml" 7 70
|
|
else
|
|
dialog --backtitle "$title" --title "${head_error}" --msgbox "${npm_059}" 7 50
|
|
clear
|
|
exit 1
|
|
fi
|
|
}
|
|
|
|
# Execute main function
|
|
main
|
|
exit 0
|