-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuninstall.ps1
More file actions
36 lines (32 loc) · 1.25 KB
/
Copy pathuninstall.ps1
File metadata and controls
36 lines (32 loc) · 1.25 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
[CmdletBinding()]
param(
[string]$GrokHome = $(if ($env:GROK_HOME) { $env:GROK_HOME } else { Join-Path $HOME '.grok' }),
[string]$ProfilePath = $PROFILE.CurrentUserCurrentHost,
[switch]$RemoveInstalledFiles
)
$ErrorActionPreference = 'Stop'
$timestamp = Get-Date -Format 'yyyyMMdd-HHmmss'
$backupDir = Join-Path $GrokHome "backups\supppergrok-uninstall-$timestamp"
New-Item -ItemType Directory -Path $backupDir -Force | Out-Null
if (Test-Path -LiteralPath $ProfilePath) {
Copy-Item -LiteralPath $ProfilePath -Destination (Join-Path $backupDir ([IO.Path]::GetFileName($ProfilePath))) -Force
$text = Get-Content -LiteralPath $ProfilePath -Raw -Encoding UTF8
$text = [regex]::Replace(
$text,
'(?ms)\r?\n?# >>> SUPPPERGROK >>>.*?# <<< SUPPPERGROK <<<\r?\n?',
"`r`n"
)
Set-Content -LiteralPath $ProfilePath -Value $text.TrimEnd() -Encoding UTF8
}
if ($RemoveInstalledFiles) {
foreach ($path in @(
(Join-Path $GrokHome 'grok-4.5-unrestricted.md'),
(Join-Path $GrokHome 'supppergrok-wrapper.ps1')
)) {
if (Test-Path -LiteralPath $path) {
Remove-Item -LiteralPath $path -Force
}
}
}
Write-Output "Removed profile block from: $ProfilePath"
Write-Output "Backup: $backupDir"