Skip to content

Commit

Permalink
Merge pull request #566 from chezzer64/development
Browse files Browse the repository at this point in the history
EvergreenLibraryUpdate Fixes #488
  • Loading branch information
aaronparker authored Feb 18, 2024
2 parents bb4f52f + ea473f4 commit 19b2d5e
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
7 changes: 7 additions & 0 deletions Evergreen/Public/Export-EvergreenApp.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ function Export-EvergreenApp {
$InputObject += $Content
}

foreach ($AppLibInfo in $InputObject) {
if (([System.Uri]$AppLibInfo.URI).Host -like '*.dl.sourceforge.net') {
Write-Verbose "Normalise Sourceforge download mirror URL"
$AppLibInfo.URI = $AppLibInfo.URI -replace ([System.Uri]$AppLibInfo.URI).Host,"nchc.dl.sourceforge.net"
}
}

# Sort the content and keep unique versions
$Properties = $InputObject | Get-Member | `
Where-Object { $_.MemberType -eq "NoteProperty" } | Select-Object -ExpandProperty "Name" -Unique | `
Expand Down
32 changes: 30 additions & 2 deletions Evergreen/Public/Invoke-EvergreenLibraryUpdate.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ function Invoke-EvergreenLibraryUpdate {
Write-Verbose -Message "Library exists: $LibraryFile."
$Library = Get-Content -Path $LibraryFile -ErrorAction "Stop" | ConvertFrom-Json -ErrorAction "Stop"

# Get current list of install media files present in library
$LibContentBefore = Get-ChildItem -Path $Path -File -Recurse -Exclude "*.json" | Select-Object FullName | Sort-Object FullName

foreach ($Application in $Library.Applications) {

# Return the application details
Expand All @@ -55,6 +58,7 @@ function Invoke-EvergreenLibraryUpdate {
}

# Gather the application version information from Get-EvergreenApp
[array]$App = @()
$App = Get-EvergreenApp -Name $Application.EvergreenApp @params | Where-Object $WhereBlock

# If something returned, add to the library
Expand All @@ -69,7 +73,7 @@ function Invoke-EvergreenLibraryUpdate {
# Add the saved installer path to the application version information
if ($Saved.Count -gt 1) {
for ($i = 0; $i -lt $App.Count; $i++) {
$Item = $Saved | Where-Object { $_.FullName -match $App[$i].Version }
$Item = $Saved | Where-Object { $_.FullName -match $App[$i].Version -and ((Split-Path $_.FullName -Leaf) -eq (Split-Path $App[$i].URI -Leaf)) }
Write-Verbose -Message "Add path to object: $($Item.FullName)"
$App[$i] | Add-Member -MemberType "NoteProperty" -Name "Path" -Value $Item.FullName
}
Expand All @@ -80,9 +84,33 @@ function Invoke-EvergreenLibraryUpdate {
}

# Write the application version information to the library
Export-EvergreenApp -InputObject $App -Path $(Join-Path -Path $AppPath -ChildPath "$($Application.Name).json")
Export-EvergreenApp -InputObject $App -Path $(Join-Path -Path $AppPath -ChildPath "$($Application.Name).json") | Out-Null
}
}

# Get new list of install media files present in library following update
$LibContentAfter = Get-ChildItem -Path $Path -File -Recurse -Exclude "*.json" | Select-Object FullName | Sort-Object FullName

# Output details of library updates
if ($Null -eq $LibContentAfter) {
Write-Output "No Installer Media found in Evergreen Library"
}
elseif ($Null -ne $LibContentBefore) {
(Compare-Object $LibContentBefore $LibContentAfter -Property FullName -IncludeEqual | ForEach-Object {
[PSCustomObject]@{
Installer = $_.Fullname
Status = $_.SideIndicator -replace '=>','NEW' -replace '==','UNCHANGED' -replace '<=','DELETED'
}
})
}
else {
($LibContentAfter | ForEach-Object {
[PSCustomObject]@{
Installer = $_.Fullname
Status = 'NEW'
}
})
}
}
else {
$Msg = "$Path is not an Evergreen Library. Cannot find EvergreenLibrary.json. Create a library with New-EvergreenLibrary."
Expand Down

0 comments on commit 19b2d5e

Please sign in to comment.