Skip to content

Commit b5d8bce

Browse files
committed
add: script files for easy download
1 parent 7e708bb commit b5d8bce

File tree

2 files changed

+237
-0
lines changed

2 files changed

+237
-0
lines changed

scripts/download.ps1

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
#!/usr/bin/env pwsh
2+
3+
<# only supports windows,
4+
# `SUPPORTED_OS` array contains the supported linux and darwin for filtering only
5+
# `SUPPORTED_ARCH` array contains the supported architectures but only x86_64/amd64 are
6+
# available for now. both amd64 and x86_64 are there cause windows does report either
7+
# of them when querying for the architecture.
8+
#>
9+
[System.String[]]$SUPPORTED_ARCH = @("x86_64", "arm64", "amd64")
10+
[System.String[]]$SUPPORTED_OS = @("linux", "darwin", "win32nt")
11+
12+
# Associate binaries with CPU architectures and operating systems
13+
[System.Collections.Hashtable]$BINARIES = @{
14+
"x86_64-linux" = "Parseable_x86_64-unknown-linux-gnu"
15+
"arm64-linux" = "Parseable_aarch64-unknown-linux-gnu"
16+
"x86_64-darwin" = "Parseable_x86_64-apple-darwin"
17+
"arm64-darwin" = "Parseable_aarch64-apple-darwin"
18+
"amd64-win32nt" = "Parseable_x86_64-pc-windows-msvc.exe"
19+
}
20+
21+
# util functions
22+
function Get-Env {
23+
param([String] $Key)
24+
25+
$RegisterKey = Get-Item -Path 'HKCU:'
26+
$EnvRegisterKey = $RegisterKey.OpenSubKey('Environment')
27+
$EnvRegisterKey.GetValue($Key, $null, [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames)
28+
}
29+
30+
# These three environment functions are roughly copied from https://github.com/prefix-dev/pixi/pull/692
31+
# They are used instead of `SetEnvironmentVariable` because of unwanted variable expansions.
32+
function Publish-Env {
33+
if (-not ("Win32.NativeMethods" -as [Type])) {
34+
<# dllimport should not be needed but still#>
35+
Add-Type -Namespace Win32 -Name NativeMethods -MemberDefinition @"
36+
[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)]
37+
public static extern IntPtr SendMessageTimeout(
38+
IntPtr hWnd, uint Msg, UIntPtr wParam, string lParam,
39+
uint fuFlags, uint uTimeout, out UIntPtr lpdwResult);
40+
"@
41+
}
42+
$HWND_BROADCAST = [IntPtr] 0xffff
43+
$WM_SETTINGCHANGE = 0x1a
44+
$result = [UIntPtr]::Zero
45+
[Win32.NativeMethods]::SendMessageTimeout($HWND_BROADCAST,
46+
$WM_SETTINGCHANGE,
47+
[UIntPtr]::Zero,
48+
"Environment",
49+
2,
50+
5000,
51+
[ref] $result
52+
) | Out-Null
53+
}
54+
function Write-Env {
55+
param([String]$Key, [String]$Value)
56+
57+
[Microsoft.Win32.RegistryKey]$RegisterKey = Get-Item -Path 'HKCU:'
58+
59+
60+
[Microsoft.Win32.RegistryKey]$EnvRegisterKey = $RegisterKey.OpenSubKey('Environment', $true)
61+
if ($null -eq $Value) {
62+
$EnvRegisterKey.DeleteValue($Key)
63+
}
64+
else {
65+
$RegistryValueKind = if ($Value.Contains('%')) {
66+
[Microsoft.Win32.RegistryValueKind]::ExpandString
67+
}
68+
elseif ($EnvRegisterKey.GetValue($Key)) {
69+
$EnvRegisterKey.GetValueKind($Key)
70+
}
71+
else {
72+
[Microsoft.Win32.RegistryValueKind]::String
73+
}
74+
$EnvRegisterKey.SetValue($Key, $Value, $RegistryValueKind)
75+
}
76+
77+
Publish-Env
78+
}
79+
80+
function Get-Env {
81+
param([String] $Key)
82+
83+
[Microsoft.Win32.RegistryKey]$RegisterKey = Get-Item -Path 'HKCU:'
84+
[Microsoft.Win32.RegistryKey]$EnvRegisterKey = $RegisterKey.OpenSubKey('Environment')
85+
$EnvRegisterKey.GetValue($Key, $null, [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames)
86+
}
87+
88+
# Get the system's CPU architecture and operating system
89+
[String]$CPU_ARCH = [System.Environment]::GetEnvironmentVariable("PROCESSOR_ARCHITECTURE").ToLower()
90+
[String]$OS = [System.Environment]::OSVersion.Platform.ToString().ToLower()
91+
[String]$INSTALLDIR = "${HOME}\.parseable\bin"
92+
[String]$BIN = "${INSTALLDIR}\parseable.exe"
93+
94+
function Install-Parseable {
95+
Write-Output "OS: $OS"
96+
Write-Output "CPU arch: $CPU_ARCH"
97+
98+
# Check if the CPU architecture is supported
99+
if ($SUPPORTED_ARCH -notcontains $CPU_ARCH) {
100+
Write-Error "Unsupported CPU architecture ($CPU_ARCH)."
101+
exit 1
102+
}
103+
# Check if the OS is supported
104+
if ($SUPPORTED_OS -notcontains $OS) {
105+
Write-Error "Unsupported operating system ($OS)."
106+
exit 1
107+
}
108+
109+
Write-Output "Checking for existing installation..."
110+
if (Test-Path $BIN) {
111+
Write-Error "Parseable is already installed. Run 'parseable --version' to check the version."
112+
Write-Error "Consider removing the existing installation"
113+
exit 1
114+
}
115+
116+
Write-Output "No existing installation found"
117+
118+
Write-Output "Fetching latest release..."
119+
# Get the latest release information using GitHub API
120+
$release = Invoke-RestMethod -Uri "https://api.github.com/repos/parseablehq/parseable/releases/latest"
121+
# Loop through binaries in the release and find the appropriate one
122+
foreach ($arch_os in "$CPU_ARCH-$OS") {
123+
$binary_name = $BINARIES[$arch_os]
124+
$download_url = ($release.assets | Where-Object { $_.name -like "*$binary_name*" }).browser_download_url
125+
if ($download_url) {
126+
break
127+
}
128+
}
129+
130+
mkdir -Force $INSTALLDIR
131+
132+
Write-Output "Downloading Parseable Server..."
133+
# Download the binary using Invoke-WebRequest
134+
Invoke-WebRequest -Uri $download_url -OutFile $BIN
135+
136+
# Make the binary executable (for Unix-like systems)
137+
if ($OS -eq "linux" -or $OS -eq "darwin") {
138+
Set-ItemProperty -Path $BIN -Name IsReadOnly -Value $false
139+
Set-ItemProperty -Path $BIN -Name IsExecutable -Value $true
140+
}
141+
142+
Write-Output "Adding Parseable to PATH..."
143+
# Only try adding to path if there isn't already a bun.exe in the path
144+
$Path = (Get-Env -Key "Path") -split ';'
145+
if ($Path -notcontains $INSTALLDIR) {
146+
$Path += $INSTALLDIR
147+
Write-Env -Key 'Path' -Value ($Path -join ';')
148+
$env:PATH = $Path;
149+
}
150+
}
151+
152+
Install-Parseable
153+
154+
Write-Output "Parseable was downloaded successfully! at $INSTALLDIR"
155+
Write-Output "To get started, restart your terminal/editor, then type `"parseable`"`n"

scripts/download.sh

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
#!/bin/zsh
2+
3+
# supported CPU architectures and operating systems
4+
SUPPORTED_ARCH=("x86_64" "arm64")
5+
SUPPORTED_OS=("linux" "darwin")
6+
# Associate binaries with CPU architectures and operating systems
7+
declare -A BINARIES=(
8+
["x86_64-linux"]="Parseable_x86_64-unknown-linux-gnu"
9+
["arm64-linux"]="Parseable_aarch64-unknown-linux-gnu"
10+
["x86_64-darwin"]="Parseable_x86_64-apple-darwin"
11+
["arm64-darwin"]="Parseable_aarch64-apple-darwin"
12+
)
13+
# Get the system's CPU architecture and operating system
14+
CPU_ARCH=$(uname -m)
15+
OS=$(uname -s | tr '[:upper:]' '[:lower:]')
16+
17+
printf "Detected CPU architecture: %s\n" "$CPU_ARCH"
18+
printf "Detected operating system: %s\n" "$OS"
19+
20+
SHELL_NAME=$(basename $SHELL)
21+
RC_FILE=".${SHELL_NAME}rc"
22+
RC_FILE_PATH="${HOME}/${RC_FILE}"
23+
INSTALL_DIR="${HOME}/.parseable"
24+
BIN_DIR="${INSTALL_DIR}/bin"
25+
BIN_NAME="${BIN_DIR}/parseable"
26+
27+
# Check if the CPU architecture is supported
28+
if ! echo "${SUPPORTED_ARCH[@]}" | grep -q "\\b${CPU_ARCH}\\b"; then
29+
echo "Error: Unsupported CPU architecture (${CPU_ARCH})."
30+
exit 1
31+
fi
32+
# Check if the OS is supported
33+
if ! echo "${SUPPORTED_OS[@]}" | grep -q "\\b${OS}\\b"; then
34+
echo "Error: Unsupported operating system (${OS})."
35+
exit 1
36+
fi
37+
# Get the latest release information using GitHub API
38+
release=$(curl -s "https://api.github.com/repos/parseablehq/parseable/releases/latest")
39+
40+
printf "Fetching release information for parseable...\n"
41+
42+
# Loop through binaries in the release and find the appropriate one
43+
for arch_os in "${CPU_ARCH}-${OS}"; do
44+
binary_name="${BINARIES[$arch_os]}"
45+
download_url=$(echo "$release" | grep -o "\"browser_download_url\":\s*\"[^\"]*${binary_name}\"" | cut -d '"' -f 4)
46+
if [ -n "$download_url" ]; then
47+
break
48+
fi
49+
done
50+
51+
printf "Checking for existing installation...\n"
52+
if [[ -d ${INSTALL_DIR} ]]; then
53+
printf "A Previous version of parseable already exists. Run 'parseable --version' to check the version."
54+
printf "or consider removing that before Installing"
55+
exit 1
56+
57+
else
58+
printf "No Previous installation found\n"
59+
printf "Installing parseable...\n"
60+
mkdir -p ${BIN_DIR}
61+
fi
62+
63+
64+
# Download the binary using curl or wget
65+
if command -v curl &>/dev/null; then
66+
curl -L -o "${BIN_NAME}" "$download_url" 2&>> /dev/null
67+
elif command -v wget &>/dev/null; then
68+
wget -O "${BIN_NAME}" "$download_url" 2&>> /dev/null
69+
else
70+
echo "Error: Neither curl nor wget found. Please install either curl or wget."
71+
exit 1
72+
fi
73+
74+
printf "Parseable Server was successfully installed at: ${BIN_NAME}\n"
75+
76+
chmod +x "${BIN_NAME}"
77+
78+
printf "Adding parseable to the path\n"
79+
PATH_STR="export PATH=${BIN_DIR}"':$PATH'
80+
echo ${PATH_STR} >> ${RC_FILE_PATH}
81+
82+
echo "parseable was added to the path. Please refresh the environment by sourcing the ${RC_PATH}"

0 commit comments

Comments
 (0)