-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
123 lines (107 loc) · 4.38 KB
/
Copy pathinstall.ps1
File metadata and controls
123 lines (107 loc) · 4.38 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
param(
[ValidateSet("install", "uninstall")]
[string]$Action = "install"
)
$ErrorActionPreference = "Stop"
$AgentsDir = Join-Path $HOME ".cursor"
$UpdateScript = Join-Path $AgentsDir "update-usergenerated.ps1"
$TaskName = "UserGeneratedAgentsUpdate"
$Repos = @(
@{ Name = "rules"; Url = "https://github.com/UserGeneratedLLC/agent-rules.git" }
@{ Name = "skills"; Url = "https://github.com/UserGeneratedLLC/agent-skills.git" }
@{ Name = "docs"; Url = "https://github.com/UserGeneratedLLC/agent-docs.git" }
@{ Name = "commands"; Url = "https://github.com/UserGeneratedLLC/agent-commands.git" }
)
function Install {
if (-not (Get-Command git -ErrorAction SilentlyContinue)) {
Write-Error "git is required but not installed."
return
}
New-Item -ItemType Directory -Path $AgentsDir -Force | Out-Null
foreach ($repo in $Repos) {
$dest = Join-Path $AgentsDir $repo.Name "usergenerated"
try {
if (Test-Path (Join-Path $dest ".git")) {
Write-Host "Updating $($repo.Name)..."
$ErrorActionPreference = "Continue"
git -C $dest fetch --depth 1 2>$null
if ($LASTEXITCODE -eq 0) { git -C $dest reset --hard origin/HEAD 2>$null }
$ErrorActionPreference = "Stop"
if ($LASTEXITCODE -ne 0) { Write-Host " Warning: pull failed for $($repo.Name), skipping" }
} else {
if (Test-Path $dest) {
Write-Host "Repairing $($repo.Name) (removing incomplete clone)..."
Remove-Item -Recurse -Force $dest
}
Write-Host "Cloning $($repo.Name)..."
$parent = Split-Path $dest -Parent
New-Item -ItemType Directory -Path $parent -Force | Out-Null
$ErrorActionPreference = "Continue"
git clone --quiet --depth 1 $repo.Url $dest
$ErrorActionPreference = "Stop"
if ($LASTEXITCODE -ne 0) {
Write-Host " Warning: clone failed for $($repo.Name), skipping"
continue
}
}
} catch {
$ErrorActionPreference = "Stop"
Write-Host " Warning: failed to process $($repo.Name): $_"
continue
}
}
$scriptContent = @'
$ErrorActionPreference = "SilentlyContinue"
$dirs = @(
"$HOME\.cursor\rules\usergenerated"
"$HOME\.cursor\skills\usergenerated"
"$HOME\.cursor\docs\usergenerated"
"$HOME\.cursor\commands\usergenerated"
)
foreach ($dir in $dirs) {
if (Test-Path (Join-Path $dir ".git")) {
git -C $dir fetch --depth 1 2>$null
if ($LASTEXITCODE -eq 0) { git -C $dir reset --hard origin/HEAD 2>$null }
}
}
'@
Set-Content -Path $UpdateScript -Value $scriptContent -Encoding UTF8
Write-Host "Created update script at $UpdateScript"
$pwsh = if (Get-Command pwsh -ErrorAction SilentlyContinue) { "pwsh.exe" } else { "powershell.exe" }
$ErrorActionPreference = "Continue"
schtasks /create /tn $TaskName /sc hourly /tr "$pwsh -NoProfile -ExecutionPolicy Bypass -File `"$UpdateScript`"" /f 2>$null | Out-Null
$ErrorActionPreference = "Stop"
if ($LASTEXITCODE -eq 0) {
Write-Host "Installed hourly scheduled task."
} else {
Write-Host "Warning: failed to create scheduled task."
}
Write-Host "Installed to $AgentsDir"
}
function Uninstall {
foreach ($repo in $Repos) {
$dest = Join-Path $AgentsDir $repo.Name "usergenerated"
if (Test-Path $dest) {
Write-Host "Removing $dest..."
Remove-Item -Recurse -Force $dest
}
$parent = Join-Path $AgentsDir $repo.Name
try {
if ((Test-Path $parent) -and -not (Get-ChildItem -Force $parent)) {
Remove-Item -Force $parent
}
} catch { }
}
if (Test-Path $UpdateScript) { Remove-Item -Force $UpdateScript }
$ErrorActionPreference = "Continue"
schtasks /delete /tn $TaskName /f 2>$null | Out-Null
$ErrorActionPreference = "Stop"
if ($LASTEXITCODE -eq 0) { Write-Host "Removed scheduled task." }
try {
if ((Test-Path $AgentsDir) -and -not (Get-ChildItem -Force $AgentsDir)) {
Remove-Item -Force $AgentsDir
}
} catch { }
Write-Host "Uninstalled."
}
if ($Action -eq "uninstall") { Uninstall } else { Install }