-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuninstall.ps1
More file actions
196 lines (174 loc) · 5.93 KB
/
Copy pathuninstall.ps1
File metadata and controls
196 lines (174 loc) · 5.93 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
#Requires -Version 5.1
[CmdletBinding()]
param(
[string]$Prefix = "$env:LOCALAPPDATA\llmconfig\bin",
[switch]$All,
[switch]$KeepCache,
[switch]$Help
)
$ErrorActionPreference = "Stop"
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
$OutputEncoding = [System.Text.Encoding]::UTF8
$BinaryName = "llmconfig"
$LlamaHome = Join-Path $env:USERPROFILE ".llmconfig"
$SrcDir = Join-Path $LlamaHome "src" # legacy (old source-install)
$BinDir = Join-Path $LlamaHome "bin" # llama.cpp, sd, whisper binaries
$ConfigDir = Join-Path $LlamaHome "configs"
$LogsDir = Join-Path $LlamaHome "logs"
$ModelsDir = Join-Path $LlamaHome "models"
if ($Help) {
@"
Usage: uninstall.ps1 [-Prefix PATH] [-All] [-KeepCache]
-Prefix PATH Install directory to remove from
(default: %LOCALAPPDATA%\llmconfig\bin)
-All Remove everything without prompting (binary, configs,
logs, llama.cpp, cache). Equivalent to answering "yes"
to every prompt.
-KeepCache Skip the model cache prompt/removal (useful with -All).
Interactive by default: asks yes/no per category.
"@ | Write-Host
exit 0
}
function ok { param($msg) Write-Host " [OK] $msg" -ForegroundColor Green }
function skip { param($msg) Write-Host " [-] $msg" -ForegroundColor DarkGray }
function warn { param($msg) Write-Host " [!] $msg" -ForegroundColor Yellow }
function Get-SizeLabel {
param($path)
if (-not (Test-Path $path)) { return "-" }
try {
$bytes = (Get-ChildItem $path -Recurse -Force -ErrorAction SilentlyContinue | Measure-Object Length -Sum).Sum
if (-not $bytes) { return "0B" }
if ($bytes -gt 1GB) { return ("{0:N1}GB" -f ($bytes / 1GB)) }
if ($bytes -gt 1MB) { return ("{0:N1}MB" -f ($bytes / 1MB)) }
if ($bytes -gt 1KB) { return ("{0:N1}KB" -f ($bytes / 1KB)) }
return "${bytes}B"
} catch {
return "?"
}
}
function Ask {
param(
[string]$Label,
[string]$Path,
[switch]$DefaultNo
)
if ($All) { return $true }
$size = Get-SizeLabel $Path
$suffix = if ($DefaultNo) { "[y/N]" } else { "[Y/n]" }
$answer = Read-Host " Remove $Label ($size)? $suffix"
if ($DefaultNo) {
return ($answer -match "^[yY]")
} else {
return (-not ($answer -match "^[nN]"))
}
}
Write-Host ""
Write-Host @"
_ _ _ _ _ _
| | | |_ __ (_)_ __ ___| |_ __ _| | |
| | | | '_ \| | '_ \/ __| __/ _' | | |
| |_| | | | | | | | \__ \ || (_| | | |
\___/|_| |_|_|_| |_|___/\__\__,_|_|_|
"@ -ForegroundColor Red
Write-Host ""
$binaryPath = Join-Path $Prefix "$BinaryName.exe"
$llmcExe = Join-Path $Prefix "llmc.exe"
$llmcCmd = Join-Path $Prefix "llmc.cmd"
$lcExe = Join-Path $Prefix "lc.exe" # legacy alias (pre-v0.3.0)
$lcCmd = Join-Path $Prefix "lc.cmd" # legacy alias (pre-v0.3.0)
# Stop running models before we yank the binary
if (Test-Path $binaryPath) {
try { & $binaryPath down --all 2>$null } catch { }
}
# --- Binary ---
if (Test-Path $binaryPath) {
if (Ask -Label "llmconfig binary" -Path $binaryPath) {
Remove-Item $binaryPath -Force
ok "Removed $binaryPath"
foreach ($p in @($llmcExe, $llmcCmd, $lcExe, $lcCmd)) {
if (Test-Path $p) { Remove-Item $p -Force; ok "Removed $p" }
}
# Remove prefix dir if empty
if ((Test-Path $Prefix) -and @(Get-ChildItem $Prefix -Force -ErrorAction SilentlyContinue).Count -eq 0) {
Remove-Item $Prefix -Force
ok "Removed empty $Prefix"
}
# Clean PATH
$userPath = [Environment]::GetEnvironmentVariable("PATH", "User")
if ($userPath -like "*$Prefix*") {
$newPath = ($userPath -split ";" | Where-Object { $_ -ne $Prefix }) -join ";"
[Environment]::SetEnvironmentVariable("PATH", $newPath, "User")
ok "Removed $Prefix from user PATH"
}
} else {
skip "Kept binary"
}
} else {
skip "Binary not found at $binaryPath"
}
# --- Legacy source dir ---
if (Test-Path $SrcDir) {
if (Ask -Label "legacy source dir" -Path $SrcDir) {
Remove-Item $SrcDir -Recurse -Force
ok "Removed $SrcDir"
} else {
skip "Kept source dir"
}
}
# --- llama.cpp / sd / whisper binaries ---
if (Test-Path $BinDir) {
if (Ask -Label "backend binaries (llama.cpp, sd, whisper)" -Path $BinDir) {
Remove-Item $BinDir -Recurse -Force
ok "Removed $BinDir"
} else {
skip "Kept backend binaries"
}
}
# --- Configs ---
if (Test-Path $ConfigDir) {
if (Ask -Label "model configs" -Path $ConfigDir) {
Remove-Item $ConfigDir -Recurse -Force
ok "Removed $ConfigDir"
} else {
skip "Kept configs"
}
}
# --- Logs ---
if (Test-Path $LogsDir) {
if (Ask -Label "logs" -Path $LogsDir) {
Remove-Item $LogsDir -Recurse -Force
ok "Removed $LogsDir"
} else {
skip "Kept logs"
}
}
# --- Models (default no) ---
if ((Test-Path $ModelsDir) -and -not $KeepCache) {
if (Ask -Label "downloaded models (GGUF files)" -Path $ModelsDir -DefaultNo) {
Remove-Item $ModelsDir -Recurse -Force
ok "Removed $ModelsDir"
} else {
skip "Kept downloaded models at $ModelsDir"
}
} elseif (Test-Path $ModelsDir) {
skip "Kept downloaded models at $ModelsDir (--KeepCache)"
}
# --- Remove home dir if empty ---
if (Test-Path $LlamaHome) {
$remaining = @(Get-ChildItem $LlamaHome -Force -ErrorAction SilentlyContinue)
if ($remaining.Count -eq 0) {
Remove-Item $LlamaHome -Force
ok "Removed $LlamaHome"
}
}
# --- Remove empty prefix dir ---
if (Test-Path $Prefix) {
$remaining = @(Get-ChildItem $Prefix -Force -ErrorAction SilentlyContinue)
if ($remaining.Count -eq 0) {
Remove-Item $Prefix -Force
ok "Removed empty $Prefix"
}
}
Write-Host ""
Write-Host " Done." -ForegroundColor Green
Write-Host ""