Files
Bastion-Stid/template/http/s3_pysnapcap.ps1
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

155 lines
5.6 KiB
PowerShell

Set-ExecutionPolicy Bypass -Scope Process -Force
function Write-Log {
param ([string]$Message)
"$Message" | Out-File -FilePath "C:\install.log" -Append -Encoding utf8
}
# Logs initiaux
Write-Log "=== Configuration et installation des prerequis pysnapcap ==="
Write-Host "=== Configuration et installation des prerequis pysnapcap ===" -ForegroundColor Cyan
# Detection automatique du lecteur CD 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
}
# Definition propre du chemin vers le dossier install
$installDir = Join-Path "$($cdDrive.Name):\" "install"
Write-Log "Dossier d'installation trouve : $installDir"
# Decompression de pysnapcap.zip
$zipFile = Get-ChildItem -Path $installDir -Filter "pysnapcap.zip" -ErrorAction SilentlyContinue | Select-Object -First 1
$projectDir = "C:\Users\Installer\Documents\pysnapcap"
if ($zipFile) {
$destinationPath = "C:\Users\Installer\Documents\"
Write-Log "Archive pysnapcap.zip trouvee ($($zipFile.FullName)). Extraction en cours vers $destinationPath..."
if (-not (Test-Path -Path $destinationPath)) {
New-Item -Path $destinationPath -ItemType Directory -Force | Out-Null
Write-Log "Dossier de destination $destinationPath cree."
}
try {
Expand-Archive -Path $zipFile.FullName -DestinationPath $destinationPath -Force -ErrorAction Stop
Write-Log "Archive pysnapcap.zip extraite avec succes dans $destinationPath"
} catch {
Write-Error "Echec de l'extraction de pysnapcap.zip : $_"
Write-Log "ERREUR lors de la decompression de pysnapcap.zip : $_"
exit 1
}
} else {
Write-Warning "Archive pysnapcap.zip introuvable dans $installDir"
Write-Log "AVERTISSEMENT : Archive pysnapcap.zip introuvable dans $installDir"
}
# ==========================================
# Detection de l'executable Python
# ==========================================
Write-Log "=== Recherche de Python ==="
$pythonCmd = Get-Command "py" -ErrorAction SilentlyContinue
if ($pythonCmd) {
$pythonExe = "py"
} else {
$pythonCmd = Get-Command "python" -ErrorAction SilentlyContinue
if ($pythonCmd) {
$pythonExe = "python"
} else {
$possiblePaths = @(
"$env:LocalAppData\Programs\Python\Python*\python.exe",
"C:\Python*\python.exe",
"C:\Program Files\Python*\python.exe"
)
$foundExe = Get-Item $possiblePaths -ErrorAction SilentlyContinue | Select-Object -First 1
if ($foundExe) {
$pythonExe = "$($foundExe.FullName)"
} else {
Write-Error "Python introuvable sur la machine."
Write-Log "ERREUR : Python introuvable sur la machine."
exit 1
}
}
}
Write-Log "Executable Python utilise : $pythonExe"
# ==========================================
# Installation de Poetry
# ==========================================
Write-Log "=== Installation de Poetry ==="
try {
(Invoke-WebRequest -Uri https://install.python-poetry.org -UseBasicParsing).Content | & $pythonExe -
Write-Log "Script d'installation de Poetry execute avec succes."
} catch {
Write-Error "Echec de l'installation de Poetry : $_"
Write-Log "ERREUR lors de l'installation de Poetry : $_"
exit 1
}
# Ajout du dossier binaire de Poetry au PATH
$possiblePoetryPaths = @(
"$env:APPDATA\Python\Scripts",
"$env:USERPROFILE\.local\bin"
)
$poetryPath = $possiblePoetryPaths | Where-Object { Test-Path $_ } | Select-Object -First 1
if ($poetryPath) {
if ($env:Path -notlike "*$poetryPath*") {
$env:Path += ";$poetryPath"
Write-Log "Chemin $poetryPath ajoute a la session courante."
}
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($userPath -notlike "*$poetryPath*") {
[Environment]::SetEnvironmentVariable("Path", "$userPath;$poetryPath", "User")
Write-Log "Chemin $poetryPath ajoute de facon permanente aux variables utilisateur."
}
} else {
Write-Warning "Le dossier d'installation de Poetry est introuvable."
Write-Log "AVERTISSEMENT : Aucun dossier d'installation Poetry trouve."
}
# Verification du fonctionnement de Poetry
try {
$poetryVersion = & "$poetryPath\poetry.exe" --version
Write-Log "Poetry est operationnel : $poetryVersion"
} catch {
Write-Log "ERREUR : Impossible de verifier la commande 'poetry' apres installation."
}
# ==========================================
# Installation des dependances du projet
# ==========================================
Write-Log "=== Installation des dependances Python via Poetry ==="
if (Test-Path $projectDir) {
Set-Location $projectDir
try {
# Contournement de l'erreur Windows Credential Manager / WinRM
Write-Log "Desactivation du keyring pour Poetry..."
& "$poetryPath\poetry.exe" config keyring.enabled false
# Installation des dépendances sans root
& "$poetryPath\poetry.exe" install --no-root
Write-Log "Dependances du projet installees avec succes."
} catch {
Write-Error "Echec de l'installation des dependances : $_"
Write-Log "ERREUR lors de 'poetry install' : $_"
exit 1
}
} else {
Write-Warning "Dossier projet $projectDir introuvable pour lancer 'poetry install'."
Write-Log "AVERTISSEMENT : Dossier $projectDir introuvable."
}
Write-Log "=== Fin de la configuration de pysnapcap ==="