-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathuninstall.ps1
More file actions
103 lines (84 loc) · 3.09 KB
/
uninstall.ps1
File metadata and controls
103 lines (84 loc) · 3.09 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
$ErrorActionPreference = "Stop"
$BackupDir = ".mechanicus-backup"
Write-Host ""
Write-Host "================================================================" -ForegroundColor Cyan
Write-Host " OpenClaw Mechanicus Patch Uninstaller" -ForegroundColor Cyan
Write-Host "================================================================" -ForegroundColor Cyan
Write-Host ""
function Find-OpenClaw {
param([string]$Hint)
if ($Hint -and (Test-Path $Hint)) { return (Resolve-Path $Hint).Path }
$userHome = $env:USERPROFILE
if (-not $userHome) { $userHome = $HOME }
$candidates = @(
(Join-Path $userHome "openclaw"),
(Join-Path "." "openclaw"),
"."
)
foreach ($c in $candidates) {
if ((Test-Path $c) -and (Test-Path (Join-Path $c $BackupDir))) {
return (Resolve-Path $c).Path
}
}
return $null
}
$OpenClawRoot = Find-OpenClaw -Hint $args[0]
if (-not $OpenClawRoot) {
Write-Host "ERROR: Could not find OpenClaw installation with Mechanicus backup." -ForegroundColor Red
Write-Host "Usage: .\uninstall.ps1 C:\path\to\openclaw"
exit 1
}
$BackupPath = Join-Path $OpenClawRoot $BackupDir
$InstalledList = Join-Path $BackupPath "installed-files.txt"
$BackedUpList = Join-Path $BackupPath "backed-up-files.txt"
if (-not (Test-Path $InstalledList)) {
Write-Host "ERROR: No installation record found at $InstalledList" -ForegroundColor Red
Write-Host "Mechanicus does not appear to be installed here."
exit 1
}
Write-Host "OpenClaw root: $OpenClawRoot"
Write-Host ""
$removed = 0
$restored = 0
Write-Host "[1/3] Removing new files added by Mechanicus..."
$installedFiles = Get-Content $InstalledList
$backedUpFiles = @()
if (Test-Path $BackedUpList) {
$backedUpFiles = Get-Content $BackedUpList
}
foreach ($rel in $installedFiles) {
if ($backedUpFiles -contains $rel) { continue }
$target = Join-Path $OpenClawRoot $rel
if (Test-Path $target) {
Remove-Item $target -Force
$removed++
}
}
Write-Host " Removed $removed new files"
Write-Host ""
Write-Host "[2/3] Restoring original files from backup..."
foreach ($rel in $backedUpFiles) {
$backupFile = Join-Path $BackupPath $rel
$target = Join-Path $OpenClawRoot $rel
if (Test-Path $backupFile) {
$targetDir = Split-Path -Parent $target
New-Item -ItemType Directory -Path $targetDir -Force | Out-Null
Copy-Item $backupFile $target -Force
$restored++
}
}
Write-Host " Restored $restored original files"
Write-Host ""
Write-Host "[3/3] Cleaning up backup directory..."
Remove-Item $BackupPath -Recurse -Force
Write-Host " Removed $BackupDir\"
Write-Host ""
Write-Host "================================================================" -ForegroundColor Green
Write-Host " UNINSTALL COMPLETE" -ForegroundColor Green
Write-Host "================================================================" -ForegroundColor Green
Write-Host ""
Write-Host " Removed: $removed new files"
Write-Host " Restored: $restored original files"
Write-Host ""
Write-Host " OpenClaw has been restored to its pre-patch state."
Write-Host ""