#!/bin/bash # # Script: jarvis_token.sh # Description: Script para encriptar el Jarvis token de Claude Code usando SOPS # Created: 2025/03/12 20:26:07 # Modified: 2025/03/19 11:57:08 # [Author] Mauro Rosero P. # # 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 . # Script para encriptar el token de Cortana (Claude Code) para Cortana usando SOPS # Jarvis Token se usa para el agente Jarvis a nivel de servidor de desarrollo autonomo # 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" BIN_SOPS="sops" # 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 output_file="$1" local token="$2" local token_file="/tmp/jarvis_token_$$" # Ensure directory exists mkdir -p "${BIN_HOME}/${BIN_SOPS}" # 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 "${BIN_HOME}/${BIN_SOPS}" # Get SOPS config file path sops_file="${BIN_HOME}/${BIN_SOPS}/jarvis.sops.yaml" # 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 dialog --backtitle "$title" --title "${head_canceled}" --msgbox "${npm_008}" 6 40 clear exit 0 fi fi # Get Jarvis token while true; do token=$(dialog --backtitle "$title" --stdout --title "${npm_000_0} Token" \ --passwordbox "${npm_054} ${npm_000_0}:" 8 60) # Check if user canceled if [ $? -ne 0 ]; then clear dialog --backtitle "$title" --title "${head_canceled}" --msgbox "${npm_008}" 6 40 clear 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} $sops_file" 7 70 else dialog --backtitle "$title" --title "${head_error}" --msgbox "${npm_059}" 7 50 clear exit 1 fi } # Execute main function main clear exit 0