Update boot.ps1
Browse files
boot.ps1
CHANGED
|
@@ -1,71 +1,105 @@
|
|
| 1 |
-
# --- AI-LAB Windows Smart Agent (Self-Updating) ---
|
| 2 |
-
# Este script gerencia sua própria atualização, a pasta C:\AI-LAB e o atalho na Área de Trabalho.
|
| 3 |
-
|
| 4 |
-
$
|
| 5 |
-
$
|
| 6 |
-
$
|
| 7 |
-
$
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
if (
|
| 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 |
-
if (
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# --- AI-LAB Windows Smart Agent (Self-Updating) ---
|
| 2 |
+
# Este script gerencia sua própria atualização, a pasta C:\AI-LAB e o atalho na Área de Trabalho.
|
| 3 |
+
$ErrorActionPreference = "Stop"
|
| 4 |
+
$INSTALL_PATH = "C:\AI-LAB"
|
| 5 |
+
$SCRIPT_NAME = "boot.ps1"
|
| 6 |
+
$FULL_SCRIPT_PATH = Join-Path $INSTALL_PATH $SCRIPT_NAME
|
| 7 |
+
$REPO_RAW_URL = "https://huggingface.co/vost/pub-scripts/raw/main/"
|
| 8 |
+
|
| 9 |
+
# 1. Garantir Privilégios e Pastas Estruturais
|
| 10 |
+
if (-not (Test-Path $INSTALL_PATH)) {
|
| 11 |
+
New-Item -Path $INSTALL_PATH -ItemType Directory -Force | Out-Null
|
| 12 |
+
}
|
| 13 |
+
Set-Location $INSTALL_PATH
|
| 14 |
+
|
| 15 |
+
$MOUNT_ROOT = New-Item -Path "C:\AI-LAB\mnt" -ItemType Directory -Force | Out-Null
|
| 16 |
+
$HF_PATH = New-Item -Path "C:\AI-LAB\mnt\hf" -ItemType Directory -Force | Out-Null
|
| 17 |
+
|
| 18 |
+
# 2. Verificação do Docker (Winget)
|
| 19 |
+
if (-not (Get-Command docker -ErrorAction SilentlyContinue)) {
|
| 20 |
+
# Solicita admin apenas se precisar instalar o Docker
|
| 21 |
+
if (-not ([Security.Principal.WindowsPrincipal][Security.Principal.WindowsIdentity]::GetCurrent()).IsInRole([Security.Principal.WindowsBuiltInRole]::Administrator)) {
|
| 22 |
+
Write-Host "Docker não encontrado. Solicitando permissões de Administrador para instalação..." -ForegroundColor Cyan
|
| 23 |
+
Start-Process powershell.exe -ArgumentList "-ExecutionPolicy Bypass -File `"$PSCommandPath`"" -Verb RunAs
|
| 24 |
+
exit
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
Write-Host "Docker não encontrado. Iniciando instalação..." -ForegroundColor Yellow
|
| 28 |
+
winget install --id Docker.DockerDesktop --silent --accept-package-agreements
|
| 29 |
+
Write-Host "Por favor, REINICIE o computador e clique no atalho AI-LAB na Área de Trabalho." -ForegroundColor Red
|
| 30 |
+
exit
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
function Sync-RemoteFile {
|
| 34 |
+
param (
|
| 35 |
+
[Parameter(Mandatory=$true)][string]$FileName,
|
| 36 |
+
[Parameter(Mandatory=$true)][string]$DestinationPath,
|
| 37 |
+
[switch]$RestartOnUpdate
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
$RemoteUrl = "$REPO_RAW_URL$FileName"
|
| 41 |
+
$TempFile = Join-Path $env:TEMP "ai-lab-$FileName"
|
| 42 |
+
|
| 43 |
+
try {
|
| 44 |
+
if (Test-Path $DestinationPath) {
|
| 45 |
+
Invoke-WebRequest -Uri $RemoteUrl -OutFile $TempFile -UseBasicParsing
|
| 46 |
+
|
| 47 |
+
$localHash = (Get-FileHash $DestinationPath -Algorithm SHA256).Hash
|
| 48 |
+
$remoteHash = (Get-FileHash $TempFile -Algorithm SHA256).Hash
|
| 49 |
+
|
| 50 |
+
if ($localHash -ne $remoteHash) {
|
| 51 |
+
Write-Host "Nova versão de [$FileName] detectada! Atualizando..." -ForegroundColor Magenta
|
| 52 |
+
Move-Item -Path $TempFile -Destination $DestinationPath -Force
|
| 53 |
+
if ($RestartOnUpdate) {
|
| 54 |
+
Write-Host "Reiniciando script para aplicar alterações..." -ForegroundColor Cyan
|
| 55 |
+
Start-Process powershell.exe -ArgumentList "-ExecutionPolicy Bypass -File `"$DestinationPath`""
|
| 56 |
+
exit
|
| 57 |
+
}
|
| 58 |
+
} else {
|
| 59 |
+
Write-Host "[$FileName] já está na versão mais recente." -ForegroundColor Green
|
| 60 |
+
}
|
| 61 |
+
} else {
|
| 62 |
+
Write-Host "Baixando versão inicial de [$FileName]..." -ForegroundColor Cyan
|
| 63 |
+
Invoke-WebRequest -Uri $RemoteUrl -OutFile $DestinationPath -UseBasicParsing
|
| 64 |
+
}
|
| 65 |
+
} catch {
|
| 66 |
+
Write-Warning "Falha ao sincronizar [$FileName]. Usando versão local se disponível."
|
| 67 |
+
} finally {
|
| 68 |
+
if (Test-Path $TempFile) { Remove-Item $TempFile -ErrorAction SilentlyContinue }
|
| 69 |
+
}
|
| 70 |
+
}
|
| 71 |
+
|
| 72 |
+
# 3. Lógica de Auto-Atualização com Re-execução
|
| 73 |
+
Write-Host "--- Verificando atualizações do Agente ---" -ForegroundColor Cyan
|
| 74 |
+
Sync-RemoteFile -FileName $SCRIPT_NAME -DestinationPath $FULL_SCRIPT_PATH -RestartOnUpdate
|
| 75 |
+
|
| 76 |
+
# 4. Solicita o Token (Uma única vez)
|
| 77 |
+
if (-not $env:HF_TOKEN) {
|
| 78 |
+
$token = Read-Host "Insira seu HuggingFace Token (Read)"
|
| 79 |
+
[Environment]::SetEnvironmentVariable("HF_TOKEN", $token, "User")
|
| 80 |
+
}
|
| 81 |
+
|
| 82 |
+
# 5. Sincronização do docker-compose.yaml
|
| 83 |
+
Write-Host "--- Sincronizando Infraestrutura (YAML) ---" -ForegroundColor Cyan
|
| 84 |
+
Sync-RemoteFile -FileName "docker-compose.yaml" -DestinationPath (Join-Path $INSTALL_PATH "docker-compose.yaml")
|
| 85 |
+
|
| 86 |
+
# 6. Execução Final do Docker
|
| 87 |
+
Write-Host "--- Iniciando containers do Laboratório ---" -ForegroundColor Green
|
| 88 |
+
docker compose up -d
|
| 89 |
+
|
| 90 |
+
# 7. Criação do Atalho na Área de Trabalho
|
| 91 |
+
$ShortcutPath = Join-Path ([Environment]::GetFolderPath("Desktop")) "AI-LAB.lnk"
|
| 92 |
+
if (-not (Test-Path $ShortcutPath)) {
|
| 93 |
+
Write-Host "Criando atalho na Área de Trabalho..." -ForegroundColor Gray
|
| 94 |
+
$WshShell = New-Object -ComObject WScript.Shell
|
| 95 |
+
$Shortcut = $WshShell.CreateShortcut($ShortcutPath)
|
| 96 |
+
$Shortcut.TargetPath = "powershell.exe"
|
| 97 |
+
$Shortcut.Arguments = "-ExecutionPolicy Bypass -File `"$FULL_SCRIPT_PATH`""
|
| 98 |
+
$Shortcut.WorkingDirectory = $INSTALL_PATH
|
| 99 |
+
$Shortcut.IconLocation = "powershell.exe,0" # Ícone do PowerShell
|
| 100 |
+
$Shortcut.Save()
|
| 101 |
+
}
|
| 102 |
+
|
| 103 |
+
Write-Host "`n[SUCESSO] Seu AI-LAB está rodando e sincronizado." -ForegroundColor Green
|
| 104 |
+
Write-Host "Pressione qualquer tecla para sair..."
|
| 105 |
+
$null = [System.Console]::ReadKey()
|