|
| 1 | +# PowerShell uninstallation script for shepai on Windows |
| 2 | + |
| 3 | +param( |
| 4 | + [string]$InstallDir = "$env:LOCALAPPDATA\Programs\shepai" |
| 5 | +) |
| 6 | + |
| 7 | +$ErrorActionPreference = "Stop" |
| 8 | + |
| 9 | +# Configuration |
| 10 | +$BINARY_NAME = "shepai.exe" |
| 11 | + |
| 12 | +# Color output functions |
| 13 | +function Write-ColorOutput { |
| 14 | + param( |
| 15 | + [string]$ForegroundColor, |
| 16 | + [string]$Message |
| 17 | + ) |
| 18 | + $fc = $host.UI.RawUI.ForegroundColor |
| 19 | + $host.UI.RawUI.ForegroundColor = $ForegroundColor |
| 20 | + Write-Host $Message |
| 21 | + $host.UI.RawUI.ForegroundColor = $fc |
| 22 | +} |
| 23 | + |
| 24 | +function Write-Success { |
| 25 | + param([string]$Message) |
| 26 | + Write-ColorOutput -ForegroundColor "Green" -Message $Message |
| 27 | +} |
| 28 | + |
| 29 | +function Write-Error-Message { |
| 30 | + param([string]$Message) |
| 31 | + Write-ColorOutput -ForegroundColor "Red" -Message $Message |
| 32 | +} |
| 33 | + |
| 34 | +function Write-Warning-Message { |
| 35 | + param([string]$Message) |
| 36 | + Write-ColorOutput -ForegroundColor "Yellow" -Message $Message |
| 37 | +} |
| 38 | + |
| 39 | +# Uninstall shepai |
| 40 | +function Uninstall-Shepai { |
| 41 | + $targetPath = Join-Path $InstallDir $BINARY_NAME |
| 42 | + |
| 43 | + # Check if shepai is installed |
| 44 | + if (-not (Test-Path $InstallDir)) { |
| 45 | + Write-Warning-Message "shepai installation directory not found: $InstallDir" |
| 46 | + Write-Warning-Message "shepai may not be installed or was installed to a different location" |
| 47 | + return |
| 48 | + } |
| 49 | + |
| 50 | + if (-not (Test-Path $targetPath)) { |
| 51 | + Write-Warning-Message "shepai binary not found: $targetPath" |
| 52 | + Write-Warning-Message "shepai may not be installed or was installed to a different location" |
| 53 | + } |
| 54 | + |
| 55 | + # Remove installation directory |
| 56 | + try { |
| 57 | + Write-Warning-Message "Removing shepai from $InstallDir..." |
| 58 | + Remove-Item -Path $InstallDir -Recurse -Force -ErrorAction Stop |
| 59 | + Write-Success "[OK] Removed shepai installation directory" |
| 60 | + } |
| 61 | + catch { |
| 62 | + Write-Error-Message "Error: Failed to remove installation directory" |
| 63 | + Write-Error-Message $_.Exception.Message |
| 64 | + exit 1 |
| 65 | + } |
| 66 | + |
| 67 | + # Remove from PATH |
| 68 | + try { |
| 69 | + $userPath = [System.Environment]::GetEnvironmentVariable("Path", "User") |
| 70 | + |
| 71 | + if ($userPath -like "*$InstallDir*") { |
| 72 | + Write-Warning-Message "Removing $InstallDir from user PATH..." |
| 73 | + |
| 74 | + # Split path entries, filter out shepai directory, and rejoin |
| 75 | + $pathEntries = $userPath -split ';' |
| 76 | + $newPathEntries = $pathEntries | Where-Object { $_ -ne $InstallDir -and $_ -notlike '*shepai*' } |
| 77 | + $newPath = $newPathEntries -join ';' |
| 78 | + |
| 79 | + [System.Environment]::SetEnvironmentVariable("Path", $newPath, "User") |
| 80 | + Write-Success "[OK] Removed from PATH. Please restart your terminal for changes to take effect." |
| 81 | + } |
| 82 | + else { |
| 83 | + Write-Warning-Message "shepai directory not found in PATH" |
| 84 | + } |
| 85 | + } |
| 86 | + catch { |
| 87 | + Write-Error-Message "Warning: Failed to update PATH" |
| 88 | + Write-Error-Message $_.Exception.Message |
| 89 | + } |
| 90 | + |
| 91 | + Write-Success "[OK] Uninstallation complete!" |
| 92 | + Write-Success "shepai has been removed from your system" |
| 93 | +} |
| 94 | + |
| 95 | +# Main |
| 96 | +Write-Success "Uninstalling shepai..." |
| 97 | +Uninstall-Shepai |
0 commit comments