# d0a1 pack - OpenClaw (Windows) # Asistente de IA en tus chats. OpenClaw + Ollama. # # Local: .\deploy.ps1 local -> terminal + http://localhost:11434 (Ollama) # VPS: .\deploy.ps1 vps -> + gateway accesible desde fuera # Stop: .\deploy.ps1 stop -> para Ollama # # Requiere: Docker Desktop para Windows (https://docs.docker.com/desktop/) param( [Parameter(Position = 0)] [ValidateSet('local', 'vps', 'stop')] [string]$Mode = 'local' ) $ErrorActionPreference = 'Stop' # Escape ANSI via [char]27 (compatible con Windows PowerShell 5.1 y PS 7+) $Esc = [char]27 $Green = "$Esc[32m"; $Cyan = "$Esc[36m"; $Yellow = "$Esc[33m"; $Red = "$Esc[31m"; $Bold = "$Esc[1m"; $NC = "$Esc[0m" if ($env:NO_COLOR) { $Green = $Cyan = $Yellow = $Red = $Bold = $NC = '' } function Info($msg) { Write-Host "${Bold}${Green}>>>${NC} $msg" } function Warn($msg) { Write-Host "${Bold}${Yellow}>>>${NC} $msg" } function Err($msg) { Write-Host "${Bold}${Red}>>>${NC} $msg" } function Ok($msg) { Write-Host "${Green}OK${NC} $msg" } function Find-FreePort([int]$Start) { for ($p = $Start; $p -le ($Start + 20); $p++) { $inUse = Get-NetTCPConnection -LocalPort $p -State Listen -ErrorAction SilentlyContinue if (-not $inUse) { return $p } } return $Start } Write-Host '' Write-Host "${Bold}${Cyan}============================================================${NC}" Write-Host "${Bold}${Cyan} d0a1 pack - OpenClaw (Windows)${NC}" Write-Host "${Bold}${Cyan} Asistente de IA en tus chats.${NC}" Write-Host "${Bold}${Cyan}============================================================${NC}" Write-Host '' # --- Stop mode ------------------------------------------------------------ if ($Mode -eq 'stop') { $running = docker ps --format '{{.Names}}' | Select-String -Quiet 'd0a1-openclaw-ollama' if ($running) { docker stop d0a1-openclaw-ollama | Out-Null docker rm d0a1-openclaw-ollama | Out-Null Info 'Ollama parado.' } else { Write-Host 'Ollama no esta corriendo.' } exit 0 } # --- Check Docker (para Ollama) ------------------------------------------- if (-not (Get-Command docker -ErrorAction SilentlyContinue)) { Err 'Docker no esta instalado (necesario para Ollama).' Write-Host '' Write-Host 'Instala Docker Desktop para Windows:' Write-Host ' https://docs.docker.com/desktop/setup/install/windows-install/' exit 1 } # En PS 5.1, *> $null sobre comandos nativos convierte stderr en errores # terminantes con EAP=Stop (PS #4002). Se descarta via cmd /c. $null = cmd /c "docker info >NUL 2>&1" if ($LASTEXITCODE -ne 0) { Err 'Docker Desktop no responde. Abre Docker Desktop y espera a que arranque.' exit 1 } Ok "Docker: $((docker --version) -replace 'Docker version ','' -replace ',.*','')" # --- Check RAM ------------------------------------------------------------ $TotalRamGb = [math]::Round((Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory / 1GB, 1) if ($TotalRamGb -lt 3.5) { Err "Se necesitan 4 GB de RAM minimo (detectado: $TotalRamGb GB)." exit 1 } Ok "RAM: $TotalRamGb GB" # --- Auto-detect Ollama port ------------------------------------------------ $OllamaPort = Find-FreePort 11434 if ($Mode -eq 'vps') { Warn 'Modo: VPS' Write-Host '' Write-Host " ${Bold}¿No tienes VPS?${NC} Consigue uno con descuento:" Write-Host " ${Cyan}https://d0a1.es/go/vultr/${NC} - Vultr" Write-Host " ${Cyan}https://d0a1.es/go/digitalocean/${NC} - DigitalOcean (`$200 credit)" Write-Host '' } if ($OllamaPort -ne 11434) { Warn "Puerto 11434 ocupado, usando $OllamaPort" } Write-Host '' # --- 1. Arrancar Ollama (Docker) ------------------------------------------- Warn '[1/3] Arrancando Ollama (IA local)...' cmd /c docker rm -f d0a1-openclaw-ollama '>' NUL '2>&1' $running = docker ps --format '{{.Names}}' | Select-String -Quiet 'd0a1-openclaw-ollama' if (-not $running) { docker run -d --name d0a1-openclaw-ollama ` -p "${OllamaPort}:11434" ` -v d0a1_openclaw_ollama:/root/.ollama ` -e OLLAMA_HOST=0.0.0.0 ` --restart unless-stopped ` ollama/ollama:0.33.3 | Out-Null if ($LASTEXITCODE -ne 0) { Err 'Fallo al arrancar el contenedor de Ollama.'; exit 1 } } Warn ' Esperando a que Ollama arranque...' $MaxWait = 60; $Waited = 0 while ($true) { # Descarte de stderr via cmd /c (ver nota de PS 5.1 / PS #4002 arriba) cmd /c "docker exec d0a1-openclaw-ollama ollama ps >NUL 2>&1" if ($LASTEXITCODE -eq 0) { break } Start-Sleep -Seconds 2 $Waited += 2 if ($Waited -ge $MaxWait) { Err 'Ollama no arranco. Revisa: docker logs d0a1-openclaw-ollama' exit 1 } } Warn ' Descargando modelo (llama3.2:3b, ~2 GB)...' # Si el usuario define $env:HTTPS_PROXY, Ollama lo usa para el pull (doc oficial): $ProxyEnv = @() if ($env:HTTPS_PROXY) { $ProxyEnv = @('-e', "HTTPS_PROXY=$env:HTTPS_PROXY", '-e', "HTTP_PROXY=$env:HTTP_PROXY") } $PullOk = $false foreach ($Attempt in 1..3) { if ($Attempt -gt 1) { Warn "Reintento $Attempt de 3..." } docker exec @ProxyEnv d0a1-openclaw-ollama ollama pull llama3.2:3b if ($LASTEXITCODE -eq 0) { $PullOk = $true; break } Warn 'Descarga interrumpida (red). Reintentando en 5 s...' Start-Sleep -Seconds 5 } if (-not $PullOk) { # --- Fallback: mismo modelo via HuggingFace (otro CDN, no el registry de Ollama) --- Warn 'Registry de Ollama no accesible. Probando via HuggingFace (mismo modelo)...' $Gguf = Join-Path $ScriptDir 'llama3.2-3b-q4.gguf' $Urls = @( 'https://huggingface.co/bartowski/Llama-3.2-3B-Instruct-GGUF/resolve/main/Llama-3.2-3B-Instruct-Q4_K_M.gguf', 'https://huggingface.co/unsloth/Llama-3.2-3B-Instruct-GGUF/resolve/main/Llama-3.2-3B-Instruct-Q4_K_M.gguf' ) $DlOk = $false foreach ($Url in $Urls) { curl.exe -sL --retry 3 --max-time 1800 -o "$Gguf" $Url if ($LASTEXITCODE -eq 0 -and (Test-Path $Gguf) -and (Get-Item $Gguf).Length -gt 1900000000) { $DlOk = $true; break } Warn "Mirror no accesible, probando el siguiente..." } if ($DlOk) { docker cp "$Gguf" d0a1-openclaw-ollama:/root/.ollama/import.gguf docker exec d0a1-openclaw-ollama sh -c 'echo FROM /root/.ollama/import.gguf > /tmp/mf && ollama create llama3.2:3b -f /tmp/mf' $CreateOk = ($LASTEXITCODE -eq 0) docker exec d0a1-openclaw-ollama rm -f /root/.ollama/import.gguf | Out-Null Remove-Item "$Gguf" -Force -ErrorAction SilentlyContinue if ($CreateOk) { $PullOk = $true } else { Err 'Fallo al importar el modelo desde el GGUF.' } } else { Err 'No se pudo descargar el modelo (ni registry ni HuggingFace).' if (-not $env:HTTPS_PROXY) { Write-Host ' Tu red bloquea ambos. Si tienes proxy/VPN:' Write-Host ' $env:HTTPS_PROXY = "http://127.0.0.1:7890" # (puerto de tu proxy)' Write-Host ' .\deploy.ps1 vps' } exit 1 } } Ok "Ollama corriendo en http://localhost:${OllamaPort}" # --- 2. Instalar OpenClaw ----------------------------------------------------- Warn '[2/3] Instalando OpenClaw...' if (Get-Command openclaw -ErrorAction SilentlyContinue) { Ok "OpenClaw ya instalado: $(cmd /c 'openclaw --version 2>NUL')" } else { # En Windows: instala con npm (Node 18+). El install.sh de Linux no aplica. Write-Host ' Instalando con npm (requiere Node.js 18+)...' npm install -g openclaw if ($LASTEXITCODE -ne 0 -or -not (Get-Command openclaw -ErrorAction SilentlyContinue)) { Err 'OpenClaw no se instalo. Instalalo manualmente:' Write-Host ' https://openclaw.ai/docs' exit 1 } Ok "OpenClaw instalado: $(cmd /c 'openclaw --version 2>NUL')" } # --- 3. Configurar ------------------------------------------------------------ Warn '[3/3] Configurando...' Write-Host '' Write-Host " ${Bold}Ejecuta estos comandos para terminar:${NC}" Write-Host '' Write-Host " ${Cyan}openclaw onboard --install-daemon${NC} - configuracion inicial" Write-Host " ${Cyan}openclaw gateway status${NC} - verifica el gateway" Write-Host " ${Cyan}openclaw dashboard${NC} - abre la UI" Write-Host '' Write-Host " ${Bold}Conecta tus chats (WhatsApp, Telegram, etc.):${NC}" Write-Host " ${Cyan}openclaw channel add whatsapp${NC}" Write-Host " ${Cyan}openclaw channel add telegram${NC}" Write-Host '' if ($Mode -eq 'vps') { Write-Host " ${Bold}Para VPS:${NC} configura el gateway para acceso remoto." Write-Host '' } Write-Host " ${Bold}Parar:${NC} .\deploy.ps1 stop" Write-Host " ${Bold}¿Quieres mas?${NC} ${Cyan}https://d0a1.es/packs/${NC}" Write-Host ''