Skip to content

Commit a254275

Browse files
Support offline OS and driver catalogs, add post-network script execution, and improve download reliability
- Add support for importing offline OS catalogs in - Get-OSDCloudOperatingSystems.ps1 - Get-OSDCloudOperatingSystemsIndexMap.ps1 - Get-OSDCloudOperatingSystemsIndexes.ps1 - Add offline driver catalog support in OSDCloud.DriverPack.ps1 - Add post-network script execution and optional supression of module auto-update in - Initialize-OSDCloudStartNet.ps1 - OSDCloudTemplate.ps1 - Improve Save-WebFile.ps1 by checking HTTP headers before download
1 parent f57a8d8 commit a254275

File tree

7 files changed

+116
-32
lines changed

7 files changed

+116
-32
lines changed

Public/Functions/Other/Save-WebFile.ps1

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,13 +116,17 @@ function Save-WebFile {
116116
else {
117117
Write-Verbose "cURL Source: $SourceUrl"
118118
Write-Verbose "Destination: $DestinationFullName"
119-
120-
if ($host.name -match 'ConsoleHost') {
121-
Invoke-Expression "& curl.exe --insecure --location --output `"$DestinationFullName`" --url `"$SourceUrl`""
122-
}
123-
else {
124-
#PowerShell ISE will display a NativeCommandError, so progress will not be displayed
125-
$Quiet = Invoke-Expression "& curl.exe --insecure --location --output `"$DestinationFullName`" --url `"$SourceUrl`" 2>&1"
119+
$Headers = Invoke-Expression "& curl.exe --head --silent --insecure --location --url `"$SourceUrl`""
120+
if ($Headers[0] -match "200.+OK") {
121+
if ($host.name -match 'ConsoleHost') {
122+
Invoke-Expression "& curl.exe --insecure --location --output `"$DestinationFullName`" --url `"$SourceUrl`""
123+
}
124+
else {
125+
#PowerShell ISE will display a NativeCommandError, so progress will not be displayed
126+
$Quiet = Invoke-Expression "& curl.exe --insecure --location --output `"$DestinationFullName`" --url `"$SourceUrl`" 2>&1"
127+
}
128+
} else {
129+
Write-Warning "Header status: $($headers[0])"
126130
}
127131
}
128132
#=================================================

Public/OSDCloudDriverPack/OSDCloud.DriverPack.ps1

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,17 @@ function Get-OSDCloudDriverPacks {
6767
#>
6868
[CmdletBinding()]
6969
param ()
70-
$Results = Import-Clixml -Path "$(Get-OSDModulePath)\cache\driverpack-catalogs\build-driverpacks.xml"
70+
$DriverCatalogXML = Get-PSDrive -PSProvider FileSystem | Where-Object {$_.Name -ne 'C'} | ForEach-Object {
71+
Get-ChildItem "$($_.Root)OSDCloud\Catalogs" -Include "build-driverpacks.xml" -File -Force -Recurse -ErrorAction Ignore
72+
}
73+
if ($DriverCatalogXML) {
74+
foreach ($Item in $DriverCatalogXML) {
75+
Write-Warning "$($Item.FullName) is imported instead of the cache under $(Get-OSDModulePath)."
76+
$Results = Import-Clixml -Path $Item.FullName
77+
}
78+
} else {
79+
$Results = Import-Clixml -Path "$(Get-OSDModulePath)\cache\driverpack-catalogs\build-driverpacks.xml"
80+
}
7181
$Results
7282
}
7383
function Save-OSDCloudDriverPack {

Public/OSDCloudSetup/OSDCloudTemplate.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1014,7 +1014,8 @@ Windows Registry Editor Version 5.00
10141014
'Config\Scripts\SetupComplete',
10151015
'Config\Scripts\Shutdown',
10161016
'Config\Scripts\Startup',
1017-
'Config\Scripts\StartNet'
1017+
'Config\Scripts\StartNet',
1018+
'Config\Scripts\StartNet2'
10181019
)
10191020

10201021
if ($Name -match 'public') {

Public/OSDCloudTS/Get-OSDCloudOperatingSystems.ps1

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,18 @@ function Get-OSDCloudOperatingSystems {
1616
[System.String]
1717
$OSArch = 'x64'
1818
)
19-
$FullResults = Get-Content -Path "$(Get-OSDModulePath)\cache\archive-cloudoperatingsystems\CloudOperatingSystems.json" | ConvertFrom-Json
20-
if ($OSArch -eq 'x64'){
21-
$Results = $FullResults | Where-Object {$_.Architecture -eq "x64"}
19+
$OfflineCatalog = Get-PSDrive -PSProvider FileSystem | Where-Object {$_.Name -ne 'C'} | ForEach-Object {
20+
Get-ChildItem "$($_.Root)OSDCloud\Catalogs" -Include "CloudOperatingSystems.json" -File -Force -Recurse -ErrorAction Ignore
2221
}
23-
elseif ($OSArch -eq "arm64"){
24-
$Results = Get-Content -Path "$(Get-OSDModulePath)\cache\archive-cloudoperatingsystems\CloudOperatingSystemsARM64.json" | ConvertFrom-Json
22+
if ($OfflineCatalog) {
23+
foreach ($Item in $OfflineCatalog) {
24+
Write-Warning "$($Item.FullName) is imported instead of the cache under $(Get-OSDModulePath)."
25+
$FullResults = Get-Content -Path "$($Item.FullName)" | ConvertFrom-Json -ErrorAction "Stop"
26+
}
27+
$Results = $FullResults | Where-Object {$_.Architecture -eq $OSArch}
28+
} else {
29+
$FullResults = Get-Content -Path "$(Get-OSDModulePath)\cache\archive-cloudoperatingsystems\CloudOperatingSystems.json" | ConvertFrom-Json
30+
$Results = $FullResults | Where-Object {$_.Architecture -eq $OSArch}
2531
}
2632
$Results
2733
}

Public/OSDCloudTS/Get-OSDCloudOperatingSystemsIndexMap.ps1

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,19 @@ function Get-OSDCloudOperatingSystemsIndexMap {
2121
$OSArch = 'x64'
2222
)
2323

24-
$indexMapPath = "$(Get-OSDModulePath)\cache\archive-cloudoperatingindexmap\CloudOperatingIndexMap.json"
25-
$Results = Get-Content -Path $indexMapPath | ConvertFrom-Json
24+
$OfflineCatalog = Get-PSDrive -PSProvider FileSystem | Where-Object {$_.Name -ne 'C'} | ForEach-Object {
25+
Get-ChildItem "$($_.Root)OSDCloud\Catalogs" -Include "CloudOperatingIndexMap.json" -File -Force -Recurse -ErrorAction Ignore
26+
}
27+
if ($OfflineCatalog) {
28+
foreach ($Item in $OfflineCatalog) {
29+
Write-Warning "$($Item.FullName) is imported instead of the cache under $(Get-OSDModulePath)."
30+
$indexMapPath = (Get-Item -Path "$($Item.FullName)").FullName
31+
}
32+
} else {
33+
$indexMapPath = "$(Get-OSDCachePath)\archive-cloudoperatingindexmap\CloudOperatingIndexMap.json"
34+
}
35+
$Results = Get-Content -Path $indexMapPath -Encoding UTF8 | ConvertFrom-Json # as of OSD 25.6.10.1 encoding of the json is UTF8
2636
$Results = $Results | Where-Object { $_.Architecture -eq $OSArch }
2737

2838
return $Results
29-
}
39+
}

Public/OSDCloudTS/Get-OSDCloudOperatingSystemsIndexes.ps1

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,30 @@ function Get-OSDCloudOperatingSystemsIndexes {
1919
)
2020

2121
if ($OSArch -eq 'x64') {
22-
$Results = Get-Content -Path "$(Get-OSDModulePath)\cache\archive-cloudoperatingsystems\CloudOperatingSystemsIndexes.json" | ConvertFrom-Json
22+
$OfflineCatalog = Get-PSDrive -PSProvider FileSystem | Where-Object {$_.Name -ne 'C'} | ForEach-Object {
23+
Get-ChildItem "$($_.Root)OSDCloud\Catalogs" -Include "CloudOperatingSystemsIndexes.json" -File -Force -Recurse -ErrorAction Ignore
24+
}
25+
if ($OfflineCatalog) {
26+
foreach ($Item in $OfflineCatalog) {
27+
Write-Warning "$($Item.FullName) is imported instead of the cache under $(Get-OSDModulePath)."
28+
$Results = Get-Content -Path "$($Item.FullName)" | ConvertFrom-Json -ErrorAction "Stop"
29+
}
30+
} else {
31+
$Results = Get-Content -Path "$(Get-OSDCachePath)\archive-cloudoperatingsystems\CloudOperatingSystemsIndexes.json" | ConvertFrom-Json
32+
}
2333
}
2434
elseif ($OSArch -eq "ARM64") {
25-
$Results = Get-Content -Path "$(Get-OSDModulePath)\cache\archive-cloudoperatingsystems\CloudOperatingSystemsARM64Indexes.json" | ConvertFrom-Json
35+
$OfflineCatalog = Get-PSDrive -PSProvider FileSystem | Where-Object {$_.Name -ne 'C'} | ForEach-Object {
36+
Get-ChildItem "$($_.Root)OSDCloud\Catalogs" -Include "CloudOperatingSystemsARM64Indexes.json" -File -Force -Recurse -ErrorAction Ignore
37+
}
38+
if ($OfflineCatalog) {
39+
foreach ($Item in $OfflineCatalog) {
40+
Write-Warning "$($Item.FullName) is imported instead of the cache under $(Get-OSDModulePath)."
41+
$Results = Get-Content -Path "$($Item.FullName)" | ConvertFrom-Json -ErrorAction "Stop"
42+
}
43+
} else {
44+
$Results = Get-Content -Path "$(Get-OSDCachePath)\archive-cloudoperatingsystems\CloudOperatingSystemsARM64Indexes.json" | ConvertFrom-Json
45+
}
2646
}
2747

2848
return $Results

Public/OSDCloudTS/Initialize-OSDCloudStartnet.ps1

Lines changed: 46 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -142,20 +142,53 @@ function Initialize-OSDCloudStartnet {
142142
}
143143
}
144144

145-
# Check if the OSD Module in the PowerShell Gallery is newer than the installed version
146-
$TimeSpan = New-TimeSpan -Start $Global:StartnetStart -End (Get-Date)
147-
Write-Host -ForegroundColor DarkGray "$($TimeSpan.ToString("mm':'ss")) Updating OSD PowerShell Module"
148-
$PSModuleName = 'OSD'
149-
$InstalledModule = Get-Module -Name $PSModuleName -ListAvailable -ErrorAction Ignore | Sort-Object Version -Descending | Select-Object -First 1
150-
$GalleryPSModule = Find-Module -Name $PSModuleName -ErrorAction Ignore -WarningAction Ignore
151-
152-
# Install the OSD module if it is not installed or if the version is older than the gallery version
153-
if ($GalleryPSModule) {
154-
if (($GalleryPSModule.Version -as [version]) -gt ($InstalledModule.Version -as [version])) {
155-
Write-Host -ForegroundColor DarkGray "$PSModuleName $($GalleryPSModule.Version) [AllUsers]"
156-
Install-Module $PSModuleName -Scope AllUsers -Force -SkipPublisherCheck
157-
Import-Module $PSModuleName -Force
145+
Write-Host -ForegroundColor Cyan '[i] Config Post StartNet Scripts'
146+
$Global:ScriptStartNet2 = Get-PSDrive -PSProvider FileSystem | Where-Object { $_.Name -ne 'C' } | ForEach-Object {
147+
Write-Host -ForegroundColor DarkGray "$($_.Root)OSDCloud\Config\Scripts\StartNet2\*.ps1"
148+
Get-ChildItem "$($_.Root)OSDCloud\Config\Scripts\StartNet2\" -Include "*.ps1" -File -Recurse -Force -ErrorAction Ignore
149+
}
150+
if ($Global:ScriptStartNet2) {
151+
$Global:ScriptStartNet2 = $Global:ScriptStartNet2 | Sort-Object -Property FullName
152+
foreach ($Item in $Global:ScriptStartNet2) {
153+
Write-Host -ForegroundColor Gray "Execute $($Item.FullName)"
154+
& "$($Item.FullName)"
155+
}
156+
$TimeSpan = New-TimeSpan -Start $Global:StartnetStart -End (Get-Date)
157+
Write-Host -ForegroundColor DarkGray "$($TimeSpan.ToString("mm':'ss")) Tried to execute Post StartNet Scripts"
158+
}
159+
160+
Write-Host -ForegroundColor Cyan '[i] OSD module update'
161+
$Global:OSDModuleUpdate = $true # Default is trying to newer OSD module
162+
$Global:OSDCloudStartnetJson = Get-PSDrive -PSProvider FileSystem | Where-Object {$_.Name -ne 'C'} | ForEach-Object {
163+
Get-ChildItem "$($_.Root)OSDCloud\Config" -Include "Initialize-OSDCloudStartnet.json" -File -Force -Recurse -ErrorAction Ignore
164+
}
165+
if ($Global:OSDCloudStartnetJson ) {
166+
foreach ($Item in $Global:OSDCloudStartnetJson) {
167+
Write-Host -ForegroundColor DarkGray "$($Item.FullName)"
168+
$Global:OSDModuleUpdate = (Get-Content -Path "$($Item.FullName)" | ConvertFrom-Json -ErrorAction "Stop").OSDAutoUpdate
169+
Write-Host -ForegroundColor DarkGray "- OSDAutoUpdate: $($Global:OSDModuleUpdate)"
158170
}
159171
}
172+
if ($Global:OSDModuleUpdate) {
173+
# Check if the OSD Module in the PowerShell Gallery is newer than the installed version
174+
$TimeSpan = New-TimeSpan -Start $Global:StartnetStart -End (Get-Date)
175+
Write-Host -ForegroundColor DarkGray "$($TimeSpan.ToString("mm':'ss")) Updating OSD PowerShell Module"
176+
$PSModuleName = 'OSD'
177+
$InstalledModule = Get-Module -Name $PSModuleName -ListAvailable -ErrorAction Ignore | Sort-Object Version -Descending | Select-Object -First 1
178+
$GalleryPSModule = Find-Module -Name $PSModuleName -ErrorAction Ignore -WarningAction Ignore
179+
180+
# Install the OSD module if it is not installed or if the version is older than the gallery version
181+
if ($GalleryPSModule) {
182+
if (($GalleryPSModule.Version -as [version]) -gt ($InstalledModule.Version -as [version])) {
183+
Write-Host -ForegroundColor DarkGray "$PSModuleName $($GalleryPSModule.Version) [AllUsers]"
184+
Install-Module $PSModuleName -Scope AllUsers -Force -SkipPublisherCheck
185+
Import-Module $PSModuleName -Force
186+
}
187+
}
188+
} else {
189+
# if json contains {"OSDAutoUpdate": false} then not trying to import newer OSD module
190+
$TimeSpan = New-TimeSpan -Start $Global:StartnetStart -End (Get-Date)
191+
Write-Host -ForegroundColor DarkGray "$($TimeSpan.ToString("mm':'ss")) Skip Updating OSD PowerShell Module"
192+
}
160193
}
161194
}

0 commit comments

Comments
 (0)