vost commited on
Commit
bc9cf25
·
verified ·
1 Parent(s): 01f56d2

Update boot.ps1

Browse files
Files changed (1) hide show
  1. boot.ps1 +105 -71
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
- $ErrorActionPreference = "Stop"
5
- $INSTALL_PATH = "C:\AI-LAB"
6
- $SCRIPT_NAME = "boot.ps1"
7
- $FULL_SCRIPT_PATH = Join-Path $INSTALL_PATH $SCRIPT_NAME
8
- $REPO_RAW_URL = "https://huggingface.co/vost/pub-scripts/raw/main/"
9
-
10
- # 1. Garantir Privilégios e Pasta Estrutural
11
- if (-not (Test-Path $INSTALL_PATH)) {
12
- New-Item -Path $INSTALL_PATH -ItemType Directory -Force | Out-Null
13
- }
14
- Set-Location $INSTALL_PATH
15
-
16
- # 2. Lógica de Auto-Atualização com Re-execução
17
- Write-Host "--- Verificando atualizações do Agente ---" -ForegroundColor Cyan
18
-
19
- if (Test-Path $FULL_SCRIPT_PATH) {
20
- # Calcula o Hash do arquivo local para comparar com o remoto
21
- $localHash = (Get-FileHash $FULL_SCRIPT_PATH -Algorithm MD5).Hash
22
- $remoteContent = Invoke-WebRequest -Uri "$REPO_RAW_URL/$SCRIPT_NAME" -UseBasicParsing
23
-
24
- # Gera o Hash do conteúdo baixado na memória
25
- $remoteHash = ([System.Security.Cryptography.MD5]::Create().ComputeHash([System.Text.Encoding]::UTF8.GetBytes($remoteContent.Content)) | ForEach-Object { $_.ToString("X2") }) -join ""
26
-
27
- if ($localHash -ne $remoteHash) {
28
- Write-Host "Nova versão detectada! Atualizando e reiniciando o script..." -ForegroundColor Magenta
29
- $remoteContent.Content | Out-File $FULL_SCRIPT_PATH -Encoding UTF8
30
-
31
- # RE-EXECUÇÃO: Chama a nova versão e encerra a atual
32
- Start-Process powershell.exe -ArgumentList "-ExecutionPolicy Bypass -File `"$FULL_SCRIPT_PATH`""
33
- exit
34
- }
35
- Write-Host "O Agente já está na versão mais recente." -ForegroundColor Green
36
- } else {
37
- # Primeira instalação (Caso o arquivo ainda não exista no diretório)
38
- Write-Host "Baixando versão inicial do Agente..." -ForegroundColor Cyan
39
- Invoke-WebRequest -Uri "$REPO_RAW_URL/$SCRIPT_NAME" -OutFile $FULL_SCRIPT_PATH
40
- }
41
-
42
- # 3. Criação do Atalho na Área de Trabalho
43
- $ShortcutPath = Join-Path ([Environment]::GetFolderPath("Desktop")) "AI-LAB.lnk"
44
- if (-not (Test-Path $ShortcutPath)) {
45
- Write-Host "Criando atalho na Área de Trabalho..." -ForegroundColor Gray
46
- $WshShell = New-Object -ComObject WScript.Shell
47
- $Shortcut = $WshShell.CreateShortcut($ShortcutPath)
48
- $Shortcut.TargetPath = "powershell.exe"
49
- $Shortcut.Arguments = "-ExecutionPolicy Bypass -File `"$FULL_SCRIPT_PATH`""
50
- $Shortcut.WorkingDirectory = $INSTALL_PATH
51
- $Shortcut.IconLocation = "powershell.exe,0" # Ícone do PowerShell
52
- $Shortcut.Save()
53
- }
54
-
55
- # 4. Sincronização do docker-compose.yaml
56
- Write-Host "--- Sincronizando Infraestrutura (YAML) ---" -ForegroundColor Cyan
57
- Invoke-WebRequest -Uri "$REPO_RAW_URL/docker-compose.yaml" -OutFile (Join-Path $INSTALL_PATH "docker-compose.yaml")
58
-
59
- # 5. Verificação do Docker (Winget)
60
- if (-not (Get-Command docker -ErrorAction SilentlyContinue)) {
61
- Write-Host "Docker não encontrado. Iniciando instalação..." -ForegroundColor Yellow
62
- winget install --id Docker.DockerDesktop --silent --accept-package-agreements
63
- Write-Host "Por favor, REINICIE o computador e clique no atalho AI-LAB na Área de Trabalho." -ForegroundColor Red
64
- exit
65
- }
66
-
67
- # 6. Execução Final do Docker
68
- Write-Host "--- Iniciando containers do Laboratório ---" -ForegroundColor Green
69
- docker compose up -d
70
-
71
- Write-Host "`n[SUCESSO] Seu AI-LAB está rodando e sincronizado." -ForegroundColor Green
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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] 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()