Files
winutil/functions/private/Test-WinUtilPackageManager.ps1
T

97 lines
4.4 KiB
PowerShell
Raw Normal View History

+3
2023-03-07 12:28:00 -08:00
function Test-WinUtilPackageManager {
<#
2023-10-19 17:12:55 -05:00
.SYNOPSIS
Checks if Winget and/or Choco are installed
.PARAMETER winget
Check if Winget is installed
.PARAMETER choco
Check if Chocolatey is installed
+3
2023-03-07 12:28:00 -08:00
#>
Param(
[System.Management.Automation.SwitchParameter]$winget,
[System.Management.Automation.SwitchParameter]$choco
)
$status = "not-installed"
2024-02-06 14:02:58 -06:00
if ($winget) {
+26
2024-06-04 20:27:27 -07:00
# Check if Winget is available while getting it's Version if it's available
$wingetExists = $true
try {
$wingetVersionFull = winget --version
} catch [System.Management.Automation.CommandNotFoundException], [System.Management.Automation.ApplicationFailedException] {
Write-Warning "Winget was not found due to un-availablity reasons"
$wingetExists = $false
} catch {
Write-Warning "Winget was not found due to un-known reasons, The Stack Trace is:`n$($psitem.Exception.StackTrace)"
$wingetExists = $false
}
+26
2024-06-04 20:27:27 -07:00
# If Winget is available, Parse it's Version and give proper information to Terminal Output.
# If it isn't available, the return of this funtion will be "not-installed", indicating that
+26
2024-06-04 20:27:27 -07:00
# Winget isn't installed/available on The System.
if ($wingetExists) {
# Check if Preview Version
if ($wingetVersionFull.Contains("-preview")) {
$wingetVersion = $wingetVersionFull.Trim("-preview")
$wingetPreview = $true
+8
2024-03-21 16:23:24 -07:00
} else {
$wingetVersion = $wingetVersionFull
$wingetPreview = $false
+8
2024-03-21 16:23:24 -07:00
}
# Check if Winget's Version is too old.
$wingetCurrentVersion = [System.Version]::Parse($wingetVersion.Trim('v'))
+1
2024-04-20 16:38:43 -05:00
# Grabs the latest release of Winget from the Github API for version check process.
$response = Invoke-RestMethod -Uri "https://api.github.com/repos/microsoft/Winget-cli/releases/latest" -Method Get -ErrorAction Stop
$wingetLatestVersion = [System.Version]::Parse(($response.tag_name).Trim('v')) #Stores version number of latest release.
$wingetOutdated = $wingetCurrentVersion -lt $wingetLatestVersion
Write-Host "===========================================" -ForegroundColor Green
+1
2024-04-20 16:38:43 -05:00
Write-Host "--- Winget is installed ---" -ForegroundColor Green
Write-Host "===========================================" -ForegroundColor Green
Write-Host "Version: $wingetVersionFull" -ForegroundColor White
if (!$wingetPreview) {
Write-Host " - Winget is a release version." -ForegroundColor Green
} else {
Write-Host " - Winget is a preview version. Unexpected problems may occur." -ForegroundColor Yellow
}
if (!$wingetOutdated) {
Write-Host " - Winget is Up to Date" -ForegroundColor Green
$status = "installed"
} else {
Write-Host " - Winget is Out of Date" -ForegroundColor Red
$status = "outdated"
}
} else {
Write-Host "===========================================" -ForegroundColor Red
+1
2024-04-20 16:38:43 -05:00
Write-Host "--- Winget is not installed ---" -ForegroundColor Red
Write-Host "===========================================" -ForegroundColor Red
$status = "not-installed"
+3
2023-03-07 12:28:00 -08:00
}
}
+8
2024-03-21 16:23:24 -07:00
if ($choco) {
if ((Get-Command -Name choco -ErrorAction Ignore) -and ($chocoVersion = (Get-Item "$env:ChocolateyInstall\choco.exe" -ErrorAction Ignore).VersionInfo.ProductVersion)) {
Write-Host "===========================================" -ForegroundColor Green
+1
2024-04-20 16:38:43 -05:00
Write-Host "--- Chocolatey is installed ---" -ForegroundColor Green
Write-Host "===========================================" -ForegroundColor Green
Write-Host "Version: v$chocoVersion" -ForegroundColor White
$status = "installed"
} else {
Write-Host "===========================================" -ForegroundColor Red
+1
2024-04-20 16:38:43 -05:00
Write-Host "--- Chocolatey is not installed ---" -ForegroundColor Red
Write-Host "===========================================" -ForegroundColor Red
$status = "not-installed"
+3
2023-03-07 12:28:00 -08:00
}
}
return $status
+8
2024-03-21 16:23:24 -07:00
}