This repository was archived by the owner on Mar 20, 2026. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.ps1
More file actions
160 lines (133 loc) · 4.34 KB
/
install.ps1
File metadata and controls
160 lines (133 loc) · 4.34 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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
#!/usr/bin/env pwsh
# RestMan installer script for Windows
# Usage: powershell -c "irm restman.sh/install.ps1 | iex"
$ErrorActionPreference = 'Stop'
# Configuration
$Repo = "cadamsdev/restman"
$InstallDir = if ($env:RESTMAN_INSTALL) { $env:RESTMAN_INSTALL } else { "$HOME\.restman" }
$BinDir = "$InstallDir\bin"
$Executable = "$BinDir\restman.exe"
# Helper function for colored output
function Write-ColorOutput {
param(
[string]$Message,
[string]$Color = "White"
)
$previousColor = $Host.UI.RawUI.ForegroundColor
$Host.UI.RawUI.ForegroundColor = $Color
Write-Output $Message
$Host.UI.RawUI.ForegroundColor = $previousColor
}
# Detect architecture
function Get-Architecture {
$arch = $env:PROCESSOR_ARCHITECTURE
switch ($arch) {
"AMD64" { return "x64" }
"ARM64" { return "arm64" }
default {
Write-ColorOutput "Unsupported architecture: $arch" "Red"
exit 1
}
}
}
# Get latest release version
function Get-LatestVersion {
try {
$response = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest"
return $response.tag_name
}
catch {
Write-ColorOutput "Failed to get latest version: $_" "Red"
exit 1
}
}
# Download and install RestMan
function Install-RestMan {
$arch = Get-Architecture
$version = Get-LatestVersion
$platform = "windows-$arch"
Write-ColorOutput "Installing RestMan $version for $platform..." "Green"
# Construct download URL
$archiveName = "restman-$platform.zip"
$downloadUrl = "https://github.com/$Repo/releases/download/$version/$archiveName"
Write-Output "Downloading from: $downloadUrl"
# Create directories
New-Item -ItemType Directory -Force -Path $BinDir | Out-Null
# Download to temp directory
$tempDir = New-Item -ItemType Directory -Path (Join-Path $env:TEMP "restman-install-$(Get-Random)")
$archivePath = Join-Path $tempDir $archiveName
try {
Invoke-WebRequest -Uri $downloadUrl -OutFile $archivePath -UseBasicParsing
# Extract archive
$extractDir = Join-Path $tempDir "extracted"
Expand-Archive -Path $archivePath -DestinationPath $extractDir -Force
# Find and move binary (look for restman.exe or restman)
$extractedBinary = Get-ChildItem -Path $extractDir -Recurse -Filter "restman*" | Where-Object {
$_.Name -eq "restman.exe" -or $_.Name -eq "restman"
} | Select-Object -First 1
if ($extractedBinary) {
Copy-Item -Path $extractedBinary.FullName -Destination $Executable -Force
Write-ColorOutput "✓ RestMan installed to $Executable" "Green"
}
else {
Write-ColorOutput "Binary not found in archive" "Red"
exit 1
}
}
catch {
Write-ColorOutput "Installation failed: $_" "Red"
exit 1
}
finally {
# Cleanup temp directory
Remove-Item -Path $tempDir -Recurse -Force -ErrorAction SilentlyContinue
}
}
# Add to PATH
function Update-Path {
# Check if already in PATH
$currentPath = [Environment]::GetEnvironmentVariable("Path", "User")
if ($currentPath -like "*$BinDir*") {
Write-ColorOutput "✓ $BinDir is already in PATH" "Green"
return
}
# Add to user PATH
try {
$newPath = "$currentPath;$BinDir"
[Environment]::SetEnvironmentVariable("Path", $newPath, "User")
# Update current session PATH
$env:Path = "$env:Path;$BinDir"
Write-ColorOutput "✓ Added $BinDir to PATH" "Green"
Write-ColorOutput "Note: You may need to restart your terminal for PATH changes to take effect" "Yellow"
}
catch {
Write-ColorOutput "Failed to update PATH: $_" "Yellow"
Write-ColorOutput "Please manually add $BinDir to your PATH" "Yellow"
}
}
# Verify installation
function Test-Installation {
try {
$version = & $Executable --version 2>&1
Write-ColorOutput "✓ RestMan is working: $version" "Green"
}
catch {
Write-ColorOutput "Warning: Could not verify installation" "Yellow"
}
}
# Main installation flow
function Main {
Write-ColorOutput "RestMan Installer" "Green"
Write-Output ""
Install-RestMan
Update-Path
Write-Output ""
Write-ColorOutput "Installation complete!" "Green"
Write-Output ""
Write-Output "To get started:"
Write-Output " 1. Restart your terminal or run: refreshenv (if using chocolatey)"
Write-Output " 2. Run: restman"
Write-Output ""
Write-Output "For more information, visit: https://github.com/$Repo"
}
Main