Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 46 additions & 16 deletions tools/install/install.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ function Say-Green {
param([string]$Message)
if (Use-Color) {
Write-Host $Message -ForegroundColor Green
} else {
}
else {
Write-Host $Message
}
}
Expand All @@ -41,7 +42,8 @@ function Say-Red {
param([string]$Message)
if (Use-Color) {
Write-Host $Message -ForegroundColor Red
} else {
}
else {
Write-Host $Message
}
}
Expand Down Expand Up @@ -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."
}
}
}
Expand All @@ -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"
}

Expand Down Expand Up @@ -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"
}
}
Expand Down Expand Up @@ -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"
}
Expand All @@ -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"
}
Expand All @@ -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"
}

Expand All @@ -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
}
Expand Down Expand Up @@ -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
}
Expand Down Expand Up @@ -354,6 +383,7 @@ if ($Help) {

if ($Uninstall) {
Invoke-Uninstall
} else {
}
else {
Invoke-Install -RequestedVersion $Version
}
Loading