# Instalador do PoP local do Pradok (Windows Server com Docker). # Uso (PowerShell como administrador): # iwr https://download.pradok.com.br/pop/install.ps1 -OutFile install.ps1; .\install.ps1 -Token param( [Parameter(Mandatory = $true)][string]$Token, [string]$Api = "https://api.pradok.cloud", [string]$Dir = "C:\ProgramData\pradok-pop" ) $ErrorActionPreference = "Stop" $Download = "https://download.pradok.com.br/pop" $falhas = @() if (-not (Get-Command docker -ErrorAction SilentlyContinue)) { $falhas += "O Docker não está instalado." } $cpus = (Get-CimInstance Win32_ComputerSystem).NumberOfLogicalProcessors $ramMb = [int]((Get-CimInstance Win32_ComputerSystem).TotalPhysicalMemory / 1MB) New-Item -ItemType Directory -Force -Path $Dir | Out-Null $discoGb = [int]((Get-PSDrive -Name ($Dir.Substring(0, 1))).Free / 1GB) if ($cpus -lt 4) { $falhas += "O servidor tem $cpus CPU(s); o mínimo é 4." } if ($ramMb -lt 7500) { $falhas += "O servidor tem $([int]($ramMb / 1024)) GB de memória; o mínimo é 8 GB." } if ($discoGb -lt 200) { $falhas += "Há $discoGb GB livres em disco; o mínimo é 256 GB de SSD (200 GB livres)." } if (Get-NetTCPConnection -LocalPort 8443 -State Listen -ErrorAction SilentlyContinue) { $falhas += "A porta 8443 está ocupada." } if ($falhas.Count -gt 0) { $falhas | ForEach-Object { Write-Host "✗ $_" -ForegroundColor Red } Write-Host "Corrija os itens acima e rode o instalador de novo." exit 1 } Write-Host "Baixando o agente e o compose..." $agente = Join-Path $Dir "pradok-pop-agente.exe" Invoke-WebRequest "$Download/agente/pradok-pop-agente-windows-amd64.exe" -OutFile $agente Invoke-WebRequest "$Download/compose.local.yaml" -OutFile (Join-Path $Dir "compose.yaml") Invoke-WebRequest "$Download/initdb.tar.gz" -OutFile (Join-Path $Dir "initdb.tar.gz") tar -xzf (Join-Path $Dir "initdb.tar.gz") -C $Dir Write-Host "Registrando o PoP (a chave privada é gerada aqui e não sai deste servidor)..." $cfg = Join-Path $Dir "agente.json" & $agente instalar --api $Api --token $Token --dir $Dir --config $cfg --cpus $cpus --ram-mb $ramMb --disco-gb $discoGb if ($LASTEXITCODE -ne 0) { exit 1 } function Senha { -join ((48..57) + (65..90) + (97..122) | Get-Random -Count 32 | ForEach-Object { [char]$_ }) } $c = Get-Content $cfg -Raw | ConvertFrom-Json @( "PRADOK_POP_ID=$($c.pop_codigo)", "PRADOK_POP_DIR=$Dir", "PRADOK_POP_TAG=estavel", "PRADOK_API_SYNC_URL=$($c.api_url)", "PRADOK_POP_DB_PASSWORD=$(Senha)", "PRADOK_POP_APP_PASSWORD=$(Senha)", "PRADOK_POP_WORKER_PASSWORD=$(Senha)" ) | Set-Content (Join-Path $Dir ".env") Push-Location $Dir docker compose up -d Pop-Location # O agente roda como tarefa agendada na inicialização. $acao = New-ScheduledTaskAction -Execute $agente -Argument "rodar --config `"$cfg`"" Register-ScheduledTask -TaskName "PradokPopAgente" -Action $acao -Trigger (New-ScheduledTaskTrigger -AtStartup) -RunLevel Highest -Force | Out-Null Start-ScheduledTask -TaskName "PradokPopAgente" Write-Host "✓ PoP $($c.pop_codigo) instalado."