master
ps1 95 lines 3 KB
Raw
1 # Generate the Netdata driver catalog file required by WiX packaging.
2 #
3 # Requires INF and SYS files already staged in the target directory.
4
5 #Requires -Version 4.0
6
7 param(
8 [Parameter(Mandatory = $true)]
9 [string]$DriverDirectory,
10
11 [Parameter()]
12 [string]$OsTargets = "10_GE_X64,10_25H2_X64,Server2025_X64,10_NI_X64,10_CO_X64,ServerFE_X64,10_VB_X64,10_19H1_X64,10_RS5_X64,ServerRS5_X64,10_RS4_X64,10_RS3_X64,10_RS2_X64,10_AU_X64,10_X64,Server10_X64"
13 )
14
15 $ErrorActionPreference = "Stop"
16
17 function Find-Inf2Cat {
18 $command = Get-Command Inf2Cat.exe -ErrorAction SilentlyContinue
19 if ($null -ne $command) {
20 return $command.Source
21 }
22
23 $kitRoots = @(
24 (Join-Path ${env:ProgramFiles(x86)} "Windows Kits\10\bin"),
25 (Join-Path $env:ProgramFiles "Windows Kits\10\bin")
26 )
27
28 $candidates = @()
29 foreach ($root in $kitRoots) {
30 if (Test-Path $root) {
31 # Prefer the typical WDK/SDK layout: Windows Kits\10\bin\<version>\x64\Inf2Cat.exe
32 $patternX64 = Join-Path $root '*\x64\Inf2Cat.exe'
33 $found = Get-ChildItem -Path $patternX64 -File -ErrorAction SilentlyContinue
34 if (-not $found) {
35 # Fallback: any versioned subfolder directly under bin containing Inf2Cat.exe
36 $patternAnyArch = Join-Path $root '*\Inf2Cat.exe'
37 $found = Get-ChildItem -Path $patternAnyArch -File -ErrorAction SilentlyContinue
38 if ($found) {
39 $candidates += $found
40 }
41 }
42 }
43 }
44
45 if ($candidates.Count -eq 0) {
46 throw "Inf2Cat.exe not found. Install Windows Driver Kit (WDK) or Windows SDK tools with Inf2Cat."
47 }
48
49 $x64Candidates = $candidates | Where-Object { $_.FullName -match '\\x64\\Inf2Cat\.exe$' }
50 if ($x64Candidates.Count -gt 0) {
51 $candidates = $x64Candidates
52 }
53
54 $latest = $candidates |
55 Sort-Object -Property {
56 $match = [regex]::Match($_.FullName, '\\10\\bin\\(?<ver>\d+\.\d+\.\d+\.\d+)\\')
57 if ($match.Success) {
58 [version]$match.Groups['ver'].Value
59 } else {
60 [version]"0.0.0.0"
61 }
62 } -Descending |
63 Select-Object -First 1
64
65 return $latest.FullName
66 }
67
68 $driverDir = (Resolve-Path -LiteralPath $DriverDirectory).Path
69 $driverInf = Join-Path $driverDir "netdata_driver.inf"
70 $driverSys = Join-Path $driverDir "netdata_driver.sys"
71 $driverCat = Join-Path $driverDir "netdata_driver.cat"
72
73 if (-not (Test-Path $driverInf)) {
74 throw "Missing driver INF: $driverInf"
75 }
76
77 if (-not (Test-Path $driverSys)) {
78 throw "Missing driver SYS: $driverSys"
79 }
80
81 $inf2cat = Find-Inf2Cat
82 Write-Host "Using Inf2Cat: $inf2cat"
83 Write-Host "Generating driver catalog in: $driverDir"
84
85 & $inf2cat "/driver:$driverDir" "/os:$OsTargets"
86
87 if ($LastExitCode -ne 0) {
88 throw "Inf2Cat failed with exit code $LastExitCode"
89 }
90
91 if (-not (Test-Path $driverCat)) {
92 throw "Catalog generation failed, missing output: $driverCat"
93 }
94
95 Write-Host "Generated driver catalog: $driverCat"