-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.ps1
147 lines (124 loc) · 4.15 KB
/
install.ps1
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
# Installation script for specifai-mcp-server (Windows PowerShell)
# Script parameters
param(
[string]$v = "", # Version parameter
[switch]$h = $false # Help parameter
)
# Repository information
$RepoOwner = "vj-presidio"
$RepoName = "specifai-mcp-server"
$BinaryName = "specifai-mcp-server"
$InstallDir = "$env:ProgramFiles\specifai"
# Colors for output
$Green = "Green"
$Red = "Red"
$Blue = "Cyan"
# Show help
function Show-Help {
Write-Host "Usage: install.ps1 [-v version]"
Write-Host ""
Write-Host "Options:"
Write-Host " -v version Install specific version"
Write-Host " -h Show this help message"
exit 0
}
# Show help if requested
if ($h) {
Show-Help
}
# Function to get latest version from GitHub
function Get-LatestVersion {
try {
$response = Invoke-RestMethod -Uri "https://api.github.com/repos/$RepoOwner/$RepoName/releases/latest"
return $response.tag_name -replace '^v', ''
}
catch {
Write-Host "Error: Could not determine latest version" -ForegroundColor $Red
exit 1
}
}
# Function to check if version exists
function Test-VersionExists {
param([string]$Version)
try {
$response = Invoke-RestMethod -Uri "https://api.github.com/repos/$RepoOwner/$RepoName/releases/tags/v$Version" -ErrorAction SilentlyContinue
return $true
}
catch {
return $false
}
}
# Function to download binary
function Get-Binary {
param([string]$Version)
# Determine CPU variant
$Variant = "-modern"
try {
# Check if CPU supports modern features
$CpuInfo = Get-WmiObject -Class Win32_Processor
if (-not ($CpuInfo.Caption -match "Intel|AMD")) {
$Variant = "-baseline"
}
} catch {
# Fallback to baseline if can't determine
$Variant = "-baseline"
}
# Create temp directory
$TempDir = New-TemporaryFile | ForEach-Object { Remove-Item $_; New-Item -ItemType Directory -Path $_ }
$TempFile = Join-Path $TempDir "$BinaryName.exe"
# Construct download URL
$DownloadUrl = "https://github.com/$RepoOwner/$RepoName/releases/download/v$Version/$BinaryName-windows-x64$Variant-v$Version.exe"
Write-Host "Downloading $BinaryName v$Version..." -ForegroundColor $Blue
try {
Invoke-WebRequest -Uri $DownloadUrl -OutFile $TempFile
return $TempFile
}
catch {
Write-Host "Error: Failed to download binary" -ForegroundColor $Red
Remove-Item -Recurse -Force $TempDir
exit 1
}
}
# Function to install binary
function Install-Binary {
param([string]$TempFile)
# Create installation directory if it doesn't exist
if (-not (Test-Path $InstallDir)) {
New-Item -ItemType Directory -Path $InstallDir | Out-Null
}
# Move binary to installation directory
$TargetPath = Join-Path $InstallDir "$BinaryName.exe"
Move-Item -Force $TempFile $TargetPath
# Add to PATH if not already there
$CurrentPath = [Environment]::GetEnvironmentVariable("Path", "Machine")
if ($CurrentPath -notlike "*$InstallDir*") {
$NewPath = "$CurrentPath;$InstallDir"
[Environment]::SetEnvironmentVariable("Path", $NewPath, "Machine")
$env:Path = $NewPath
}
}
# Main installation flow
function Install-Main {
# Determine version to install
if ([string]::IsNullOrEmpty($v)) {
Write-Host "No version specified, getting latest..." -ForegroundColor $Blue
$Version = Get-LatestVersion
}
else {
$Version = $v
Write-Host "Checking if version v$Version exists..." -ForegroundColor $Blue
if (-not (Test-VersionExists $Version)) {
Write-Host "Error: Version v$Version not found" -ForegroundColor $Red
exit 1
}
}
# Download and install binary
$TempFile = Get-Binary $Version
Install-Binary $TempFile
# Cleanup
Remove-Item -Recurse -Force (Split-Path $TempFile)
Write-Host "Successfully installed $BinaryName v$Version" -ForegroundColor $Green
Write-Host "Run '$BinaryName --help' to get started" -ForegroundColor $Blue
}
# Run main installation
Install-Main