- 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>
133 lines
4.9 KiB
PowerShell
133 lines
4.9 KiB
PowerShell
#Requires -RunAsAdministrator
|
|
|
|
Set-ExecutionPolicy Bypass -Scope Process -Force
|
|
$ErrorActionPreference = "Stop"
|
|
$LogFile = "C:\install.log"
|
|
|
|
function Write-Log($msg) {
|
|
$time = Get-Date -Format "yyyy-MM-dd HH:mm:ss"
|
|
Add-Content -Path $LogFile -Value "$time - $msg" -Encoding UTF8
|
|
Write-Host "$msg" -ForegroundColor Cyan
|
|
}
|
|
|
|
Write-Log "=========================================="
|
|
Write-Log "Debut de l installation silencieuse com0com"
|
|
|
|
# 1. Activation de TESTSIGNING
|
|
Write-Log "Verification de TESTSIGNING..."
|
|
$bcd = bcdedit.exe /enum '{current}'
|
|
if (($bcd -join "`n") -notmatch "testsigning\s+Yes") {
|
|
Write-Log "Activation TESTSIGNING..."
|
|
bcdedit.exe /set testsigning on | Out-Null
|
|
Write-Log "ATTENTION: Un redemarrage est requis si TESTSIGNING vient d etre active."
|
|
}
|
|
|
|
# 2. Localisation de setup.exe
|
|
Write-Log "Recherche de setup.exe..."
|
|
$setupExe = $null
|
|
|
|
$drives = Get-PSDrive -PSProvider FileSystem
|
|
foreach ($drive in $drives) {
|
|
$targetPath = Join-Path $drive.Root "install\setup.exe"
|
|
if (Test-Path $targetPath) {
|
|
$setupExe = Get-Item $targetPath
|
|
break
|
|
}
|
|
}
|
|
|
|
if (-not $setupExe) {
|
|
$setupExe = Get-ChildItem -Path "C:\install", "D:\install" -Filter "setup.exe" -Recurse -ErrorAction SilentlyContinue | Select-Object -First 1
|
|
}
|
|
|
|
if ($setupExe) {
|
|
Write-Log "Installeur trouve : $($setupExe.FullName)"
|
|
|
|
# 3. Installation silencieuse de setup.exe
|
|
Write-Log "Lancement de l installeur silencieux..."
|
|
$proc = Start-Process -FilePath $setupExe.FullName -ArgumentList "/S" -Wait -PassThru
|
|
Write-Log "Code de retour installeur : $($proc.ExitCode)"
|
|
} else {
|
|
Write-Log "ERREUR : setup.exe introuvable."
|
|
exit 1
|
|
}
|
|
|
|
# 4. Localisation des fichiers installés
|
|
$setupc = "C:\Program Files (x86)\com0com\setupc.exe"
|
|
if (-not (Test-Path $setupc)) {
|
|
$setupc = "C:\Program Files\com0com\setupc.exe"
|
|
}
|
|
|
|
if (Test-Path $setupc) {
|
|
$workDir = Split-Path $setupc -Parent
|
|
$infFile = Join-Path $workDir "com0com.inf"
|
|
|
|
# 5. Extraction et ajout de TOUS les certificats signatures trouvés dans le dossier com0com
|
|
Write-Log "Extraction des certificats depuis le dossier : $workDir"
|
|
|
|
# Recherche de tous les fichiers susceptibles d'être signés (.sys, .cat, .dll, .exe, .cer, .crt)
|
|
$filesToScan = Get-ChildItem -Path $workDir -Recurse -Include "*.sys", "*.cat", "*.dll", "*.exe", "*.cer", "*.crt"
|
|
|
|
$importedThumbprints = @()
|
|
|
|
foreach ($file in $filesToScan) {
|
|
# Si c'est déjà un fichier certificat (.cer / .crt)
|
|
if ($file.Extension -match "\.(cer|crt)$") {
|
|
Write-Log "Fichier certificat brut trouve : $($file.Name)"
|
|
certutil.exe -addstore "TrustedPublisher" $file.FullName | Out-Null
|
|
certutil.exe -addstore "Root" $file.FullName | Out-Null
|
|
Write-Log "Certificat $($file.Name) importe dans TrustedPublisher et Root."
|
|
continue
|
|
}
|
|
|
|
# Si c'est un fichier signé (.sys, .cat, .dll, .exe)
|
|
$sig = Get-AuthenticodeSignature -FilePath $file.FullName
|
|
if ($sig.SignerCertificate) {
|
|
$cert = $sig.SignerCertificate
|
|
|
|
# Évite d'importer plusieurs fois le même certificat s'il signe plusieurs fichiers
|
|
if ($importedThumbprints -notcontains $cert.Thumbprint) {
|
|
$certPath = Join-Path $env:TEMP "$($cert.Thumbprint).cer"
|
|
[System.IO.File]::WriteAllBytes($certPath, $cert.Export([System.Security.Cryptography.X509Certificates.X509ContentType]::Cert))
|
|
|
|
certutil.exe -addstore "TrustedPublisher" $certPath | Out-Null
|
|
certutil.exe -addstore "Root" $certPath | Out-Null
|
|
|
|
$importedThumbprints += $cert.Thumbprint
|
|
Write-Log "Certificat extrait et importe : '$($cert.Subject)' (Thumbprint: $($cert.Thumbprint))"
|
|
|
|
Remove-Item $certPath -Force -ErrorAction SilentlyContinue
|
|
}
|
|
}
|
|
}
|
|
|
|
# 6. Enregistrement du pilote via PnPUtil
|
|
if (Test-Path $infFile) {
|
|
Write-Log "Enregistrement du pilote com0com.inf dans le magasin Windows..."
|
|
pnputil.exe /add-driver "$infFile" /install | Out-Null
|
|
}
|
|
|
|
# 7. Création des ports COM30 et COM31
|
|
Write-Log "Creation des ports COM30 et COM31..."
|
|
|
|
# Fichier vide pour rediriger STDIN afin de parer tout blocage d'attente d'entrée
|
|
$nullFile = Join-Path$env:TEMP "stdin_null.txt"
|
|
New-Item -Path $nullFile -ItemType File -Force | Out-Null
|
|
|
|
$p = Start-Process -FilePath$setupc `
|
|
-ArgumentList "install PortName=COM30 PortName=COM31" `
|
|
-WorkingDirectory $workDir `
|
|
-RedirectStandardInput $nullFile `
|
|
-NoNewWindow `
|
|
-Wait `
|
|
-PassThru
|
|
|
|
Write-Log "Code de retour setupc : $($p.ExitCode)"
|
|
|
|
Remove-Item $nullFile -Force -ErrorAction SilentlyContinue
|
|
} else {
|
|
Write-Log "ERREUR : setupc.exe est introuvable."
|
|
exit 1
|
|
}
|
|
|
|
Write-Log "Fin du traitement."
|