-
Notifications
You must be signed in to change notification settings - Fork 79
Add native Windows installer and documentation #676
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
nsxdavid
wants to merge
2
commits into
justrach:release/0.2.5829
from
nsxdavid:docs/windows-native-install
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,141 @@ | ||
| [CmdletBinding()] | ||
| param( | ||
| [string]$Version = $env:CODEDB_VERSION, | ||
| [string]$InstallDir = $env:CODEDB_DIR, | ||
| [switch]$NoPath | ||
| ) | ||
|
|
||
| Set-StrictMode -Version Latest | ||
| $ErrorActionPreference = "Stop" | ||
|
|
||
| $repo = "justrach/codedb" | ||
| $assetName = "codedb-windows-x86_64.exe" | ||
| $baseUrl = if ($env:CODEDB_URL) { $env:CODEDB_URL.TrimEnd("/") } else { "https://codedb.codegraff.com" } | ||
|
|
||
| if ([Environment]::OSVersion.Platform -ne [PlatformID]::Win32NT) { | ||
| throw "This installer is for native Windows. Use install.sh on macOS or Linux." | ||
| } | ||
|
|
||
| $architecture = [Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString() | ||
| if ($architecture -ne "X64") { | ||
| throw "Unsupported Windows architecture: $architecture (x86_64 is required)" | ||
| } | ||
|
|
||
| if (-not $InstallDir) { | ||
| $InstallDir = Join-Path $env:LOCALAPPDATA "Programs\codedb" | ||
| } | ||
| $InstallDir = [IO.Path]::GetFullPath($InstallDir) | ||
| if ($env:CODEDB_NO_PATH) { | ||
| $NoPath = $true | ||
| } | ||
|
|
||
| if (-not $Version) { | ||
| try { | ||
| $release = Invoke-RestMethod ` | ||
| -Headers @{ "User-Agent" = "codedb-installer" } ` | ||
| "https://api.github.com/repos/$repo/releases/latest" | ||
| $Version = $release.tag_name | ||
| } catch { | ||
| $latest = Invoke-RestMethod ` | ||
| -Headers @{ "User-Agent" = "codedb-installer" } ` | ||
| "$baseUrl/latest.json" | ||
| $Version = $latest.version | ||
| } | ||
| } | ||
| $Version = $Version.TrimStart("v", "V") | ||
| if ($Version -notmatch '^\d+\.\d+\.\d+(?:[-+][0-9A-Za-z.-]+)?$') { | ||
| throw "Invalid codedb version: $Version" | ||
| } | ||
|
|
||
| # Windows PowerShell 5.1 may otherwise negotiate an obsolete TLS version. | ||
| if ([Net.ServicePointManager]::SecurityProtocol -band [Net.SecurityProtocolType]::Tls12) { | ||
| # TLS 1.2 is already enabled. | ||
| } else { | ||
| [Net.ServicePointManager]::SecurityProtocol = ` | ||
| [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12 | ||
| } | ||
|
|
||
| $releaseUrl = "https://github.com/$repo/releases/download/v$Version" | ||
| $downloadDir = Join-Path ([IO.Path]::GetTempPath()) ("codedb-install-" + [guid]::NewGuid().ToString("N")) | ||
| $targetPath = Join-Path $InstallDir "codedb.exe" | ||
| $stagedPath = Join-Path $InstallDir ("codedb.exe.new." + $PID) | ||
|
|
||
| try { | ||
| New-Item -ItemType Directory -Force -Path $downloadDir, $InstallDir | Out-Null | ||
|
|
||
| $downloadedBinary = Join-Path $downloadDir $assetName | ||
| $downloadedChecksums = Join-Path $downloadDir "checksums.sha256" | ||
|
|
||
| Write-Host "codedb installer" | ||
| Write-Host " version v$Version" | ||
| Write-Host " install $InstallDir" | ||
| Write-Host " download $assetName" | ||
|
|
||
| Invoke-WebRequest -UseBasicParsing ` | ||
| -Headers @{ "User-Agent" = "codedb-installer" } ` | ||
| "$releaseUrl/$assetName" ` | ||
| -OutFile $downloadedBinary | ||
| Invoke-WebRequest -UseBasicParsing ` | ||
| -Headers @{ "User-Agent" = "codedb-installer" } ` | ||
| "$releaseUrl/checksums.sha256" ` | ||
| -OutFile $downloadedChecksums | ||
|
|
||
| $checksumLine = Get-Content -LiteralPath $downloadedChecksums | | ||
| Where-Object { $_ -match "\s\*?$([regex]::Escape($assetName))$" } | | ||
| Select-Object -First 1 | ||
| if (-not $checksumLine) { | ||
| throw "Release v$Version has no checksum for $assetName" | ||
| } | ||
|
|
||
| $expectedHash = ($checksumLine -split '\s+')[0] | ||
| if ($expectedHash -notmatch '^[0-9a-fA-F]{64}$') { | ||
| throw "Release v$Version contains an invalid checksum for $assetName" | ||
| } | ||
|
|
||
| $actualHash = (Get-FileHash -LiteralPath $downloadedBinary -Algorithm SHA256).Hash | ||
| if ($actualHash -ne $expectedHash.ToUpperInvariant()) { | ||
| throw "SHA256 mismatch for $assetName" | ||
| } | ||
| Write-Host " verify SHA256 OK" | ||
|
|
||
| Copy-Item -LiteralPath $downloadedBinary -Destination $stagedPath -Force | ||
| Unblock-File -LiteralPath $stagedPath -ErrorAction SilentlyContinue | ||
| Move-Item -LiteralPath $stagedPath -Destination $targetPath -Force | ||
|
|
||
| if (-not $NoPath) { | ||
| $userPath = [Environment]::GetEnvironmentVariable("Path", "User") | ||
| $pathEntries = @($userPath -split ';' | Where-Object { $_ }) | ||
| $alreadyOnPath = $false | ||
| foreach ($entry in $pathEntries) { | ||
| if ($entry.TrimEnd("\") -ieq $InstallDir.TrimEnd("\")) { | ||
| $alreadyOnPath = $true | ||
| break | ||
| } | ||
| } | ||
| if (-not $alreadyOnPath) { | ||
| $newUserPath = if ($userPath) { | ||
| $userPath.TrimEnd(';') + ';' + $InstallDir | ||
| } else { | ||
| $InstallDir | ||
| } | ||
| [Environment]::SetEnvironmentVariable("Path", $newUserPath, "User") | ||
| Write-Host " PATH added for future terminals" | ||
| } | ||
| } | ||
|
|
||
| if (-not (($env:PATH -split ';') | Where-Object { $_.TrimEnd("\") -ieq $InstallDir.TrimEnd("\") })) { | ||
| $env:PATH = "$InstallDir;$env:PATH" | ||
| } | ||
|
|
||
| & $targetPath --version | ||
| if ($LASTEXITCODE -ne 0) { | ||
| throw "Installed codedb failed its version check" | ||
| } | ||
|
|
||
| Write-Host "" | ||
| Write-Host "Installed: $targetPath" | ||
| Write-Host "MCP command: $targetPath mcp" | ||
| } finally { | ||
| Remove-Item -LiteralPath $stagedPath -Force -ErrorAction SilentlyContinue | ||
| Remove-Item -LiteralPath $downloadDir -Recurse -Force -ErrorAction SilentlyContinue | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In Windows PowerShell 5.1 environments where
ServicePointManager.SecurityProtocoldoes not already include TLS 1.2, this firstInvoke-RestMethodstill negotiates with the obsolete default because the TLS 1.2 setup runs later at lines 50-56. That means both the GitHub release lookup and thelatest.jsonfallback can fail before the installer reaches the download step, so the documented PowerShell one-liner exits without installing; move the TLS-enabling block above this first network call.Useful? React with 👍 / 👎.