Files
runner-images-sangeeth/images/ubuntu/scripts/docs-gen/SoftwareReport.Helpers.psm1
Shamil Mubarakshin 0c03739e50 [ubuntu] Refactor Common.Helpers (#8910)
* [ubuntu] Refactor Common.Helpers

* Move Get-AndroidPackages function from BeforeAll

* Fix ParameterBinding
2023-11-30 10:23:27 +01:00

55 lines
1.3 KiB
PowerShell

function Take-OutputPart {
param (
[Parameter(ValueFromPipeline)]
[string] $toolOutput,
[string] $Delimiter = " ",
[int[]] $Part
)
$parts = $toolOutput.Split($Delimiter, [System.StringSplitOptions]::RemoveEmptyEntries)
$selectedParts = $parts[$Part]
return [string]::Join($Delimiter, $selectedParts)
}
function Restore-UserOwner {
sudo chown -R ${env:USER}: $env:HOME
}
function Get-LinkTarget {
param (
[string] $inputPath
)
$link = Get-Item $inputPath | Select-Object -ExpandProperty Target
if ($link) {
return " -> $link"
}
return ""
}
function Get-PathWithLink {
param (
[string] $inputPath
)
$link = Get-LinkTarget($inputPath)
return "${inputPath}${link}"
}
function Get-AptSourceRepository {
param([String] $PackageName)
$sourceUrl = Get-Content "$PSScriptRoot/../helpers/apt-sources.txt" | Select-String -Pattern $PackageName | Take-OutputPart -Part (1..3)
return $sourceUrl
}
function Get-OSVersionShort {
$(Get-OSVersionFull) | Take-OutputPart -Delimiter '.' -Part 0,1
}
function Get-OSVersionFull {
lsb_release -ds | Take-OutputPart -Part 1, 2
}
function Get-KernelVersion {
$kernelVersion = uname -r
return $kernelVersion
}