-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathinstall.ps1
134 lines (117 loc) · 4.35 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
# Function to check if running in a terminal that supports colors
function Test-ColorSupport {
# Check if we're in a terminal that supports VirtualTerminalLevel
$supportsVT = $false
try {
$supportsVT = [Console]::IsOutputRedirected -eq $false -and
[Console]::IsErrorRedirected -eq $false -and
[Environment]::GetEnvironmentVariable("TERM") -ne $null
} catch {
$supportsVT = $false
}
return $supportsVT
}
# Function to write colored output
function Write-ColoredMessage {
param(
[string]$Message,
[System.ConsoleColor]$Color = [System.ConsoleColor]::White
)
if (Test-ColorSupport) {
$originalColor = [Console]::ForegroundColor
[Console]::ForegroundColor = $Color
Write-Host $Message
[Console]::ForegroundColor = $originalColor
} else {
Write-Host $Message
}
}
# Function to stop running instances
function Stop-RunningInstances {
param(
[string]$ProcessName
)
try {
$processes = Get-Process -Name $ProcessName -ErrorAction SilentlyContinue
if ($processes) {
$processes | ForEach-Object {
try {
$_.Kill()
$_.WaitForExit(1000)
} catch {
# Ignore errors if process already exited
}
}
Start-Sleep -Seconds 1 # Give processes time to fully exit
}
} catch {
# Ignore errors if no processes found
}
}
# Check if Docker is installed
if (-not (Get-Command "docker" -ErrorAction SilentlyContinue)) {
Write-ColoredMessage "Error: Docker is not installed" -Color Red
Write-ColoredMessage "Please install Docker Desktop for Windows:" -Color Yellow
Write-Host " https://docs.docker.com/desktop/install/windows-install/"
exit 1
}
# Check if Docker daemon is running
try {
docker info | Out-Null
} catch {
Write-ColoredMessage "Error: Docker daemon is not running" -Color Red
Write-ColoredMessage "Please start Docker Desktop and try again" -Color Yellow
exit 1
}
Write-ColoredMessage "Downloading latest release..." -Color Green
# Determine architecture
$arch = if ([Environment]::Is64BitOperatingSystem) { "amd64" } else { "386" }
# Get the latest release URL
try {
$apiResponse = Invoke-RestMethod -Uri "https://api.github.com/repos/Automata-Labs-team/code-sandbox-mcp/releases/latest"
$asset = $apiResponse.assets | Where-Object { $_.name -like "code-sandbox-mcp-windows-$arch.exe" }
} catch {
Write-ColoredMessage "Error: Failed to fetch latest release information" -Color Red
Write-Host $_.Exception.Message
exit 1
}
if (-not $asset) {
Write-ColoredMessage "Error: Could not find release for windows-$arch" -Color Red
exit 1
}
# Create installation directory
$installDir = "$env:LOCALAPPDATA\code-sandbox-mcp"
New-Item -ItemType Directory -Force -Path $installDir | Out-Null
# Download to a temporary file first
$tempFile = "$installDir\code-sandbox-mcp.tmp"
Write-ColoredMessage "Installing to $installDir\code-sandbox-mcp.exe..." -Color Green
try {
# Download the binary to temporary file
Invoke-WebRequest -Uri $asset.browser_download_url -OutFile $tempFile
# Stop any running instances
Stop-RunningInstances -ProcessName "code-sandbox-mcp"
# Try to move the temporary file to the final location
try {
Move-Item -Path $tempFile -Destination "$installDir\code-sandbox-mcp.exe" -Force
} catch {
Write-ColoredMessage "Error: Failed to install the binary. Please ensure no instances are running and try again." -Color Red
Remove-Item -Path $tempFile -ErrorAction SilentlyContinue
exit 1
}
} catch {
Write-ColoredMessage "Error: Failed to download or install the binary" -Color Red
Write-Host $_.Exception.Message
Remove-Item -Path $tempFile -ErrorAction SilentlyContinue
exit 1
}
# Add to Claude Desktop config
Write-ColoredMessage "Adding to Claude Desktop configuration..." -Color Green
try {
& "$installDir\code-sandbox-mcp.exe" --install
} catch {
Write-ColoredMessage "Error: Failed to configure Claude Desktop" -Color Red
Write-Host $_.Exception.Message
exit 1
}
Write-ColoredMessage "Installation complete!" -Color Green
Write-Host "You can now use code-sandbox-mcp with Claude Desktop or other AI applications."