@@ -36,11 +36,6 @@ function Checklist {
3636 Write-Host " -> $args " - ForegroundColor DarkGray
3737}
3838
39- function Underline {
40- param ([string ]$Text )
41- return " $Text "
42- }
43-
4439function Tildify ($Path ) {
4540 $userHome = $HOME.TrimEnd (' \' )
4641 if ($Path -like " $userHome *" ) {
@@ -119,7 +114,7 @@ function Get-Env {
119114}
120115
121116# Constants
122- $ASTRA_CLI_VERSION = " 1.0.0-rc.3 "
117+ $ASTRA_CLI_VERSION = " 1.0.0-rc.4 "
123118
124119if ($env: ASTRA_HOME ) {
125120 $ASTRA_CLI_DIR = " $env: ASTRA_HOME \cli"
@@ -192,7 +187,7 @@ if (-not $existingInstallPath -and (Test-Path (Join-Path $ASTRA_CLI_DIR "astra.e
192187if ($existingInstallPath ) {
193188 Write-Host " "
194189 Write-Host " Error: An existing astra installation was already found." - ForegroundColor Red
195- Write-Host " An existing installation was found at $ ( Underline ( Tildify (Split-Path $existingInstallPath )) ) `n "
190+ Write-Host " An existing installation was found at $ ( Tildify (Split-Path $existingInstallPath )) `n "
196191 Write-MultiColor - Texts @ (" -> " , " (< astra-cli 1.x)" , " Remove the existing installation manually and re-run this installer." ) - Colors @ (" DarkCyan" , " DarkGray" , " Gray" )
197192 Write-MultiColor - Texts @ (" -> " , " (> astra-cli 1.x)" , " Run " , " astra upgrade" , " to automatically update to the latest version." ) - Colors @ (" DarkCyan" , " DarkGray" , " Gray" , " DarkCyan" , " Gray" )
198193 Write-MultiColor - Texts @ (" -> " , " (> astra-cli 1.x)" , " Run " , " astra nuke" , " to completely remove the CLI and then re-run this installer." ) - Colors @ (" DarkCyan" , " DarkGray" , " Gray" , " DarkCyan" , " Gray" )
@@ -202,17 +197,15 @@ if ($existingInstallPath) {
202197 Print- Next- Steps - PathWasAdded $false
203198 throw " Existing installation found"
204199}
205- else {
206- Checklist " No existing installation found."
207- }
208200
209201# Create installation directory
210202New-Item - ItemType Directory - Force - Path $ASTRA_CLI_DIR | Out-Null
211- Checklist " Using installation dir $ ( Underline ( $ASTRA_CLI_DIR + " \" ) ) "
203+ Checklist " Using installation dir $ ( $ASTRA_CLI_DIR + " \" ) "
212204
213205# Download and extract
214206$zipPath = Join-Path $ASTRA_CLI_DIR " astra-tmp.zip"
215- $exePath = Join-Path $ASTRA_CLI_DIR " astra.exe"
207+ $uninstallPath = Join-Path $ASTRA_CLI_DIR " uninstall.ps1"
208+ $iconPath = Join-Path $ASTRA_CLI_DIR " astra.ico"
216209
217210Remove-Item - Force $zipPath - ErrorAction SilentlyContinue
218211
@@ -221,22 +214,17 @@ try {
221214 if ($LASTEXITCODE -ne 0 ) {
222215 throw " curl download failed with exit code $LASTEXITCODE "
223216 }
224- if (-not (Test-Path $zipPath ) -or (Get-Item $zipPath ).Length -eq 0 ) {
225- throw " Downloaded file is missing or empty"
226- }
227217 Checklist " Archive downloaded."
228218}
229219catch {
230220 try {
221+ Remove-Item $zipPath - ErrorAction SilentlyContinue
231222 Invoke-RestMethod - Uri $installUrl - OutFile $zipPath
232- if (-not (Test-Path $zipPath ) -or (Get-Item $zipPath ).Length -eq 0 ) {
233- throw " Downloaded file is missing or empty"
234- }
235223 Checklist " Archive downloaded via Invoke-RestMethod."
236224 }
237225 catch {
238226 Remove-Item $zipPath - ErrorAction SilentlyContinue
239- Panic " `n Error: Failed to download the archive to $ ( Underline ( Tildify $zipPath ) ) . Check your internet connection and permissions."
227+ Panic " `n Error: Failed to download the archive to $ ( Tildify $zipPath ) . Check your internet connection and permissions."
240228 }
241229}
242230
@@ -249,140 +237,82 @@ try {
249237 Expand-Archive - Path $zipPath - DestinationPath $tempDir - Force
250238 Checklist " Archive extracted to temp dir."
251239
252- $sourceExe = Join-Path $tempDir " astra\bin\astra.exe"
253-
254- # Verify extracted file exists
255- if (-not (Test-Path $sourceExe )) {
256- Remove-Item - Recurse - Force $tempDir
257- throw " astra.exe not found in archive. Archive may be corrupted."
258- }
240+ # Move all files from archive
241+ $sourceBinDir = Join-Path $tempDir " astra\bin"
242+ Get-ChildItem - Path $sourceBinDir | Move-Item - Destination $ASTRA_CLI_DIR - Force
259243
260- # Check if astra.exe is running before replacing
261- try {
262- Remove-Item - Force $exePath - ErrorAction Stop
263- }
264- catch [System.UnauthorizedAccessException ] {
265- $openProcesses = Get-Process - Name astra - ErrorAction SilentlyContinue | Where-Object { $_.Path -eq $exePath }
266- if ($openProcesses.Count -gt 0 ) {
267- Remove-Item - Recurse - Force $tempDir
268- Panic " `n Error: An existing astra.exe is running. Please close it and try again."
269- }
270- Remove-Item - Recurse - Force $tempDir
271- Panic " `n Error: Failed to replace existing astra.exe. Check file permissions."
272- }
273- catch [System.Management.Automation.ItemNotFoundException ] {
274- # File doesn't exist, that's fine
275- }
276-
277- Move-Item - Force $sourceExe $exePath
278244 Remove-Item - Recurse - Force $tempDir
279-
280- # Verify installation succeeded
281- if (-not (Test-Path $exePath )) {
282- throw " Failed to install astra.exe to final location"
283- }
284-
285- Checklist " Archive verified and extracted."
286245}
287246catch {
288- Panic " `n Error: Failed to extract the archive at $ ( Underline ( Tildify $zipPath ) ) ."
247+ Panic " `n Error: Failed to extract the archive at $ ( Tildify $zipPath ) ."
289248}
290249finally {
291250 Remove-Item - Force $zipPath - ErrorAction SilentlyContinue
292251 $global :ProgressPreference = $lastProgressPreference
293252}
294253
295- # Download uninstall script
296- $uninstallPath = Join-Path $ASTRA_CLI_DIR " uninstall.ps1"
297- $uninstallUrl = " https://raw.githubusercontent.com/datastax/astra-cli/main/scripts/uninstall.ps1"
298- $uninstallDownloaded = $false
299-
300- try {
301- curl.exe " -#sfLo" " $uninstallPath " " $uninstallUrl "
302- if ($LASTEXITCODE -eq 0 ) {
303- $uninstallDownloaded = $true
304- }
305- else {
306- throw " curl download failed"
307- }
308- }
309- catch {
310- try {
311- Invoke-RestMethod - Uri $uninstallUrl - OutFile $uninstallPath
312- $uninstallDownloaded = $true
313- }
314- catch {
315- Write-Host " Warning: Failed to download uninstall script." - ForegroundColor Yellow
316- }
254+ # Verify required files exist
255+ if (-not (Test-Path (Join-Path $ASTRA_CLI_DIR " astra.exe" ))) {
256+ Panic " astra.exe not found in archive. Archive may be corrupted."
317257}
318258
319- if ($uninstallDownloaded -and (Test-Path $uninstallPath )) {
320- Checklist " Downloaded uninstall script ."
259+ if (-not (Test-Path $uninstallPath )) {
260+ Panic " uninstall.ps1 not found in archive. Archive may be corrupted ."
321261}
322- else {
323- Write-Host " Warning: Uninstaller in Add/Remove Programs will not work." - ForegroundColor Yellow
262+
263+ if (-not (Test-Path $iconPath )) {
264+ Panic " astra.ico not found in archive. Archive may be corrupted."
324265}
325266
267+ Checklist " Archive extracted."
268+
326269# Add to PATH automatically
327270$pathWasAdded = $false
328- try {
329- $currentPath = Get-Env - Key " Path"
330- $Path = if ($null -ne $currentPath ) {
331- $currentPath -split ' ;'
332- }
333- else {
334- @ ()
335- }
271+ if (-not $NoPathUpdate ) {
272+ try {
273+ $currentPath = Get-Env - Key " Path"
274+ $Path = if ($null -ne $currentPath ) {
275+ $currentPath -split ' ;'
276+ }
277+ else {
278+ @ ()
279+ }
336280
337- if ($Path -notcontains $ASTRA_CLI_DIR ) {
338- if (-not $NoPathUpdate ) {
281+ if ($Path -notcontains $ASTRA_CLI_DIR ) {
339282 $Path += $ASTRA_CLI_DIR
340283 Write-Env - Key ' Path' - Value ($Path -join ' ;' )
341- $pathWasAdded = $true
342284 Checklist " Added to PATH."
343285 }
344- }
345- else {
346- Checklist " Already in PATH. "
286+ else {
287+ Checklist " Already in PATH. "
288+ }
347289 $pathWasAdded = $true
348290 }
349- }
350- catch {
351- Write-Host " Warning: Failed to update PATH. You'll need to add it manually. " - ForegroundColor Yellow
291+ catch {
292+ Write-Host " Warning: Failed to update PATH. You'll need to add it manually. " - ForegroundColor Yellow
293+ }
352294}
353295
354296# Register in Add/Remove Programs
355297if (-not $NoRegisterInstallation ) {
356- $rootKey = $null
357298 try {
299+ $uninstallPath = Join-Path $ASTRA_CLI_DIR " uninstall.ps1"
300+ $iconPath = Join-Path $ASTRA_CLI_DIR " astra.ico"
301+
358302 $RegistryKey = " HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\AstraCLI"
359- $rootKey = New-Item - Path $RegistryKey - Force
303+ New-Item - Path $RegistryKey - Force | Out-Null
360304 New-ItemProperty - Path $RegistryKey - Name " DisplayName" - Value " Astra CLI" - PropertyType String - Force | Out-Null
361305 New-ItemProperty - Path $RegistryKey - Name " DisplayVersion" - Value " $ASTRA_CLI_VERSION " - PropertyType String - Force | Out-Null
362306 New-ItemProperty - Path $RegistryKey - Name " Publisher" - Value " DataStax" - PropertyType String - Force | Out-Null
363307 New-ItemProperty - Path $RegistryKey - Name " InstallLocation" - Value " $ASTRA_CLI_DIR " - PropertyType String - Force | Out-Null
364- New-ItemProperty - Path $RegistryKey - Name " DisplayIcon" - Value " $exePath " - PropertyType String - Force | Out-Null
365-
366- # Use uninstall script if available, otherwise provide manual instructions
367- if ($uninstallDownloaded -and (Test-Path $uninstallPath )) {
368- New-ItemProperty - Path $RegistryKey - Name " UninstallString" - Value " powershell -ExecutionPolicy Bypass -File `" $uninstallPath `" -PauseOnError" - PropertyType String - Force | Out-Null
369- New-ItemProperty - Path $RegistryKey - Name " QuietUninstallString" - Value " powershell -ExecutionPolicy Bypass -File `" $uninstallPath `" " - PropertyType String - Force | Out-Null
370- }
371- else {
372- # Fallback: Point to a command that provides manual uninstall instructions
373- $fallbackCmd = " powershell -ExecutionPolicy Bypass -Command `" Write-Host 'To uninstall Astra CLI:' -ForegroundColor Yellow; Write-Host '1. Run: astra nuke' -ForegroundColor Cyan; Write-Host '2. Remove from PATH manually' -ForegroundColor Cyan; Write-Host '3. Delete registry key: HKCU:\Software\Microsoft\Windows\CurrentVersion\Uninstall\AstraCLI' -ForegroundColor Cyan; Read-Host 'Press Enter to close'`" "
374- New-ItemProperty - Path $RegistryKey - Name " UninstallString" - Value $fallbackCmd - PropertyType String - Force | Out-Null
375- }
376-
308+ New-ItemProperty - Path $RegistryKey - Name " DisplayIcon" - Value " $iconPath " - PropertyType String - Force | Out-Null
309+ New-ItemProperty - Path $RegistryKey - Name " UninstallString" - Value " powershell -ExecutionPolicy Bypass -File `" $uninstallPath `" -PauseOnError" - PropertyType String - Force | Out-Null
310+ New-ItemProperty - Path $RegistryKey - Name " QuietUninstallString" - Value " powershell -ExecutionPolicy Bypass -File `" $uninstallPath `" " - PropertyType String - Force | Out-Null
377311 New-ItemProperty - Path $RegistryKey - Name " NoModify" - Value 1 - PropertyType DWord - Force | Out-Null
378312 New-ItemProperty - Path $RegistryKey - Name " NoRepair" - Value 1 - PropertyType DWord - Force | Out-Null
379313 Checklist " Registered in Add/Remove Programs."
380314 }
381315 catch {
382- # Cleanup on failure
383- if ($rootKey -ne $null ) {
384- Remove-Item - Path $RegistryKey - Force - ErrorAction SilentlyContinue
385- }
386316 Write-Host " Warning: Failed to register in Add/Remove Programs." - ForegroundColor Yellow
387317 }
388318}
0 commit comments