mirror of
https://github.com/fleetdm/fleet
synced 2026-05-01 18:37:37 +00:00
This pull request adds full support for managing the installation and uninstallation of Spotify on Windows via winget in the maintained apps system. It introduces new configuration and script files, updates output manifests, and ensures that both install and uninstall processes are handled silently and robustly. **Spotify Windows app integration:** * Added a new manifest `spotify.json` in `ee/maintained-apps/inputs/winget` to define Spotify's winget package details, including references to custom install and uninstall scripts. * Updated `ee/maintained-apps/outputs/apps.json` to register the Spotify Windows app, enabling it to be discovered and managed by the platform. * Added a new output manifest `ee/maintained-apps/outputs/spotify/windows.json` specifying the installer URL, version, install/uninstall script references, and detection query for Spotify. **Installation and uninstallation scripting:** * Introduced a PowerShell install script `spotify_install.ps1` that performs a silent installation of Spotify, handling exit codes and errors gracefully. * Added a PowerShell uninstall script `spotify_uninstall.ps1` that locates Spotify's uninstaller via the registry, kills running processes, and executes the uninstall silently, preserving existing arguments and handling errors.
83 lines
2.6 KiB
PowerShell
83 lines
2.6 KiB
PowerShell
# Attempts to locate Spotify's uninstaller from registry and execute it silently
|
|
|
|
$displayName = "Spotify"
|
|
$publisher = "Spotify AB"
|
|
|
|
# Spotify is user-scope, so check HKCU first, then HKLM as fallback
|
|
$paths = @(
|
|
'HKCU:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',
|
|
'HKCU:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall',
|
|
'HKLM:\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall',
|
|
'HKLM:\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall'
|
|
)
|
|
|
|
$uninstall = $null
|
|
foreach ($p in $paths) {
|
|
$items = Get-ItemProperty "$p\*" -ErrorAction SilentlyContinue | Where-Object {
|
|
$_.DisplayName -and ($_.DisplayName -eq $displayName -or $_.DisplayName -like "$displayName*") -and ($publisher -eq "" -or $_.Publisher -eq $publisher)
|
|
}
|
|
if ($items) { $uninstall = $items | Select-Object -First 1; break }
|
|
}
|
|
|
|
if (-not $uninstall -or -not $uninstall.UninstallString) {
|
|
Write-Host "Uninstall entry not found"
|
|
Exit 0
|
|
}
|
|
|
|
# Kill any running Spotify processes before uninstalling
|
|
Stop-Process -Name "Spotify" -Force -ErrorAction SilentlyContinue
|
|
Stop-Process -Name "SpotifyWebHelper" -Force -ErrorAction SilentlyContinue
|
|
|
|
$uninstallString = $uninstall.UninstallString
|
|
$exePath = ""
|
|
$arguments = ""
|
|
|
|
# Parse the uninstall string to extract executable path and existing arguments
|
|
# Handles both quoted and unquoted paths
|
|
if ($uninstallString -match '^"([^"]+)"(.*)') {
|
|
$exePath = $matches[1]
|
|
$arguments = $matches[2].Trim()
|
|
} elseif ($uninstallString -match '^([^\s]+)(.*)') {
|
|
$exePath = $matches[1]
|
|
$arguments = $matches[2].Trim()
|
|
} else {
|
|
Write-Host "Error: Could not parse uninstall string: $uninstallString"
|
|
Exit 1
|
|
}
|
|
|
|
# Build argument list array, preserving existing arguments and adding /silent for silent
|
|
$argumentList = @()
|
|
if ($arguments -ne '') {
|
|
# Split existing arguments and add them
|
|
$argumentList += $arguments -split '\s+'
|
|
}
|
|
# Append /silent if not already present
|
|
if ($argumentList -notcontains "/silent" -and $arguments -notmatch '\b/silent\b') {
|
|
$argumentList += "/silent"
|
|
}
|
|
|
|
Write-Host "Uninstall executable: $exePath"
|
|
Write-Host "Uninstall arguments: $($argumentList -join ' ')"
|
|
|
|
try {
|
|
$processOptions = @{
|
|
FilePath = $exePath
|
|
NoNewWindow = $true
|
|
PassThru = $true
|
|
Wait = $true
|
|
}
|
|
|
|
if ($argumentList.Count -gt 0) {
|
|
$processOptions.ArgumentList = $argumentList
|
|
}
|
|
|
|
$process = Start-Process @processOptions
|
|
$exitCode = $process.ExitCode
|
|
|
|
Write-Host "Uninstall exit code: $exitCode"
|
|
Exit $exitCode
|
|
} catch {
|
|
Write-Host "Error running uninstaller: $_"
|
|
Exit 1
|
|
}
|
|
|