# post_bootpack_pointer_refresh_v1.0.1.ps1 # Post-build hook for BootPack: refresh KB pointer + optional acceptance check (PS 5.1 safe) param( [string]$Root = '', [switch]$Preview, [switch]$NoPrompt, [switch]$Verify ) # --- Robust script path resolution (PS 5.1) --- # Prefer $PSScriptRoot / $PSCommandPath; fallback to $MyInvocation $ScriptDir = $null try{ if($PSScriptRoot){ $ScriptDir = $PSScriptRoot } }catch{} if([string]::IsNullOrWhiteSpace($ScriptDir)){ $thisPath = $null try{ if($PSCommandPath){ $thisPath = $PSCommandPath } }catch{} if([string]::IsNullOrWhiteSpace($thisPath)){ try{ $thisPath = $MyInvocation.MyCommand.Path }catch{} } if(-not [string]::IsNullOrWhiteSpace($thisPath)){ try{ $ScriptDir = [System.IO.Path]::GetDirectoryName($thisPath) }catch{} } } $DefaultRoot = $null if(-not [string]::IsNullOrWhiteSpace($ScriptDir)){ try{ $DefaultRoot = [System.IO.Path]::GetDirectoryName($ScriptDir) }catch{} } if([string]::IsNullOrWhiteSpace($Root)){ $Root = $DefaultRoot } # Dependencies (resolved relative to this script) $PtrRefresh = $null $Acceptance = $null if(-not [string]::IsNullOrWhiteSpace($ScriptDir)){ try{ $PtrRefresh = Join-Path $ScriptDir 'kb_pointer_refresh_v1.0.ps1' }catch{} try{ $Acceptance = Join-Path $ScriptDir 'kb_acceptance_tests_v1.0.1.ps1' }catch{} } # Plan (Preview) Write-Host '== PLAN :: post_bootpack_pointer_refresh_v1.0.1 ==' Write-Host ("Root : {0}" -f $Root) Write-Host ("ScriptDir : {0}" -f $ScriptDir) Write-Host ("PtrRefresh : {0} {1}" -f $PtrRefresh, (if([string]::IsNullOrWhiteSpace($PtrRefresh)){ $false } else { Test-Path -LiteralPath $PtrRefresh })) Write-Host ("Acceptance : {0} {1}" -f $Acceptance, (if([string]::IsNullOrWhiteSpace($Acceptance)){ $false } else { Test-Path -LiteralPath $Acceptance })) Write-Host ("Actions : 1) Refresh KB pointer 2) Verify PTR (optional)") if($Preview){ Write-Host '[PREVIEW] Simulation uniquement. Aucune écriture déclenchée par ce hook.' exit 0 } if(-not $NoPrompt){ $resp = Read-Host 'Exécuter le hook maintenant ? (O/N)' if($resp -notmatch '^[OoYy]'){ Write-Host '[ABORT] Hook non exécuté.'; exit 0 } } # Guards if([string]::IsNullOrWhiteSpace($Root) -or -not (Test-Path -LiteralPath $Root)){ Write-Host '[ERROR] Root introuvable.'; exit 3 } if([string]::IsNullOrWhiteSpace($PtrRefresh) -or -not (Test-Path -LiteralPath $PtrRefresh)){ Write-Host '[ERROR] kb_pointer_refresh_v1.0.ps1 introuvable.'; exit 3 } # 1) Refresh pointer + paste Write-Host '[STEP] Rafraîchissement du KB Pointer...' & powershell -NoProfile -ExecutionPolicy Bypass -File $PtrRefresh $Root $rc1 = $LASTEXITCODE if($rc1 -ne 0){ Write-Host ("[FAIL] kb_pointer_refresh_v1.0.ps1 rc={0}" -f $rc1) exit $rc1 } Write-Host '[OK] Pointer rafraîchi.' # 2) Acceptance (optionnel) if($Verify){ if([string]::IsNullOrWhiteSpace($Acceptance) -or -not (Test-Path -LiteralPath $Acceptance)){ Write-Host '[WARN] Test d’acceptance absent, skip vérification.' } else { Write-Host '[STEP] Vérification acceptance PTR...' & powershell -NoProfile -ExecutionPolicy Bypass -File $Acceptance $Root $rc2 = $LASTEXITCODE if($rc2 -ne 0){ Write-Host ("[FAIL] Acceptance PTR rc={0}" -f $rc2) exit $rc2 } Write-Host '[OK] Acceptance PTR PASS.' } } Write-Host '[OK] post_bootpack_pointer_refresh_v1.0.1 exécuté avec succès.' # DOC-VERSION-FOOTER: post_bootpack_pointer_refresh_v1.0.1.ps1 | Enc=UTF8-noBOM CRLF | _MAJ_=2025-10-22T18:47:00+02:00