Skip to content

fix win download script #779

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

Merged
merged 1 commit into from
Apr 23, 2024
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
37 changes: 6 additions & 31 deletions scripts/download.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,7 @@
# of them when querying for the architecture.
#>
[System.String[]]$SUPPORTED_ARCH = @("x86_64", "arm64", "amd64")
[System.String[]]$SUPPORTED_OS = @("linux", "darwin", "win32nt")

# Associate binaries with CPU architectures and operating systems
[System.Collections.Hashtable]$BINARIES = @{
"x86_64-linux" = "Parseable_x86_64-unknown-linux-gnu"
"arm64-linux" = "Parseable_aarch64-unknown-linux-gnu"
"x86_64-darwin" = "Parseable_x86_64-apple-darwin"
"arm64-darwin" = "Parseable_aarch64-apple-darwin"
"amd64-win32nt" = "Parseable_x86_64-pc-windows-msvc.exe"
}
[System.String]$DOWNLOAD_BASE_URL="cdn.parseable.com/"

# util functions
function Get-Env {
Expand Down Expand Up @@ -86,12 +77,13 @@ function Get-Env {
}

# Get the system's CPU architecture and operating system
[String]$CPU_ARCH = [System.Environment]::GetEnvironmentVariable("PROCESSOR_ARCHITECTURE").ToLower()
[String]$OS = [System.Environment]::OSVersion.Platform.ToString().ToLower()
[String]$CPU_ARCH = "x86_64"
[String]$OS = "windows"
[String]$INSTALLDIR = "${HOME}\.parseable\bin"
[String]$BIN = "${INSTALLDIR}\parseable.exe"

function Install-Parseable {
Write-Output "`n=========================`n"
Write-Output "OS: $OS"
Write-Output "CPU arch: $CPU_ARCH"

Expand All @@ -100,11 +92,6 @@ function Install-Parseable {
Write-Error "Unsupported CPU architecture ($CPU_ARCH)."
exit 1
}
# Check if the OS is supported
if ($SUPPORTED_OS -notcontains $OS) {
Write-Error "Unsupported operating system ($OS)."
exit 1
}

Write-Output "Checking for existing installation..."
if (Test-Path $BIN) {
Expand All @@ -119,26 +106,14 @@ function Install-Parseable {
# Get the latest release information using GitHub API
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/parseablehq/parseable/releases/latest"
# Loop through binaries in the release and find the appropriate one
foreach ($arch_os in "$CPU_ARCH-$OS") {
$binary_name = $BINARIES[$arch_os]
$download_url = ($release.assets | Where-Object { $_.name -like "*$binary_name*" }).browser_download_url
if ($download_url) {
break
}
}
$download_url = $DOWNLOAD_BASE_URL + $CPU_ARCH + "-" + $OS + "." + $release.tag_name

mkdir -Force $INSTALLDIR

Write-Output "Downloading Parseable Server..."
Write-Output "Downloading Parseable version $release_tag, for OS: $OS, CPU architecture: $CPU_ARCH`n`n"
# Download the binary using Invoke-WebRequest
Invoke-WebRequest -Uri $download_url -OutFile $BIN

# Make the binary executable (for Unix-like systems)
if ($OS -eq "linux" -or $OS -eq "darwin") {
Set-ItemProperty -Path $BIN -Name IsReadOnly -Value $false
Set-ItemProperty -Path $BIN -Name IsExecutable -Value $true
}

Write-Output "Adding Parseable to PATH..."
# Only try adding to path if there isn't already a bun.exe in the path
$Path = (Get-Env -Key "Path") -split ';'
Expand Down