1212 [string ]$Version = " " ,
1313 [string ]$Binary = " " ,
1414 [string ]$InstallDir = " " ,
15+ [string ]$Token = " " ,
1516 [switch ]$NoModifyPath ,
1617 [switch ]$Help
1718)
@@ -38,17 +39,39 @@ Options:
3839 -Version <version> Install a specific version (e.g., 0.1.0)
3940 -Binary <path> Install from a local binary instead of downloading
4041 -InstallDir <path> Override install location (default: %LOCALAPPDATA%\Programs\claurst)
42+ -Token <token> GitHub token for API/downloads (or set GITHUB_TOKEN / GH_TOKEN)
4143 -NoModifyPath Don't add the install dir to user PATH
4244
4345Examples:
4446 irm https://github.com/Kuberwastaken/claurst/releases/latest/download/install.ps1 | iex
4547 .\install.ps1 -Version 0.1.0
4648 .\install.ps1 -Binary C:\path\to\claurst.exe
49+ `$ env:GITHUB_TOKEN = 'ghp_...'; .\install.ps1
4750"@
4851}
4952
5053if ($Help ) { Show-Usage ; exit 0 }
5154
55+ # Prefer -Token; otherwise GITHUB_TOKEN, then GH_TOKEN (gh CLI convention).
56+ if ([string ]::IsNullOrEmpty($Token )) {
57+ if (-not [string ]::IsNullOrEmpty($env: GITHUB_TOKEN )) {
58+ $Token = $env: GITHUB_TOKEN
59+ } elseif (-not [string ]::IsNullOrEmpty($env: GH_TOKEN )) {
60+ $Token = $env: GH_TOKEN
61+ }
62+ }
63+
64+ function Get-GitHubHeaders {
65+ $headers = @ {
66+ ' User-Agent' = ' claurst-installer'
67+ ' Accept' = ' application/vnd.github+json'
68+ }
69+ if (-not [string ]::IsNullOrEmpty($script :Token )) {
70+ $headers [' Authorization' ] = " Bearer $ ( $script :Token ) "
71+ }
72+ return $headers
73+ }
74+
5275# ----- Detect architecture -----
5376function Get-Arch {
5477 $procArch = $env: PROCESSOR_ARCHITECTURE
@@ -88,12 +111,17 @@ function Resolve-Version {
88111 return ($script :Version -replace ' ^v' , ' ' )
89112 }
90113 try {
91- $resp = Invoke-RestMethod - UseBasicParsing - Uri " https://api.github.com/repos/$Repo /releases/latest" - Headers @ { ' User-Agent' = ' claurst-installer' }
114+ $resp = Invoke-RestMethod - UseBasicParsing `
115+ - Uri " https://api.github.com/repos/$Repo /releases/latest" `
116+ - Headers (Get-GitHubHeaders )
92117 $tag = $resp.tag_name
93118 if ([string ]::IsNullOrEmpty($tag )) { throw " no tag_name in response" }
94119 return ($tag -replace ' ^v' , ' ' )
95120 } catch {
96121 Write-Err " Failed to fetch latest version from GitHub API: $_ "
122+ if ([string ]::IsNullOrEmpty($script :Token )) {
123+ Write-Info " If you hit rate limits or need a private release, set GITHUB_TOKEN or pass -Token."
124+ }
97125 exit 1
98126 }
99127}
@@ -129,16 +157,23 @@ function Download-And-Install($desiredVersion, $arch) {
129157
130158 Write-Info " Installing claurst v$desiredVersion (windows-$arch )"
131159 Write-Muted " Downloading $url "
160+ if (-not [string ]::IsNullOrEmpty($script :Token )) {
161+ Write-Muted " Using GitHub authentication."
162+ }
163+ $ghHeaders = Get-GitHubHeaders
132164 try {
133165 # Disable progress UI for a faster, less noisy download.
134166 $oldPref = $ProgressPreference
135167 $ProgressPreference = ' SilentlyContinue'
136- Invoke-WebRequest - UseBasicParsing - Uri $url - OutFile $zipPath
168+ Invoke-WebRequest - UseBasicParsing - Uri $url - OutFile $zipPath - Headers $ghHeaders
137169 $ProgressPreference = $oldPref
138170 } catch {
139171 Write-Err " Download failed: $_ "
140172 Write-Info (" Check that release v$desiredVersion exists for windows-" + $arch + " :" )
141173 Write-Info " https://github.com/$Repo /releases/tag/v$desiredVersion "
174+ if ([string ]::IsNullOrEmpty($script :Token )) {
175+ Write-Info " Private releases require GITHUB_TOKEN / GH_TOKEN or -Token."
176+ }
142177 Remove-Item - Recurse - Force $tmpRoot - ErrorAction SilentlyContinue
143178 exit 1
144179 }
@@ -154,7 +189,7 @@ function Download-And-Install($desiredVersion, $arch) {
154189 try {
155190 $oldPref2 = $ProgressPreference
156191 $ProgressPreference = ' SilentlyContinue'
157- Invoke-WebRequest - UseBasicParsing - Uri $sumsUrl - OutFile $sumsPath
192+ Invoke-WebRequest - UseBasicParsing - Uri $sumsUrl - OutFile $sumsPath - Headers $ghHeaders
158193 $ProgressPreference = $oldPref2
159194 $haveSums = $true
160195 } catch {
@@ -223,16 +258,20 @@ function Install-FromBinary {
223258
224259function Install-Binary ($source ) {
225260 $target = Join-Path $InstallDir ' claurst.exe'
261+ $stale = " $target .old"
226262
227263 # The currently running claurst.exe (if any) holds an exclusive file lock on
228- # Windows. Try to swap by renaming the old one first.
264+ # Windows. Swap by renaming the old one aside, then remove it after the
265+ # new binary is in place (the lock is on the path that was open).
229266 if (Test-Path $target ) {
230- $stale = " $target .old"
231267 if (Test-Path $stale ) { Remove-Item - Force $stale - ErrorAction SilentlyContinue }
232268 try { Move-Item - Force $target $stale } catch { }
233269 }
234270
235271 Copy-Item - Force $source $target
272+ if (Test-Path $stale ) {
273+ Remove-Item - Force $stale - ErrorAction SilentlyContinue
274+ }
236275 Write-Success " Installed: $target "
237276}
238277
0 commit comments