# ============================================================= # Chatc2 - Script de deploy Windows -> Linux # Uso: .\deploy.ps1 -IP 192.168.1.100 # ============================================================= param( [Parameter(Mandatory=$true)] [string]$IP, [string]$User = "root", [string]$ProjectPath = (Split-Path -Parent $PSScriptRoot), [string]$RemotePath = "/home/chatc2/chatc2" ) Write-Host "╔════════════════════════════════════════════╗" -ForegroundColor Cyan Write-Host "║ Chatc2 - Deploy Windows -> Linux ║" -ForegroundColor Cyan Write-Host "╚════════════════════════════════════════════╝" -ForegroundColor Cyan Write-Host "" # 1. Testar conexao SSH Write-Host "[1/5] Testando conexao SSH..." -ForegroundColor Yellow try { $result = ssh -o StrictHostKeyChecking=no -o ConnectTimeout=5 "$User@$IP" "echo OK" 2>&1 if ($LASTEXITCODE -ne 0) { throw "SSH falhou" } Write-Host " ✓ Conectado a $IP" -ForegroundColor Green } catch { Write-Host " ✘ Erro: $_" -ForegroundColor Red exit 1 } # 2. Criar diretorios no servidor Write-Host "[2/5] Criando diretorios no servidor..." -ForegroundColor Yellow ssh "$User@$IP" "mkdir -p $RemotePath/{db,logs,tmp,uploads/audio,public,whisper/models} 2>/dev/null; chown -R chatc2:chatc2 $RemotePath 2>/dev/null; echo 'OK'" 2>$null Write-Host " ✓ Diretorios criados" -ForegroundColor Green # 3. Enviar arquivos via SCP Write-Host "[3/5] Enviando arquivos do projeto..." -ForegroundColor Yellow Write-Host " (isso pode levar alguns minutos...)" -ForegroundColor Gray $exclude = @('node_modules', '.git', 'db/*.FDB', 'logs', 'tmp', 'Nova pasta', 'chatc2-py', 'ponto_1', 'whisper') $excludeArgs = ($exclude | ForEach-Object { "--exclude=$_" }) -join ' ' $scpCommand = "scp -r $excludeArgs `"$ProjectPath\*`" $User@`"$IP`":$RemotePath/" Write-Host " Executando: scp -r (arquivos do projeto) para $IP..." -ForegroundColor Gray try { $result = scp -r ` --exclude='node_modules' ` --exclude='.git' ` --exclude='db/*.FDB' ` --exclude='logs' ` --exclude='tmp' ` --exclude='Nova pasta' ` --exclude='chatc2-py' ` --exclude='ponto_1' ` --exclude='whisper' ` "$ProjectPath\*" "$User@$IP`:$RemotePath/" 2>&1 if ($LASTEXITCODE -ne 0) { throw "SCP falhou" } Write-Host " ✓ Arquivos enviados" -ForegroundColor Green } catch { Write-Host " ✘ Erro no SCP: $_" -ForegroundColor Red Write-Host " Tente enviar manualmente via FileZilla ou WinSCP" -ForegroundColor Yellow } # 4. Ajustar permissoes Write-Host "[4/5] Ajustando permissoes..." -ForegroundColor Yellow ssh "$User@$IP" "chown -R chatc2:chatc2 $RemotePath 2>/dev/null; chmod -R 755 $RemotePath 2>/dev/null; echo OK" 2>$null Write-Host " ✓ Permissoes ajustadas" -ForegroundColor Green # 5. Instalar dependencias e rodar script de instalacao Write-Host "[5/5] Instalando dependencias e configurando servico..." -ForegroundColor Yellow ssh "$User@$IP" "cd $RemotePath/deploy-linux && sudo bash install.sh --continue" 2>&1 | Write-Host Write-Host "" Write-Host "╔════════════════════════════════════════════╗" -ForegroundColor Cyan Write-Host "║ Deploy Concluido! ║" -ForegroundColor Cyan Write-Host "╚════════════════════════════════════════════╝" -ForegroundColor Cyan Write-Host "" Write-Host " Acesse: http://$IP" -ForegroundColor Green Write-Host " SSH: ssh $User@$IP" -ForegroundColor Gray Write-Host " Logs: ssh $User@$IP 'pm2 logs chatc2'" -ForegroundColor Gray