-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.ps1
More file actions
62 lines (54 loc) · 3.2 KB
/
uninstall.ps1
File metadata and controls
62 lines (54 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# ──────────────────────────────────────────────────────────────────────────────
# hostcraft uninstaller — Windows (PowerShell)
# Usage: irm https://raw.githubusercontent.com/Zaberahmed/hostcraft/main/uninstall.ps1 | iex
# ──────────────────────────────────────────────────────────────────────────────
$ErrorActionPreference = "Stop"
$InstallDir = Join-Path $env:LOCALAPPDATA "Programs\hostcraft"
$Binary = Join-Path $InstallDir "hostcraft.exe"
# ── 1. Check if installed ─────────────────────────────────────────────────────
if (-not (Test-Path $Binary)) {
Write-Host "hostcraft is not installed at $Binary"
exit 0
}
# ── 2. Remove the binary and any update leftovers ────────────────────────────
Write-Host "Removing $Binary..."
Remove-Item -Force $Binary
# Clean up artifacts that the self-update command can leave behind
# .new — written during a replace attempt, then renamed; survives if interrupted
# .bak — the old binary is moved here before the new one is placed
foreach ($ext in @("new", "bak")) {
$leftover = Join-Path $InstallDir "hostcraft.$ext"
if (Test-Path $leftover) {
Remove-Item -Force $leftover
Write-Host "Removed leftover: $leftover"
}
}
# Remove the install directory only if it is now empty
if (Test-Path $InstallDir) {
if ((Get-ChildItem $InstallDir | Measure-Object).Count -eq 0) {
Remove-Item -Force -Recurse $InstallDir
}
}
# ── 3. Remove the cache directory ────────────────────────────────────────────
# The CLI stores update-check state here — separate from the install directory.
# Path: %LOCALAPPDATA%\hostcraft\ (created by the `directories` crate)
$CacheDir = Join-Path $env:LOCALAPPDATA "hostcraft"
if (Test-Path $CacheDir) {
Remove-Item -Recurse -Force $CacheDir
Write-Host "Removed cache directory: $CacheDir"
}
# ── 4. Remove from user PATH ─────────────────────────────────────────────────
$CurrentPath = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($CurrentPath -like "*$InstallDir*") {
# TrimEnd('\') on both sides guards against trailing-backslash mismatches
# that arise if someone manually edited their PATH
$NewPath = ($CurrentPath -split ";" |
Where-Object { $_.TrimEnd('\') -ne $InstallDir.TrimEnd('\') } |
Where-Object { $_ -ne "" }) -join ";"
[Environment]::SetEnvironmentVariable("PATH", $NewPath, "User")
Write-Host "Removed $InstallDir from your PATH."
Write-Host "Restart your terminal for the PATH change to take effect."
}
Write-Host ""
Write-Host "✓ hostcraft uninstalled"
Write-Host ""