mirror of
https://github.com/fleetdm/fleet
synced 2026-05-02 02:47:30 +00:00
This pull request adds support for managing the installation and uninstallation of Postman on Windows via Winget, and simplifies the associated PowerShell scripts. The changes introduce a new Postman app definition, refactor the install and uninstall scripts to remove unnecessary complexity, and update the Postman icon in the frontend to use a PNG image. **Postman app management support:** * Added a new `postman.json` manifest in `ee/maintained-apps/inputs/winget/` to define Postman as a managed application, including install/uninstall script paths and package metadata. **PowerShell script simplification:** * Refactored `postman_install.ps1` to remove scheduled task logic and run the installer directly with the `--silent` flag, improving reliability and maintainability. * Simplified `postman_uninstall.ps1` to directly search for and execute the uninstall command for Postman, supporting silent uninstallation and removing scheduled task and logging logic. **Frontend update:** * Updated the `Postman.tsx` icon component to use a PNG image instead of inline SVG paths, ensuring consistency with other icon assets.
87 lines
2.8 KiB
PowerShell
87 lines
2.8 KiB
PowerShell
# Fleet extracts name from installer (EXE) and saves it to PACKAGE_ID
|
|
# variable
|
|
$softwareName = $PACKAGE_ID
|
|
|
|
# It is recommended to use exact software name here if possible to avoid
|
|
# uninstalling unintended software.
|
|
$softwareNameLike = "*$softwareName*"
|
|
|
|
# Postman uninstaller supports --silent flag for silent uninstall
|
|
$uninstallArgs = "--silent"
|
|
|
|
$userKey = 'HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\*'
|
|
|
|
$exitCode = 0
|
|
|
|
try {
|
|
|
|
[array]$uninstallKeys = Get-ChildItem `
|
|
-Path @($userKey) `
|
|
-ErrorAction SilentlyContinue |
|
|
ForEach-Object { Get-ItemProperty $_.PSPath }
|
|
|
|
$foundUninstaller = $false
|
|
foreach ($key in $uninstallKeys) {
|
|
# If needed, add -notlike to the comparison to exclude certain similar
|
|
# software
|
|
if ($key.DisplayName -like $softwareNameLike) {
|
|
$foundUninstaller = $true
|
|
# Get the uninstall command. Some uninstallers do not include
|
|
# 'QuietUninstallString' and require a flag to run silently.
|
|
$uninstallCommand = if ($key.QuietUninstallString) {
|
|
$key.QuietUninstallString
|
|
} else {
|
|
$key.UninstallString
|
|
}
|
|
|
|
# The uninstall command may contain command and args, like:
|
|
# "C:\Program Files\Software\uninstall.exe" --uninstall --silent
|
|
# Split the command and args
|
|
$splitArgs = $uninstallCommand.Split('"')
|
|
if ($splitArgs.Length -gt 1) {
|
|
if ($splitArgs.Length -eq 3) {
|
|
$uninstallArgs = "$( $splitArgs[2] ) $uninstallArgs".Trim()
|
|
} elseif ($splitArgs.Length -gt 3) {
|
|
Throw `
|
|
"Uninstall command contains multiple quoted strings. " +
|
|
"Please update the uninstall script.`n" +
|
|
"Uninstall command: $uninstallCommand"
|
|
}
|
|
$uninstallCommand = $splitArgs[1]
|
|
}
|
|
Write-Host "Uninstall command: $uninstallCommand"
|
|
Write-Host "Uninstall args: $uninstallArgs"
|
|
|
|
$processOptions = @{
|
|
FilePath = $uninstallCommand
|
|
PassThru = $true
|
|
Wait = $true
|
|
}
|
|
if ($uninstallArgs -ne '') {
|
|
$processOptions.ArgumentList = "$uninstallArgs"
|
|
}
|
|
|
|
# Start process and track exit code
|
|
$process = Start-Process @processOptions
|
|
$exitCode = $process.ExitCode
|
|
|
|
# Prints the exit code
|
|
Write-Host "Uninstall exit code: $exitCode"
|
|
# Exit the loop once the software is found and uninstalled.
|
|
break
|
|
}
|
|
}
|
|
|
|
if (-not $foundUninstaller) {
|
|
Write-Host "Uninstaller for '$softwareName' not found."
|
|
# Change exit code to 0 if you don't want to fail if uninstaller is not
|
|
# found. This could happen if program was already uninstalled.
|
|
$exitCode = 1
|
|
}
|
|
|
|
} catch {
|
|
Write-Host "Error: $_"
|
|
$exitCode = 1
|
|
}
|
|
|
|
Exit $exitCode
|