Files
Serge NOELandClaude Opus 5.5 1e2bcf21cf Regroupement de la chaîne de tests de charge beWeapon
- template/ : build Packer du template Windows 11 (ex /data/Installer/MyTemplate)
- deploy/   : OpenTofu + playbooks Ansible (ex /data/Tofu)
- bin/Deploy : menu de déploiement (lien depuis /usr/local/bin/Deploy)
- jeton API Proxmox sorti des playbooks vers deploy/proxmox-secret.yml (hors git)
- README.md : documentation de la structure et du mode opératoire
- Ameliorations.md : recommandations pour fiabiliser les mesures
- tests/ (dépôt beWeapon-LT) et archives/ exclus

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-11-20 15:27:51 +01:00

243 lines
11 KiB
PowerShell

#Requires -RunAsAdministrator
Set-ExecutionPolicy Bypass -Scope Process -Force
$ErrorActionPreference = "Stop"
function Write-Log {
param ([string]$Message)
$timestamp = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
"$timestamp - $Message" | Out-File -FilePath "C:\install.log" -Append -Encoding utf8
}
Write-Log "=== Recherche du lecteur et copie des scripts Beweis ==="
Write-Host "=== Configuration et copie des scripts Beweis ===" -ForegroundColor Cyan
# 1. Detection automatique du lecteur CD / Clé USB contenant le dossier "install"
$cdDrive = Get-PSDrive -PSProvider FileSystem | Where-Object {
Test-Path (Join-Path $_.Root "install")
} | Select-Object -First 1
if (-not $cdDrive) {
Write-Error "Dossier 'install' introuvable sur les lecteurs de disque."
Write-Log "ERREUR : Dossier 'install' introuvable sur les lecteurs de disque."
exit 1
}
$installDir = Join-Path "$($cdDrive.Name):\" "install"
Write-Log "Dossier d'installation trouve : $installDir"
$destinationDir = "C:\ProgramData\beWeis\"
if (-not (Test-Path $destinationDir)) {
New-Item -Path $destinationDir -ItemType Directory -Force | Out-Null
Write-Log "Dossier $destinationDir cree."
}
# 2. Copie des fichiers start_beweapon.ps1 / start.ps1 et test.ps1
$filesToCopy = @("start_beweapon.ps1", "start.ps1", "test.ps1")
foreach ($fileName in $filesToCopy) {
$sourceFile = Join-Path $installDir $fileName
if (Test-Path $sourceFile) {
try {
Copy-Item -Path $sourceFile -Destination $destinationDir -Force -ErrorAction Stop
Write-Log "Fichier $fileName copie avec succes dans $destinationDir"
Write-Host "Copie : $fileName -> $destinationDir" -ForegroundColor Green
} catch {
Write-Error "Echec de la copie de $fileName : $_"
Write-Log "ERREUR lors de la copie de $fileName : $_"
}
}
}
# =========================================================================
# Installation automatique des pilotes système (Drivers INF, EXE, MSI)
# =========================================================================
Write-Log "=== Installation des pilotes systeme (Drivers) ==="
Write-Host "Recherche et installation des pilotes..." -ForegroundColor Cyan
$driversDir = Join-Path $installDir "drivers"
if (-not (Test-Path $driversDir)) {
$driversDir = $installDir
}
try {
$infFiles = Get-ChildItem -Path $driversDir -Filter "*.inf" -Recurse -ErrorAction SilentlyContinue
if ($infFiles) {
foreach ($inf in $infFiles) {
Write-Log "Traitement du fichier INF : $($inf.FullName)"
$catFiles = Get-ChildItem -Path $inf.DirectoryName -Filter "*.cat" -ErrorAction SilentlyContinue
foreach ($cat in $catFiles) {
$sig = Get-AuthenticodeSignature -FilePath $cat.FullName
if ($sig.SignerCertificate) {
$tempCert = "C:\Windows\Temp\driver_cert.cer"
[System.IO.File]::WriteAllBytes($tempCert, $sig.SignerCertificate.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Cert))
certutil.exe -addstore "TrustedPublisher" $tempCert | Out-Null
certutil.exe -addstore "Root" $tempCert | Out-Null
Remove-Item $tempCert -Force -ErrorAction SilentlyContinue
}
}
& pnputil.exe /add-driver "$($inf.FullName)" /install | Out-Null
Write-Log "pnputil traite : $($inf.Name)"
}
}
$exeDrivers = Get-ChildItem -Path $driversDir -Include "*driver*.exe", "*dpinst*.exe" -File -Recurse -ErrorAction SilentlyContinue
foreach ($exe in $exeDrivers) {
if ($exe.FullName -ne (Join-Path $installDir "setup.exe")) {
Write-Log "Lancement de l'installeur de pilote : $($exe.FullName)"
Start-Process -FilePath $exe.FullName -ArgumentList "/S", "/q", "/silent" -Wait -NoNewWindow -ErrorAction SilentlyContinue
}
}
Write-Host "Installation des pilotes systeme terminee." -ForegroundColor Green
} catch {
Write-Log "AVERTISSEMENT lors de l'installation des pilotes systeme : $_"
}
# =========================================================================
# Installation du Driver Appium Windows & WinAppDriver
# =========================================================================
Write-Log "=== Installation du Driver Appium Windows & WinAppDriver ==="
Write-Host "Configuration des drivers Appium Windows & WinAppDriver..." -ForegroundColor Cyan
try {
# 1. Activation du Mode Developpeur Windows (obligatoire pour WinAppDriver)
Write-Log "Activation du Mode Developpeur Windows..."
$devModeReg = "HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\AppModelUnlock"
if (-not (Test-Path $devModeReg)) { New-Item -Path $devModeReg -Force | Out-Null }
Set-ItemProperty -Path $devModeReg -Name "AllowDevelopmentWithoutDevLicense" -Value 1 -Type DWord -Force
# 2. Installation du driver Appium Windows
Write-Log "Installation du driver Appium Windows..."
Write-Host "Installation du driver Appium Windows..." -ForegroundColor Yellow
Start-Process -FilePath "npx.cmd" -ArgumentList "appium driver install windows" -Wait -NoNewWindow -ErrorAction SilentlyContinue
# 3. Téléchargement et Installation de WinAppDriver (WindowsApplicationDriver.msi)
$wadPath = "C:\Program Files (x86)\Windows Application Driver\WinAppDriver.exe"
if (-not (Test-Path $wadPath)) {
Write-Log "WinAppDriver non trouve. Installation en cours..."
# Verification si le fichier .msi est deja sur le disque d'installation
$localWadMsi = Get-ChildItem -Path $installDir -Filter "*WindowsApplicationDriver*.msi" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1
$msiPath = ""
if ($localWadMsi) {
$msiPath = $localWadMsi.FullName
Write-Log "Utilisation de l'installeur local WinAppDriver : $msiPath"
} else {
# Telechargement depuis le depot officiel Microsoft GitHub
$msiPath = "C:\Windows\Temp\WindowsApplicationDriver.msi"
$downloadUrl = "https://github.com/microsoft/WinAppDriver/releases/download/v1.2.1/WindowsApplicationDriver.msi"
Write-Host "Telechargement de WinAppDriver depuis GitHub..." -ForegroundColor Yellow
Write-Log "Telechargement de WinAppDriver ($downloadUrl)..."
# Configuration du protocole SSL/TLS et User-Agent pour eviter l'erreur 503 / Reset Connection
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12 -bor [Net.SecurityProtocolType]::Tls13
$webClient = New-Object System.Net.WebClient
$webClient.Headers.Add("User-Agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64)")
$webClient.DownloadFile($downloadUrl, $msiPath)
}
# Installation silencieuse via msiexec
if (Test-Path $msiPath) {
Write-Log "Lancement de l'installation silencieuse de WinAppDriver..."
Write-Host "Installation de WinAppDriver.msi en cours..." -ForegroundColor Yellow
$msiProcess = Start-Process -FilePath "msiexec.exe" -ArgumentList "/i `"$msiPath`" /quiet /qn /norestart" -Wait -PassThru -NoNewWindow
Write-Log "Code de retour msiexec WinAppDriver : $($msiProcess.ExitCode)"
} else {
Write-Log "ERREUR : Le fichier MSI de WinAppDriver n'a pas pu etre recupere."
}
}
# Verification finale de la presence de WinAppDriver.exe
if (Test-Path $wadPath) {
Write-Host "WinAppDriver s'est installe avec succes !" -ForegroundColor Green
Write-Log "WinAppDriver est operationnel dans : $wadPath"
} else {
Write-Log "AVERTISSEMENT : L'installation s'est terminee mais WinAppDriver.exe n'est pas detectable."
}
} catch {
Write-Log "ERREUR lors de l'installation de WinAppDriver : $_"
Write-Host "Erreur lors de la configuration de WinAppDriver : $_" -ForegroundColor Red
}
# =========================================================================
# Création de la Tâche Planifiée Windows
# =========================================================================
Write-Log "=== Creation de la tache planifiee StartBeweapon ==="
Write-Host "Creation de la tache planifiee..." -ForegroundColor Cyan
$taskName = "StartBeweapon"
$scriptToRun = Join-Path $destinationDir "start_beweapon.ps1"
if (-not (Test-Path $scriptToRun)) {
$scriptToRun = Join-Path $destinationDir "start.ps1"
}
if (Test-Path $scriptToRun) {
try {
$action = New-ScheduledTaskAction -Execute "PowerShell.exe" -Argument "-ExecutionPolicy Bypass -File `"$scriptToRun`""
$trigger = New-ScheduledTaskTrigger -AtLogOn
$trigger.Delay = 'PT30S'
$currentUser = [System.Security.Principal.WindowsIdentity]::GetCurrent().Name
$principal = New-ScheduledTaskPrincipal -UserId $currentUser -RunLevel Highest
$settings = New-ScheduledTaskSettingsSet -AllowStartIfOnBatteries -DontStopIfGoingOnBatteries -StartWhenAvailable
Register-ScheduledTask -TaskName $taskName `
-Action $action `
-Trigger $trigger `
-Principal $principal `
-Settings $settings `
-Force -ErrorAction Stop | Out-Null
Write-Log "Tache planifiee '$taskName' creee avec succes pour$currentUser."
Write-Host "Tache planifiee '$taskName' creee avec succes." -ForegroundColor Green
} catch {
Write-Error "Echec de la creation de la tache planifiee : $_"
Write-Log "ERREUR lors de la creation de la tache planifiee : $_"
exit 1
}
} else {
Write-Error "Impossible de creer la tache planifiee : le script de demarrage est introuvable."
Write-Log "ERREUR : Script de demarrage introuvable dans $destinationDir."
exit 1
}
# Liste des lettres à démonter
$drives = @("D", "E", "F")
$shell = New-Object -ComObject Shell.Application
foreach ($drive in $drives) {
try {
$shell.Namespace(17).ParseName("${drive}:").InvokeVerb("Eject")
Write-Host "Lecteur ${drive}: éjecté avec succès." -ForegroundColor Green
} catch {
Write-Host "Impossible d'éjecter le lecteur ${drive}:" -ForegroundColor Red
}
}
# Liste des lettres à démonter
$drives = @("D", "E", "F")
$shell = New-Object -ComObject Shell.Application
foreach ($drive in $drives) {
try {
$shell.Namespace(17).ParseName("${drive}:").InvokeVerb("Eject")
Write-Host "Lecteur ${drive}: éjecté avec succès." -ForegroundColor Green
} catch {
Write-Host "Impossible d'éjecter le lecteur ${drive}:" -ForegroundColor Red
}
}
Write-Log "=== Fin de l'operation ==="