-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.ps1
More file actions
57 lines (45 loc) · 1.85 KB
/
install.ps1
File metadata and controls
57 lines (45 loc) · 1.85 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
#!/usr/bin/env pwsh
$ErrorActionPreference = "Stop"
$repo = "hewliyang/splitwise-cli"
$binary = "splitwise-cli.exe"
# Detect architecture
$arch = if ([Environment]::Is64BitOperatingSystem) {
if ($env:PROCESSOR_ARCHITECTURE -eq "ARM64") { "arm64" } else { "amd64" }
} else {
Write-Error "32-bit systems are not supported"
exit 1
}
# Get latest version
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/$repo/releases/latest"
$version = $release.tag_name
$versionNum = $version.TrimStart('v')
Write-Host "Installing splitwise-cli $version (windows/$arch)..."
# Download URL
$url = "https://github.com/$repo/releases/download/$version/splitwise-cli_${versionNum}_windows_${arch}.zip"
# Create temp directory
$tmpDir = New-Item -ItemType Directory -Path ([System.IO.Path]::GetTempPath()) -Name ([System.Guid]::NewGuid().ToString())
try {
# Download
$zipPath = Join-Path $tmpDir "splitwise-cli.zip"
Write-Host "Downloading from $url"
Invoke-WebRequest -Uri $url -OutFile $zipPath
# Extract
Expand-Archive -Path $zipPath -DestinationPath $tmpDir
# Install to user's local bin
$installDir = Join-Path $env:LOCALAPPDATA "Programs\splitwise-cli"
if (!(Test-Path $installDir)) {
New-Item -ItemType Directory -Path $installDir | Out-Null
}
Copy-Item (Join-Path $tmpDir $binary) -Destination $installDir -Force
# Add to PATH if not already there
$userPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($userPath -notlike "*$installDir*") {
[Environment]::SetEnvironmentVariable("Path", "$userPath;$installDir", "User")
Write-Host "Added $installDir to PATH (restart your terminal to use)"
}
Write-Host "✓ Installed splitwise-cli to $installDir\$binary"
Write-Host " Run 'splitwise-cli help' to get started"
}
finally {
Remove-Item -Recurse -Force $tmpDir
}