#!/bin/bash # Setup rápido para asistentes - Rust Meetup 2025 # Instala ambiente demo del sistema de provisioning set -euo pipefail # Colores para output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' BLUE='\033[0;34m' NC='\033[0m' # No Color # Variables de configuración DEMO_DIR="$HOME/provisioning-demo" REPO_URL="https://github.com/JesusPerezLorenzo/provisioning.git" NUSHELL_VERSION="0.105.2" KCL_VERSION="0.11.2" log() { echo -e "${GREEN}[$(date +'%H:%M:%S')]${NC} $1" } warn() { echo -e "${YELLOW}[$(date +'%H:%M:%S')] WARN:${NC} $1" } error() { echo -e "${RED}[$(date +'%H:%M:%S')] ERROR:${NC} $1" exit 1 } banner() { echo -e "${BLUE}" echo "╔══════════════════════════════════════════════════════════════╗" echo "║ Cloud Native Provisioning Demo ║" echo "║ Rust Meetup 2025 ║" echo "╚══════════════════════════════════════════════════════════════╝" echo -e "${NC}" } check_requirements() { log "Verificando requisitos del sistema..." # Check OS if [[ "$OSTYPE" == "linux-gnu"* ]]; then OS="linux" elif [[ "$OSTYPE" == "darwin"* ]]; then OS="macos" elif [[ "$OSTYPE" == "msys" ]]; then OS="windows" warn "Windows detectado. Se recomienda usar WSL2." else error "Sistema operativo no soportado: $OSTYPE" fi log "Sistema operativo detectado: $OS" # Check architecture ARCH=$(uname -m) case $ARCH in x86_64) RUST_TARGET="x86_64-unknown-linux-gnu" ;; aarch64|arm64) RUST_TARGET="aarch64-unknown-linux-gnu" ;; *) warn "Arquitectura $ARCH puede no estar completamente soportada" RUST_TARGET="x86_64-unknown-linux-gnu" ;; esac log "Arquitectura detectada: $ARCH → $RUST_TARGET" # Check available space AVAILABLE_SPACE=$(df -h . | awk 'NR==2 {print $4}' | sed 's/[^0-9]//g') if [[ $AVAILABLE_SPACE -lt 2000 ]]; then warn "Espacio disponible bajo. Se recomiendan al menos 2GB libres." fi # Check required tools log "Verificando herramientas requeridas..." if ! command -v git &> /dev/null; then error "Git no encontrado. Por favor instalar git primero." fi if ! command -v curl &> /dev/null; then error "curl no encontrado. Por favor instalar curl primero." fi log "✅ Requisitos básicos satisfechos" } install_rust() { if command -v rustc &> /dev/null; then local rust_version=$(rustc --version | cut -d' ' -f2) log "Rust ya instalado: v$rust_version" return 0 fi log "Instalando Rust..." curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y source ~/.cargo/env # Add cross-compilation target rustup target add "$RUST_TARGET" log "✅ Rust instalado correctamente" } install_nushell() { if command -v nu &> /dev/null; then local nu_version=$(nu --version | head -n1 | cut -d' ' -f2) log "Nushell ya instalado: v$nu_version" return 0 fi log "Instalando Nushell $NUSHELL_VERSION..." case $OS in "linux") if [[ $ARCH == "x86_64" ]]; then NUSHELL_URL="https://github.com/nushell/nushell/releases/download/$NUSHELL_VERSION/nu-$NUSHELL_VERSION-x86_64-linux-gnu.tar.gz" elif [[ $ARCH == "aarch64" ]]; then NUSHELL_URL="https://github.com/nushell/nushell/releases/download/$NUSHELL_VERSION/nu-$NUSHELL_VERSION-aarch64-linux-gnu.tar.gz" fi ;; "macos") if [[ $ARCH == "x86_64" ]]; then NUSHELL_URL="https://github.com/nushell/nushell/releases/download/$NUSHELL_VERSION/nu-$NUSHELL_VERSION-x86_64-apple-darwin.tar.gz" elif [[ $ARCH == "arm64" ]]; then NUSHELL_URL="https://github.com/nushell/nushell/releases/download/$NUSHELL_VERSION/nu-$NUSHELL_VERSION-aarch64-apple-darwin.tar.gz" fi ;; esac # Download and install TMP_DIR=$(mktemp -d) cd "$TMP_DIR" curl -L "$NUSHELL_URL" | tar xz # Find the extracted directory NU_DIR=$(find . -name "nu-$NUSHELL_VERSION-*" -type d | head -n1) # Install to user local bin mkdir -p "$HOME/.local/bin" cp "$NU_DIR/nu" "$HOME/.local/bin/" # Add to PATH if not already there if [[ ":$PATH:" != *":$HOME/.local/bin:"* ]]; then echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.zshrc 2>/dev/null || true export PATH="$HOME/.local/bin:$PATH" fi cd - > /dev/null rm -rf "$TMP_DIR" log "✅ Nushell $NUSHELL_VERSION instalado" } install_kcl() { if command -v kcl &> /dev/null; then local kcl_version=$(kcl --version | cut -d' ' -f3) log "KCL ya instalado: v$kcl_version" return 0 fi log "Instalando KCL $KCL_VERSION..." case $OS in "linux") KCL_URL="https://github.com/kcl-lang/kcl/releases/download/v$KCL_VERSION/kcl-v$KCL_VERSION-linux-amd64.tar.gz" ;; "macos") if [[ $ARCH == "arm64" ]]; then KCL_URL="https://github.com/kcl-lang/kcl/releases/download/v$KCL_VERSION/kcl-v$KCL_VERSION-darwin-arm64.tar.gz" else KCL_URL="https://github.com/kcl-lang/kcl/releases/download/v$KCL_VERSION/kcl-v$KCL_VERSION-darwin-amd64.tar.gz" fi ;; esac TMP_DIR=$(mktemp -d) cd "$TMP_DIR" curl -L "$KCL_URL" | tar xz mkdir -p "$HOME/.local/bin" cp bin/kcl* "$HOME/.local/bin/" cd - > /dev/null rm -rf "$TMP_DIR" log "✅ KCL $KCL_VERSION instalado" } install_docker() { if command -v docker &> /dev/null; then log "Docker ya instalado" return 0 fi log "Instalando Docker..." case $OS in "linux") # Install Docker using official script curl -fsSL https://get.docker.com -o get-docker.sh sh get-docker.sh # Add user to docker group sudo usermod -aG docker "$USER" # Start Docker service sudo systemctl start docker sudo systemctl enable docker rm get-docker.sh ;; "macos") warn "Por favor instalar Docker Desktop desde: https://www.docker.com/products/docker-desktop" warn "Presiona Enter cuando Docker esté instalado y funcionando..." read -r ;; esac log "✅ Docker configurado" } setup_demo_environment() { log "Configurando ambiente demo..." # Create demo directory mkdir -p "$DEMO_DIR" cd "$DEMO_DIR" # Clone repository if [[ ! -d "provisioning" ]]; then log "Clonando repositorio..." git clone "$REPO_URL" provisioning else log "Repositorio ya existe, actualizando..." cd provisioning git pull origin main cd .. fi cd provisioning # Setup environment variables log "Configurando variables de entorno..." cat > "$DEMO_DIR/demo-env.sh" << EOF #!/bin/bash # Demo environment configuration export DEMO_DIR="$DEMO_DIR" export PROVISIONING_PATH="\$DEMO_DIR/provisioning" export PROVISIONING_DEMO=true # Add tools to PATH export PATH="\$HOME/.local/bin:\$PATH" # Demo-specific settings export PROVISIONING_INFRA_PATH="\$DEMO_DIR/infra" export PROVISIONING_OUT="human" export PROVISIONING_DEBUG=false echo "🎯 Ambiente demo configurado" echo "📁 Demo directory: \$DEMO_DIR" echo "🛠️ Provisioning path: \$PROVISIONING_PATH" echo "" echo "Para usar el sistema:" echo " cd \$PROVISIONING_PATH" echo " ./core/nulib/provisioning help" echo "" echo "Para las demos de la charla:" echo " cd \$PROVISIONING_PATH/talks/rust-meetup-2025/demos" echo " nu 01-basic-provisioning.nu" EOF chmod +x "$DEMO_DIR/demo-env.sh" # Create infrastructure directory mkdir -p "$DEMO_DIR/infra" log "✅ Ambiente demo configurado en $DEMO_DIR" } setup_nushell_plugins() { log "Configurando plugins de Nushell..." # Install nu_plugin_tera if available if command -v cargo &> /dev/null; then log "Instalando nu_plugin_tera..." cargo install nu_plugin_tera || warn "No se pudo instalar nu_plugin_tera" # Register plugin if command -v nu_plugin_tera &> /dev/null; then nu -c "plugin add ~/.cargo/bin/nu_plugin_tera; plugin use tera" || warn "No se pudo registrar nu_plugin_tera" fi fi log "✅ Plugins configurados" } setup_mcp_demo() { log "Configurando demo MCP..." cd "$DEMO_DIR/provisioning" # Install Python dependencies for MCP server if command -v python3 &> /dev/null && command -v pip3 &> /dev/null; then cd mcp pip3 install -r requirements.txt --user || warn "No se pudieron instalar dependencias MCP" cd .. else warn "Python3/pip3 no encontrado. Demo MCP limitada." fi # Create sample MCP configuration mkdir -p "$HOME/.config/claude" 2>/dev/null || true cat > "$DEMO_DIR/claude-desktop-config-sample.json" << EOF { "mcpServers": { "provisioning": { "command": "python3", "args": ["$DEMO_DIR/provisioning/mcp/server.py"], "env": { "PROVISIONING_PATH": "$DEMO_DIR/provisioning", "PROVISIONING_DEMO": "true" } } } } EOF log "✅ Demo MCP configurado" log "📄 Configuración Claude Desktop: $DEMO_DIR/claude-desktop-config-sample.json" } setup_docker_demo() { log "Configurando ambiente Docker para demos..." cd "$DEMO_DIR/provisioning/talks/rust-meetup-2025/setup" # Start demo services if command -v docker &> /dev/null && docker info &> /dev/null; then log "Iniciando servicios demo..." docker-compose up -d || warn "No se pudieron iniciar servicios Docker" else warn "Docker no disponible. Algunas demos serán limitadas." fi log "✅ Servicios Docker configurados" } verify_installation() { log "Verificando instalación..." cd "$DEMO_DIR" source demo-env.sh # Test basic tools ERRORS=0 if ! command -v nu &> /dev/null; then error "❌ Nushell no encontrado" ((ERRORS++)) else log "✅ Nushell: $(nu --version | head -n1)" fi if ! command -v kcl &> /dev/null; then error "❌ KCL no encontrado" ((ERRORS++)) else log "✅ KCL: $(kcl --version)" fi if [[ ! -d "$DEMO_DIR/provisioning" ]]; then error "❌ Repositorio no clonado" ((ERRORS++)) else log "✅ Repositorio provisioning disponible" fi # Test provisioning system cd "$DEMO_DIR/provisioning" if nu -c "use core/nulib/lib_provisioning *; print 'Provisioning library loaded successfully'" &> /dev/null; then log "✅ Sistema provisioning funcional" else warn "⚠️ Sistema provisioning con problemas - algunas demos pueden fallar" fi if [[ $ERRORS -eq 0 ]]; then log "🎉 Instalación completada exitosamente!" else warn "⚠️ Instalación completada con $ERRORS errores" fi } show_next_steps() { echo "" echo -e "${BLUE}🎯 Próximos pasos:${NC}" echo "" echo "1. Cargar ambiente demo:" echo " source $DEMO_DIR/demo-env.sh" echo "" echo "2. Explorar el sistema:" echo " cd $DEMO_DIR/provisioning" echo " ./core/nulib/provisioning help" echo "" echo "3. Ejecutar demos de la charla:" echo " cd talks/rust-meetup-2025/demos" echo " nu 01-basic-provisioning.nu" echo " nu 02-mcp-ai-demo.nu" echo " nu 03-cosmian-kms.nu" echo " ./04-cross-compile.sh" echo "" echo "4. Ver la presentación:" echo " cd talks/rust-meetup-2025" echo " npm install && npm run dev" echo "" echo -e "${GREEN}🦀 ¡Disfruta explorando Cloud Native Provisioning!${NC}" } main() { banner log "Iniciando setup del ambiente demo..." check_requirements install_rust install_nushell install_kcl install_docker setup_demo_environment setup_nushell_plugins setup_mcp_demo setup_docker_demo verify_installation show_next_steps log "🎉 Setup completado!" } # Execute main function main "$@"