From 16a24834ce710ac294c2a0b1f3c5b7f0edbbdb79 Mon Sep 17 00:00:00 2001 From: Rahul Kumar Date: Sun, 5 Apr 2026 01:03:40 +0530 Subject: [PATCH] fix the error for architecture detection and automated adding path var --- tools/install/install.ps1 | 62 +++++++++++++++++++++++++++++---------- 1 file changed, 46 insertions(+), 16 deletions(-) diff --git a/tools/install/install.ps1 b/tools/install/install.ps1 index a551ae78..94a86dd4 100644 --- a/tools/install/install.ps1 +++ b/tools/install/install.ps1 @@ -32,7 +32,8 @@ function Say-Green { param([string]$Message) if (Use-Color) { Write-Host $Message -ForegroundColor Green - } else { + } + else { Write-Host $Message } } @@ -41,7 +42,8 @@ function Say-Red { param([string]$Message) if (Use-Color) { Write-Host $Message -ForegroundColor Red - } else { + } + else { Write-Host $Message } } @@ -105,11 +107,24 @@ function Get-RequestHeaders { # --- Platform detection --- function Detect-Architecture { - $arch = [System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture + # Detect architecture from environment variable + $arch = if ($env:PROCESSOR_ARCHITECTURE -eq "AMD64") { + "x86_64" + } + elseif ($env:PROCESSOR_ARCHITECTURE -eq "x86") { + "x86" + } + else { + $env:PROCESSOR_ARCHITECTURE + } + + Write-Host "Detected architecture: $arch" + + # Check if supported switch ($arch) { - "X64" { return "x86_64" } + "x86_64" { return "x86_64" } # Supported default { - Fail-Installer "error: Unsupported architecture: $arch`n meshc currently supports x86_64 (64-bit) Windows only." + Fail-Installer "error: Unsupported architecture: $arch`nmeshc currently supports x86_64 (64-bit) Windows only." } } } @@ -120,7 +135,8 @@ function Get-LatestVersion { $releaseApiUrl = Get-ReleaseApiUrl try { $release = Invoke-RestMethod -Uri $releaseApiUrl -Headers (Get-RequestHeaders) -TimeoutSec (Get-DownloadTimeoutSec) - } catch { + } + catch { Fail-Installer "error: Failed to fetch release metadata.`n URL: $releaseApiUrl" } @@ -195,7 +211,8 @@ function Invoke-MeshDownload { try { Invoke-WebRequest -Uri $Url -OutFile $OutFile -Headers (Get-RequestHeaders) -TimeoutSec (Get-DownloadTimeoutSec) | Out-Null - } catch { + } + catch { Fail-Installer "$FailureMessage`n URL: $Url`n timeout: $(Get-DownloadTimeoutSec)s" } } @@ -244,7 +261,8 @@ function Install-Binary { try { Invoke-WebRequest -Uri $checksumUrl -OutFile $checksumPath -Headers (Get-RequestHeaders) -TimeoutSec (Get-DownloadTimeoutSec) | Out-Null - } catch { + } + catch { if (Test-StrictProofMode) { Fail-Installer "error: Could not download SHA256SUMS in staged-proof mode.`n URL: $checksumUrl`n timeout: $(Get-DownloadTimeoutSec)s" } @@ -258,9 +276,11 @@ function Install-Binary { Fail-Installer "error: SHA256SUMS contained a malformed checksum for $archive.`n checksum file: $checksumPath`n checksum URL: $checksumUrl" } Say "warning: Malformed SHA256SUMS entry for $archive, skipping verification." - } elseif ($expectedHash) { + } + elseif ($expectedHash) { Verify-Checksum -FilePath $archivePath -Expected $expectedHash - } else { + } + else { if (Test-StrictProofMode) { Fail-Installer "error: SHA256SUMS did not contain $archive.`n checksum file: $checksumPath`n checksum URL: $checksumUrl" } @@ -271,7 +291,8 @@ function Install-Binary { $extractDir = Join-Path $tmpDir 'extracted' try { Expand-Archive -Path $archivePath -DestinationPath $extractDir -Force - } catch { + } + catch { Fail-Installer "error: Failed to extract $archive.`n archive: $archivePath" } @@ -283,7 +304,8 @@ function Install-Binary { New-Item -ItemType Directory -Path $BinDir -Force | Out-Null Copy-Item -Path $sourceBinary.FullName -Destination (Join-Path $BinDir "$BinaryName.exe") -Force $success = $true - } finally { + } + finally { if ($success -and (Test-Path $tmpDir)) { Remove-Item -Recurse -Force $tmpDir -ErrorAction SilentlyContinue } @@ -318,14 +340,21 @@ function Invoke-Install { if (-not $userPath -or $userPath -notlike "*$BinDir*") { if ($userPath) { [Environment]::SetEnvironmentVariable('Path', "$BinDir;$userPath", 'User') - } else { + } + else { [Environment]::SetEnvironmentVariable('Path', $BinDir, 'User') } } + # Update PATH for current session + if ($env:Path -notlike "*$BinDir*") { + $env:Path = "$BinDir;$env:Path" + } + Say-Green "Installed meshc and meshpkg v$RequestedVersion to ~\.mesh\bin\" - Say "Run 'meshc --version' and 'meshpkg --version' to verify, or restart your terminal." - } catch { + Say "Run 'meshc --version' and 'meshpkg --version' to verify." + } + catch { Show-ErrorMessage $_.Exception.Message exit 1 } @@ -354,6 +383,7 @@ if ($Help) { if ($Uninstall) { Invoke-Uninstall -} else { +} +else { Invoke-Install -RequestedVersion $Version }