-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathinstall.ps1
More file actions
51 lines (40 loc) · 1.73 KB
/
Copy pathinstall.ps1
File metadata and controls
51 lines (40 loc) · 1.73 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
param(
[string]$Repo = "taichuy/agentMemory",
[string]$Ref = "main",
[string]$Destination = ".",
[switch]$Force
)
Set-StrictMode -Version Latest
$ErrorActionPreference = "Stop"
$destinationPath = (Resolve-Path -LiteralPath $Destination).Path
$targetMemoryPath = Join-Path $destinationPath ".memory"
if ((Test-Path -LiteralPath $targetMemoryPath) -and -not $Force) {
throw ".memory already exists in '$destinationPath'. Re-run with -Force to replace it."
}
$tempRoot = Join-Path ([System.IO.Path]::GetTempPath()) ("agentMemory-" + [System.Guid]::NewGuid().ToString("N"))
$archivePath = Join-Path $tempRoot "agentMemory.zip"
$extractPath = Join-Path $tempRoot "extract"
try {
New-Item -ItemType Directory -Path $tempRoot | Out-Null
$downloadUrl = "https://codeload.github.com/$Repo/zip/refs/heads/$Ref"
Invoke-WebRequest -Uri $downloadUrl -OutFile $archivePath
Expand-Archive -LiteralPath $archivePath -DestinationPath $extractPath
$repoRoot = Get-ChildItem -LiteralPath $extractPath -Directory | Select-Object -First 1
if ($null -eq $repoRoot) {
throw "Unable to locate the extracted repository root."
}
$sourceMemoryPath = Join-Path $repoRoot.FullName ".memory"
if (-not (Test-Path -LiteralPath $sourceMemoryPath)) {
throw "The repository archive does not contain a .memory directory."
}
if (Test-Path -LiteralPath $targetMemoryPath) {
Remove-Item -LiteralPath $targetMemoryPath -Recurse -Force
}
Copy-Item -LiteralPath $sourceMemoryPath -Destination $destinationPath -Recurse -Force
Write-Host "Installed .memory into $destinationPath"
}
finally {
if (Test-Path -LiteralPath $tempRoot) {
Remove-Item -LiteralPath $tempRoot -Recurse -Force
}
}