# agent-manager (am) — installateur Windows (PowerShell 5.1+) # # One-liner : # powershell -ExecutionPolicy Bypass -Command "irm https://git.dracodev.net/Projets/agent-manager/raw/branch/main/install.ps1 | iex" # # Télécharge le binaire de la dernière release Gitea ; à défaut, compile via # cargo install --git. Relancez le script pour mettre à jour. param( [string]$BaseUrl = "https://git.dracodev.net/Projets/agent-manager", [string]$ApiUrl = "https://git.dracodev.net/api/v1/repos/Projets/agent-manager", [string]$InstallDir = "" ) $ErrorActionPreference = "Stop" $ProgressPreference = "SilentlyContinue" # PowerShell 5.1 : forcer TLS 1.2 pour les serveurs modernes try { [Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 } catch {} function Fail([string]$msg) { Write-Host "erreur: $msg" -ForegroundColor Red; exit 1 } function Install-FromSource { if (-not (Get-Command cargo -ErrorAction SilentlyContinue)) { Fail "pas de binaire precompile et cargo est absent - installez Rust (https://rustup.rs) puis relancez" } Write-Host "Installation depuis les sources (cargo install --git $BaseUrl.git) ..." cargo install --git "$BaseUrl.git" --locked if ($LASTEXITCODE -ne 0) { Fail "cargo install a echoue" } $bin = Join-Path $env:USERPROFILE ".cargo\bin\am.exe" Write-Host "" Write-Host "OK - am est installe dans $bin" Write-Host "Essayez : am list | am doctor (mise a jour : relancez ce script)" exit 0 } $arch = if ($env:PROCESSOR_ARCHITECTURE -match "ARM") { "arm64" } else { "x86_64" } $binDir = if ($InstallDir) { $InstallDir } else { Join-Path $env:LOCALAPPDATA "agent-manager\bin" } if ($arch -eq "x86_64") { $ok = $false try { $release = Invoke-RestMethod -Uri "$ApiUrl/releases/latest" -UseBasicParsing -TimeoutSec 20 $tag = $release.tag_name $asset = "am-windows-x86_64.zip" $url = "$BaseUrl/releases/download/$tag/$asset" $tmp = Join-Path $env:TEMP "am-$tag.zip" Write-Host "Telechargement de $url ..." Invoke-WebRequest -Uri $url -OutFile $tmp -UseBasicParsing -TimeoutSec 300 $tmpDir = Join-Path $env:TEMP "am-$tag" Remove-Item $tmpDir -Recurse -Force -ErrorAction SilentlyContinue Expand-Archive -Path $tmp -DestinationPath $tmpDir -Force # L'entrée de l'archive varie selon le pipeline : « am.exe » ou # « am-windows-x86_64.exe » (nom de l'asset). Accepter les deux. $exe = Join-Path $tmpDir "am.exe" if (-not (Test-Path $exe)) { $exe = Join-Path $tmpDir "am-windows-x86_64.exe" } if (Test-Path $exe) { New-Item -ItemType Directory -Force -Path $binDir | Out-Null Copy-Item $exe (Join-Path $binDir "am.exe") -Force Remove-Item $tmp -Force -ErrorAction SilentlyContinue Remove-Item $tmpDir -Recurse -Force -ErrorAction SilentlyContinue $ok = $true } else { throw "am.exe absent de l'archive" } } catch { Write-Host "Binaire precompile indisponible ($($_.Exception.Message)) - installation depuis les sources ..." } if (-not $ok) { Install-FromSource } } else { Write-Host "Architecture $arch : pas de binaire precompile - installation depuis les sources ..." Install-FromSource } # Ajout au PATH utilisateur (permanent) uniquement pour le dossier par defaut if (-not $InstallDir) { $userPath = [Environment]::GetEnvironmentVariable("Path", "User") if ($userPath -notlike "*$binDir*") { [Environment]::SetEnvironmentVariable("Path", "$binDir;$userPath", "User") Write-Host "Ajout de $binDir au PATH utilisateur (rouvrez votre terminal pour en profiter)" } } $env:Path = "$binDir;$env:Path" & (Join-Path $binDir "am.exe") --version Write-Host "" Write-Host "OK - 'am' est installe. Essayez :" Write-Host " am list" Write-Host " am doctor" Write-Host "Mise a jour : relancez ce script."