File size: 4,929 Bytes
cd07f3b
 
 
bc9cf25
 
 
 
 
 
cd07f3b
bc9cf25
 
 
 
 
 
 
 
cd07f3b
bc9cf25
 
 
cd07f3b
bc9cf25
cd07f3b
bc9cf25
 
 
cd07f3b
bc9cf25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cd07f3b
bc9cf25
 
 
 
 
 
 
cd07f3b
 
bc9cf25
 
cd07f3b
bc9cf25
 
cd07f3b
bc9cf25
 
cd07f3b
 
bc9cf25
 
 
 
cd07f3b
 
 
be213fe
c9a075b
e94cb2f
 
be213fe
 
 
cd07f3b
 
 
 
bc9cf25
7c2f0e4
cd07f3b
7c2f0e4
 
c9a075b
7c2f0e4
 
 
 
 
 
 
c9a075b
7c2f0e4
cd07f3b
bc9cf25
cd07f3b
bc9cf25
 
 
 
 
 
 
 
 
 
cd07f3b
bc9cf25
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# --- AI-LAB Windows Smart Start UP ---
# Inicia os Containers e sincroniza o ambiente

$ErrorActionPreference = "Stop"
$INSTALL_PATH = "C:\AI-LAB"
$SCRIPT_NAME = "boot.ps1"
$FULL_SCRIPT_PATH = Join-Path $INSTALL_PATH $SCRIPT_NAME
$REPO_RAW_URL = "https://huggingface.co/vost/pub-scripts/raw/main/"

# 1. Garantir Pastas Estruturais
if (-not (Test-Path $INSTALL_PATH)) {
    New-Item -Path $INSTALL_PATH -ItemType Directory -Force | Out-Null
}
Set-Location $INSTALL_PATH

# 2. Verificação do Docker (Winget)
if (-not (Get-Command docker -ErrorAction SilentlyContinue)) {
    if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
        Write-Host "Docker não encontrado. Solicitando permissões de Administrador..." -ForegroundColor Cyan
        Start-Process powershell.exe -ArgumentList "-ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
        exit
    }
    Write-Host "Instalando Docker Desktop..." -ForegroundColor Yellow
    winget install --id Docker.DockerDesktop --silent --accept-package-agreements
    Write-Host "REINICIE o computador e execute o AI-LAB novamente." -ForegroundColor Red
    exit
}

# --- FUNÇÃO DE SINCRONIZAÇÃO ---
function Sync-RemoteFile {
    param (
        [Parameter(Mandatory=$true)][string]$FileName,
        [Parameter(Mandatory=$true)][string]$DestinationPath,
        [switch]$RestartOnUpdate
    )
    $RemoteUrl = "$REPO_RAW_URL$FileName"
    $TempFile = Join-Path $env:TEMP "ai-lab-$FileName"
    try {
        if (Test-Path $DestinationPath) {
            Invoke-WebRequest -Uri $RemoteUrl -OutFile $TempFile -UseBasicParsing
            $localHash = (Get-FileHash $DestinationPath -Algorithm SHA256).Hash
            $remoteHash = (Get-FileHash $TempFile -Algorithm SHA256).Hash

            if ($localHash -ne $remoteHash) {
                Write-Host "Atualizando [$FileName]..." -ForegroundColor Magenta
                Move-Item -Path $TempFile -Destination $DestinationPath -Force
                if ($RestartOnUpdate) {
                    Start-Process powershell.exe -ArgumentList "-ExecutionPolicy Bypass -File `"$DestinationPath`""
                    exit
                }
            }
        } else {
            Write-Host "Baixando [$FileName]..." -ForegroundColor Cyan
            New-Item -ItemType File -Path $DestinationPath -Force | Out-Null
            Invoke-WebRequest -Uri $RemoteUrl -OutFile $DestinationPath -UseBasicParsing
        }
    } catch { Write-Warning "Falha ao sincronizar [$FileName]." }
}

# 3. Auto-Atualização do Agente
Sync-RemoteFile -FileName $SCRIPT_NAME -DestinationPath $FULL_SCRIPT_PATH -RestartOnUpdate

# 4. Token HuggingFace (Persistente no Usuário)
if (-not [Environment]::GetEnvironmentVariable("HF_TOKEN", "User")) {
    $token = Read-Host "Insira seu HuggingFace Token (Read)"
    [Environment]::SetEnvironmentVariable("HF_TOKEN", $token, "User")
}

# --- 5. PREPARAÇÃO DO AMBIENTE DOCKER ---
Write-Host "--- Preparando Infraestrutura ---" -ForegroundColor Cyan

$CURRENT_PATH = $PSScriptRoot.Replace('\', '/')
$CURRENT_PATH = $CURRENT_PATH.TrimStart('/')
$env:HOST_AI_LAB_PATH = $CURRENT_PATH
Write-Host "VARIAVEL DEFINIDA: $env:HOST_AI_LAB_PATH" -ForegroundColor Yellow
# Define a variável de ambiente para que os containers saibam a raiz do Host
[Environment]::SetEnvironmentVariable("HOST_AI_LAB_PATH", $CURRENT_PATH, "Process")

if (-not (docker volume ls -q -f name=Guardians-Share)) {
    Write-Host "Criando Volume Compartilhado (Guardians-Share)..." -ForegroundColor Gray
    docker volume create Guardians-Share
}

# 6. Execução do HW-Guardian (O Olho)
Write-Host "--- Iniciando HW-Guardian ---" -ForegroundColor Green
$HWGUARDIAN_DIR = "$INSTALL_PATH\Guardians\HW-Guardian"
if (Test-Path $HWGUARDIAN_DIR) {
    docker build -t hw-guardian-base "$HWGUARDIAN_DIR"
    docker compose -f "$HWGUARDIAN_DIR\docker-compose.yaml" up -d
}

# 7. Execução do AI-Guardian (O Cérebro/Orquestrador)
Write-Host "--- Iniciando AI-Guardian ---" -ForegroundColor Magenta
$AIGUARDIAN_DIR = "$INSTALL_PATH\Guardians\AI-Guardian" # Corrigido o caminho
if (Test-Path $AIGUARDIAN_DIR) {
    docker build -t ai-guardian-base "$AIGUARDIAN_DIR"
    docker compose -f "$AIGUARDIAN_DIR\docker-compose.yaml" up -d
}

# 7. Atalho na Área de Trabalho
$ShortcutPath = Join-Path ([Environment]::GetFolderPath("Desktop")) "AI-LAB.lnk"
if (-not (Test-Path $ShortcutPath)) {
    $WshShell = New-Object -ComObject WScript.Shell
    $Shortcut = $WshShell.CreateShortcut($ShortcutPath)
    $Shortcut.TargetPath = "powershell.exe"
    $Shortcut.Arguments = "-ExecutionPolicy Bypass -File `"$FULL_SCRIPT_PATH`""
    $Shortcut.WorkingDirectory = $INSTALL_PATH
    $Shortcut.Save()
}

Write-Host "`n[SUCESSO] AI-LAB Ativo. Pressione qualquer tecla..." -ForegroundColor Green
$null = [System.Console]::ReadKey()