-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
50 lines (44 loc) · 2.67 KB
/
Copy pathinstall.ps1
File metadata and controls
50 lines (44 loc) · 2.67 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
$ErrorActionPreference = "Stop"
$Repository = "revolution-uz/worko-ai-usage"
$Architecture = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().ToLowerInvariant()
switch ($Architecture) {
"x64" { $Cpu = "x86_64" }
"arm64" { $Cpu = "aarch64" }
default { throw "Unsupported architecture: $Architecture" }
}
$Asset = "worko-ai-usage-$Cpu-pc-windows-msvc.zip"
$Url = "https://github.com/$Repository/releases/latest/download/$Asset"
$InstallDir = Join-Path $env:LOCALAPPDATA "WorkoAiUsage"
$Executable = Join-Path $InstallDir "worko-ai-usage.exe"
$TempDir = Join-Path ([System.IO.Path]::GetTempPath()) ("worko-ai-usage-" + [guid]::NewGuid())
New-Item -ItemType Directory -Force -Path $TempDir, $InstallDir | Out-Null
try {
$Archive = Join-Path $TempDir $Asset
Write-Host "Downloading $Asset..."
Invoke-WebRequest -UseBasicParsing -Uri $Url -OutFile $Archive
$Checksums = Join-Path $TempDir "SHA256SUMS"
Invoke-WebRequest -UseBasicParsing -Uri "https://github.com/$Repository/releases/latest/download/SHA256SUMS" -OutFile $Checksums
$ChecksumLine = Get-Content $Checksums | Where-Object { $_ -match "\s$([regex]::Escape($Asset))$" } | Select-Object -First 1
if (-not $ChecksumLine) { throw "No checksum published for $Asset" }
$Expected = ($ChecksumLine -split "\s+")[0].ToLowerInvariant()
$Actual = (Get-FileHash -Algorithm SHA256 $Archive).Hash.ToLowerInvariant()
if ($Actual -ne $Expected) { throw "Checksum verification failed for $Asset" }
Write-Host "SHA-256 checksum verified."
Expand-Archive -Path $Archive -DestinationPath $TempDir -Force
Copy-Item (Join-Path $TempDir "worko-ai-usage.exe") $Executable -Force
} finally {
Remove-Item $TempDir -Recurse -Force -ErrorAction SilentlyContinue
}
$CurrentUserPath = [Environment]::GetEnvironmentVariable("Path", "User")
if (($CurrentUserPath -split ";") -notcontains $InstallDir) {
[Environment]::SetEnvironmentVariable("Path", (($CurrentUserPath.TrimEnd(";"), $InstallDir) -join ";"), "User")
}
$Action = New-ScheduledTaskAction -Execute $Executable -Argument "sync"
$Trigger = New-ScheduledTaskTrigger -Once -At (Get-Date).AddMinutes(5) -RepetitionInterval (New-TimeSpan -Hours 1)
$Settings = New-ScheduledTaskSettingsSet -StartWhenAvailable -ExecutionTimeLimit (New-TimeSpan -Minutes 5)
Register-ScheduledTask -TaskName "Worko AI Usage" -Action $Action -Trigger $Trigger -Settings $Settings -Description "Sync Claude Code and Codex usage with Worko HR" -Force | Out-Null
Write-Host "Installed $Executable and enabled hourly sync."
Write-Host ""
Write-Host "Connect this computer to Worko HR with either command:"
Write-Host " $Executable login"
Write-Host " $Executable connect"