Skip to content

Commit f12d81e

Browse files
committed
chore: update powershell script
1 parent cb25ee4 commit f12d81e

File tree

1 file changed

+69
-24
lines changed

1 file changed

+69
-24
lines changed

scripts/install.ps1

Lines changed: 69 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,22 @@
11
# Vapi CLI installation script for Windows
22
# Usage: iex ((New-Object System.Net.WebClient).DownloadString('https://vapi.ai/install.ps1'))
33

4+
[CmdletBinding()]
5+
param()
6+
47
$ErrorActionPreference = "Stop"
8+
$ProgressPreference = "SilentlyContinue" # Suppress progress bars for faster downloads
9+
10+
# Check if running on Windows
11+
if (-not $IsWindows) {
12+
Write-Host "[ERROR] This installer is for Windows only." -ForegroundColor Red
13+
Write-Host ""
14+
if ($IsMacOS -or $IsLinux) {
15+
Write-Host "For macOS/Linux, use the shell script instead:" -ForegroundColor Yellow
16+
Write-Host " curl -sSL https://vapi.ai/install.sh | bash" -ForegroundColor White
17+
}
18+
exit 1
19+
}
520

621
# Configuration
722
$Repo = "VapiAI/cli"
@@ -29,7 +44,14 @@ function Get-Platform {
2944
switch ($arch) {
3045
"AMD64" { return "Windows_x86_64" }
3146
"ARM64" { return "Windows_arm64" }
32-
default { Write-Error "Unsupported architecture: $arch" }
47+
default {
48+
# Also check PROCESSOR_ARCHITEW6432 for 32-bit processes on 64-bit systems
49+
$arch64 = $env:PROCESSOR_ARCHITEW6432
50+
if ($arch64 -eq "AMD64") {
51+
return "Windows_x86_64"
52+
}
53+
Write-Error "Unsupported architecture: $arch"
54+
}
3355
}
3456
}
3557

@@ -38,7 +60,11 @@ function Get-LatestVersion {
3860
Write-Info "Fetching latest version..."
3961

4062
try {
41-
$response = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest"
63+
$headers = @{}
64+
# Add User-Agent for better GitHub API compatibility
65+
$headers["User-Agent"] = "Vapi-CLI-Installer/1.0"
66+
67+
$response = Invoke-RestMethod -Uri "https://api.github.com/repos/$Repo/releases/latest" -Headers $headers
4268
$version = $response.tag_name
4369

4470
if (-not $version) {
@@ -49,7 +75,7 @@ function Get-LatestVersion {
4975
return $version
5076
}
5177
catch {
52-
Write-Error "Failed to fetch latest version: $_"
78+
Write-Error "Failed to fetch latest version: $($_.Exception.Message)"
5379
}
5480
}
5581

@@ -66,16 +92,20 @@ function Install-Vapi($Version, $Platform) {
6692
New-Item -ItemType Directory -Path $tempDir -Force | Out-Null
6793

6894
try {
69-
# Download the file
70-
Invoke-WebRequest -Uri $url -OutFile $tarFile
95+
# Download the file with progress
96+
$webClient = New-Object System.Net.WebClient
97+
$webClient.Headers.Add("User-Agent", "Vapi-CLI-Installer/1.0")
98+
$webClient.DownloadFile($url, $tarFile)
99+
$webClient.Dispose()
71100

72101
Write-Info "Extracting..."
73102

74-
# Extract tar.gz (requires tar.exe available in Windows 10+)
75-
if (Get-Command tar -ErrorAction SilentlyContinue) {
103+
# Check for tar.exe (available in Windows 10 1803+)
104+
$tarCmd = Get-Command tar -ErrorAction SilentlyContinue
105+
if ($tarCmd) {
76106
tar -xzf $tarFile -C $tempDir
77107
} else {
78-
Write-Error "tar command not found. Please update to Windows 10 version 1803 or later."
108+
Write-Error "tar command not found. Please update to Windows 10 version 1803 or later, or install a compatible extraction tool."
79109
}
80110

81111
# Create install directory
@@ -90,20 +120,20 @@ function Install-Vapi($Version, $Platform) {
90120
}
91121

92122
if (Test-Path $binaryPath) {
93-
Move-Item $binaryPath "$InstallDir\$BinaryName" -Force
123+
Copy-Item $binaryPath "$InstallDir\$BinaryName" -Force
94124
} else {
95125
Write-Error "Binary not found after extraction"
96126
}
97127

98-
Write-Info "Vapi CLI installed successfully!"
128+
Write-Info "Vapi CLI installed successfully to: $InstallDir"
99129
}
100130
catch {
101-
Write-Error "Installation failed: $_"
131+
Write-Error "Installation failed: $($_.Exception.Message)"
102132
}
103133
finally {
104134
# Cleanup
105135
if (Test-Path $tempDir) {
106-
Remove-Item $tempDir -Recurse -Force
136+
Remove-Item $tempDir -Recurse -Force -ErrorAction SilentlyContinue
107137
}
108138
}
109139
}
@@ -114,7 +144,11 @@ function Add-ToPath {
114144

115145
if ($currentPath -notlike "*$InstallDir*") {
116146
Write-Info "Adding Vapi CLI to PATH..."
147+
148+
# Clean up PATH before adding (remove trailing semicolons)
149+
$currentPath = $currentPath.TrimEnd(';')
117150
$newPath = "$currentPath;$InstallDir"
151+
118152
[Environment]::SetEnvironmentVariable("PATH", $newPath, "User")
119153

120154
# Update current session PATH
@@ -133,23 +167,28 @@ function Test-Installation {
133167
if (Test-Path $vapiPath) {
134168
# Test if vapi command works
135169
try {
136-
$version = & $vapiPath --version 2>$null
137-
Write-Info "Verification: $version"
138-
Write-Host ""
139-
Write-Info "Installation complete! 🎉"
140-
Write-Host ""
141-
Write-Host "Get started with:"
142-
Write-Host " vapi login"
143-
Write-Host " vapi --help"
144-
Write-Host ""
145-
Write-Warning "Please restart your terminal or PowerShell session to use 'vapi' command globally."
170+
$output = & $vapiPath --version 2>&1
171+
if ($LASTEXITCODE -eq 0) {
172+
Write-Info "Verification successful: $output"
173+
Write-Host ""
174+
Write-Info "Installation complete! 🎉"
175+
Write-Host ""
176+
Write-Host "Get started with:" -ForegroundColor Cyan
177+
Write-Host " vapi login" -ForegroundColor White
178+
Write-Host " vapi --help" -ForegroundColor White
179+
Write-Host ""
180+
Write-Warning "Please restart your terminal or PowerShell session to use 'vapi' command globally."
181+
} else {
182+
Write-Warning "Vapi CLI was installed but verification failed (exit code: $LASTEXITCODE)"
183+
Write-Warning "You may need to restart your terminal"
184+
}
146185
}
147186
catch {
148-
Write-Warning "Vapi CLI was installed but verification failed"
187+
Write-Warning "Vapi CLI was installed but verification failed: $($_.Exception.Message)"
149188
Write-Warning "You may need to restart your terminal"
150189
}
151190
} else {
152-
Write-Error "Installation verification failed - binary not found"
191+
Write-Error "Installation verification failed - binary not found at: $vapiPath"
153192
}
154193
}
155194

@@ -160,6 +199,12 @@ function Main {
160199
Write-Host "===================================" -ForegroundColor Cyan
161200
Write-Host ""
162201

202+
# Check Windows version
203+
$osVersion = [System.Environment]::OSVersion.Version
204+
if ($osVersion.Major -lt 10) {
205+
Write-Warning "Windows 10 or later is recommended for best compatibility"
206+
}
207+
163208
$platform = Get-Platform
164209
Write-Info "Detected platform: $platform"
165210

0 commit comments

Comments
 (0)