From abbad83bb1719fce7d4da36566d10165667d1664 Mon Sep 17 00:00:00 2001 From: hackercat Date: Fri, 26 Mar 2021 06:28:15 +0100 Subject: [PATCH] feat: Return `apt` packages with their installed versions (#2939) --- .../SoftwareReport/SoftwareReport.Common.psm1 | 18 ++++++++++++++---- .../SoftwareReport.Generator.ps1 | 2 +- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/images/linux/scripts/SoftwareReport/SoftwareReport.Common.psm1 b/images/linux/scripts/SoftwareReport/SoftwareReport.Common.psm1 index 6205569b..fabcc498 100644 --- a/images/linux/scripts/SoftwareReport/SoftwareReport.Common.psm1 +++ b/images/linux/scripts/SoftwareReport/SoftwareReport.Common.psm1 @@ -295,10 +295,20 @@ function Get-CachedDockerImagesTableData { } function Get-AptPackages { - $toolsetJson = Get-ToolsetContent - $apt = $toolsetJson.apt - $pkgs = ($apt.common_packages + $apt.cmd_packages | Sort-Object) -join ", " - return $pkgs + $apt = (Get-ToolsetContent).Apt + $output = @() + ForEach ($pkg in ($apt.common_packages + $apt.cmd_packages)) { + $version = $(dpkg-query -W -f '${Version}' $pkg) + if ($Null -eq $version) { + $version = $(dpkg-query -W -f '${Version}' "$pkg*") + } + + $output += [PSCustomObject] @{ + Name = $pkg + Version = $version + } + } + return ($output | Sort-Object Name) } function Get-PipxVersion { diff --git a/images/linux/scripts/SoftwareReport/SoftwareReport.Generator.ps1 b/images/linux/scripts/SoftwareReport/SoftwareReport.Generator.ps1 index e439e237..9d68370c 100644 --- a/images/linux/scripts/SoftwareReport/SoftwareReport.Generator.ps1 +++ b/images/linux/scripts/SoftwareReport/SoftwareReport.Generator.ps1 @@ -286,6 +286,6 @@ $markdown += Get-CachedDockerImagesTableData | New-MDTable $markdown += New-MDNewLine $markdown += New-MDHeader "Installed apt packages" -Level 3 -$markdown += New-MDList -Style Unordered -Lines @(Get-AptPackages) +$markdown += Get-AptPackages | New-MDTable $markdown | Out-File -FilePath "${OutputDirectory}/Ubuntu-Readme.md"