2020-09-11 14:59:17 +03:00
|
|
|
function Get-CommandResult {
|
|
|
|
|
param (
|
|
|
|
|
[Parameter(Mandatory=$true)]
|
|
|
|
|
[string] $Command,
|
2021-12-28 11:16:20 +03:00
|
|
|
[int[]] $ExpectExitCode = 0,
|
|
|
|
|
[switch] $Multiline,
|
|
|
|
|
[bool] $ValidateExitCode = $true
|
2020-09-11 14:59:17 +03:00
|
|
|
)
|
2021-12-28 11:16:20 +03:00
|
|
|
|
2020-09-11 14:59:17 +03:00
|
|
|
# Bash trick to suppress and show error output because some commands write to stderr (for example, "python --version")
|
|
|
|
|
$stdout = & bash -c "$Command 2>&1"
|
|
|
|
|
$exitCode = $LASTEXITCODE
|
2021-12-28 11:16:20 +03:00
|
|
|
|
|
|
|
|
if ($ValidateExitCode) {
|
|
|
|
|
if ($ExpectExitCode -notcontains $exitCode) {
|
|
|
|
|
try {
|
|
|
|
|
throw "StdOut: '$stdout' ExitCode: '$exitCode'"
|
|
|
|
|
} catch {
|
|
|
|
|
Write-Host $_.Exception.Message
|
|
|
|
|
Write-Host $_.ScriptStackTrace
|
|
|
|
|
exit $LASTEXITCODE
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-11 14:59:17 +03:00
|
|
|
return @{
|
|
|
|
|
Output = If ($Multiline -eq $true) { $stdout } else { [string]$stdout }
|
|
|
|
|
ExitCode = $exitCode
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-12-13 17:07:05 +01:00
|
|
|
function Get-OSVersionShort {
|
|
|
|
|
$(Get-OSVersionFull) | Take-OutputPart -Delimiter '.' -Part 0,1
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Get-OSVersionFull {
|
|
|
|
|
lsb_release -ds | Take-OutputPart -Part 1, 2
|
2020-09-11 14:59:17 +03:00
|
|
|
}
|
|
|
|
|
|
2021-03-18 09:41:01 +03:00
|
|
|
function Get-KernelVersion {
|
|
|
|
|
$kernelVersion = uname -r
|
2022-12-13 17:07:05 +01:00
|
|
|
return $kernelVersion
|
2021-03-18 09:41:01 +03:00
|
|
|
}
|
|
|
|
|
|
2020-09-11 14:59:17 +03:00
|
|
|
function Test-IsUbuntu20 {
|
|
|
|
|
return (lsb_release -rs) -eq "20.04"
|
|
|
|
|
}
|
|
|
|
|
|
2022-05-02 10:46:10 +02:00
|
|
|
function Test-IsUbuntu22 {
|
|
|
|
|
return (lsb_release -rs) -eq "22.04"
|
|
|
|
|
}
|
|
|
|
|
|
2020-09-14 21:47:31 +03:00
|
|
|
function Get-ToolsetContent {
|
2020-09-11 14:59:17 +03:00
|
|
|
$toolset = Join-Path $env:INSTALLER_SCRIPT_FOLDER "toolset.json"
|
|
|
|
|
Get-Content $toolset -Raw | ConvertFrom-Json
|
2020-12-24 12:14:41 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Get-ToolsetValue {
|
|
|
|
|
param (
|
|
|
|
|
[Parameter(Mandatory = $true)]
|
|
|
|
|
[string] $KeyPath
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
$jsonNode = Get-ToolsetContent
|
|
|
|
|
|
|
|
|
|
$pathParts = $KeyPath.Split(".")
|
|
|
|
|
# try to walk through all arguments consequentially to resolve specific json node
|
|
|
|
|
$pathParts | ForEach-Object {
|
|
|
|
|
$jsonNode = $jsonNode.$_
|
|
|
|
|
}
|
|
|
|
|
return $jsonNode
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Get-AndroidPackages {
|
2023-06-16 18:34:04 +02:00
|
|
|
$packagesListFile = "/usr/local/lib/android/sdk/packages-list.txt"
|
|
|
|
|
|
|
|
|
|
if (-Not (Test-Path -Path $packagesListFile -PathType Leaf)) {
|
|
|
|
|
(/usr/local/lib/android/sdk/cmdline-tools/latest/bin/sdkmanager --list --verbose 2>&1) |
|
|
|
|
|
Where-Object { $_ -Match "^[^\s]" } |
|
|
|
|
|
Where-Object { $_ -NotMatch "^(Loading |Info: Parsing |---|\[=+|Installed |Available )" } |
|
|
|
|
|
Where-Object { $_ -NotMatch "^[^;]*$" } |
|
|
|
|
|
Out-File -FilePath $packagesListFile
|
|
|
|
|
|
|
|
|
|
Write-Host Android packages list:
|
|
|
|
|
Get-Content $packagesListFile
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return Get-Content $packagesListFile
|
2020-12-30 18:04:55 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function Get-EnvironmentVariable($variable) {
|
|
|
|
|
return [System.Environment]::GetEnvironmentVariable($variable)
|
2020-10-05 11:19:24 +03:00
|
|
|
}
|