|
| 1 | +# DeepSource CLI installer for Windows |
| 2 | + |
| 3 | +$ErrorActionPreference = "Stop" |
| 4 | + |
| 5 | +$BaseUrl = "__BASE_URL__" |
| 6 | +$BinaryName = "__BINARY_NAME__" |
| 7 | + |
| 8 | +function Pass($msg) { Write-Host "✓ $msg" -ForegroundColor Green } |
| 9 | +function Fail($msg) { Write-Host "✗ $msg" -ForegroundColor Red; exit 1 } |
| 10 | +function Info($msg) { Write-Host "→ $msg" -ForegroundColor Cyan } |
| 11 | + |
| 12 | +$PlatformKey = "windows_amd64" |
| 13 | + |
| 14 | +# Fetch manifest |
| 15 | +try { |
| 16 | + $Manifest = Invoke-RestMethod -Uri "$BaseUrl/manifest.json" |
| 17 | +} catch { |
| 18 | + Fail "Failed to fetch manifest: $_" |
| 19 | +} |
| 20 | + |
| 21 | +$Version = $Manifest.version |
| 22 | +if (-not $Version) { |
| 23 | + Fail "Failed to determine latest version from manifest" |
| 24 | +} |
| 25 | +Pass "Version: v$Version" |
| 26 | + |
| 27 | +$Platform = $Manifest.platforms.$PlatformKey |
| 28 | +if (-not $Platform) { |
| 29 | + Fail "No build available for $PlatformKey" |
| 30 | +} |
| 31 | + |
| 32 | +$Archive = $Platform.archive |
| 33 | +$ExpectedSha = $Platform.sha256 |
| 34 | +$ArchiveUrl = "$BaseUrl/build/$Archive" |
| 35 | + |
| 36 | +# Download archive |
| 37 | +$TmpFile = Join-Path ([System.IO.Path]::GetTempPath()) $Archive |
| 38 | +try { |
| 39 | + Invoke-WebRequest -Uri $ArchiveUrl -OutFile $TmpFile -UseBasicParsing |
| 40 | +} catch { |
| 41 | + Fail "Failed to download archive: $_" |
| 42 | +} |
| 43 | +Pass "Downloaded" |
| 44 | + |
| 45 | +# Verify SHA256 |
| 46 | +$ActualSha = (Get-FileHash -Path $TmpFile -Algorithm SHA256).Hash.ToLower() |
| 47 | +if ($ActualSha -ne $ExpectedSha) { |
| 48 | + Remove-Item -Path $TmpFile -Force |
| 49 | + Fail "Checksum mismatch: expected $ExpectedSha, got $ActualSha" |
| 50 | +} |
| 51 | +Pass "Checksum verified" |
| 52 | + |
| 53 | +# Extract binary |
| 54 | +$InstallDir = Join-Path $env:LOCALAPPDATA "DeepSource\bin" |
| 55 | +if (-not (Test-Path $InstallDir)) { |
| 56 | + New-Item -ItemType Directory -Path $InstallDir -Force | Out-Null |
| 57 | +} |
| 58 | + |
| 59 | +$TmpExtract = Join-Path ([System.IO.Path]::GetTempPath()) "deepsource_extract" |
| 60 | +if (Test-Path $TmpExtract) { |
| 61 | + Remove-Item -Path $TmpExtract -Recurse -Force |
| 62 | +} |
| 63 | + |
| 64 | +Expand-Archive -Path $TmpFile -DestinationPath $TmpExtract -Force |
| 65 | +Copy-Item -Path (Join-Path $TmpExtract "$BinaryName.exe") -Destination (Join-Path $InstallDir "$BinaryName.exe") -Force |
| 66 | + |
| 67 | +# Cleanup |
| 68 | +Remove-Item -Path $TmpFile -Force |
| 69 | +Remove-Item -Path $TmpExtract -Recurse -Force |
| 70 | + |
| 71 | +Pass "Installed to $InstallDir\$BinaryName.exe" |
| 72 | + |
| 73 | +# Add to user PATH if not already present |
| 74 | +$UserPath = [Environment]::GetEnvironmentVariable("Path", "User") |
| 75 | +if ($UserPath -notlike "*$InstallDir*") { |
| 76 | + [Environment]::SetEnvironmentVariable("Path", "$InstallDir;$UserPath", "User") |
| 77 | + Pass "Added $InstallDir to user PATH" |
| 78 | + Info "Restart your terminal for PATH changes to take effect" |
| 79 | +} else { |
| 80 | + Pass "$InstallDir is already in PATH" |
| 81 | +} |
| 82 | + |
| 83 | +Write-Host "" |
| 84 | +Info "Run '$BinaryName' to get started" |
0 commit comments