From 994be5a035dcf19b45eda73f567cd36b146911f1 Mon Sep 17 00:00:00 2001 From: Eshan <60269431+Eshanatnight@users.noreply.github.com> Date: Tue, 23 Apr 2024 07:55:41 +0530 Subject: [PATCH] add: script files for easy download (#762) --- README.md | 27 ++------ scripts/download.ps1 | 155 +++++++++++++++++++++++++++++++++++++++++++ scripts/download.sh | 82 +++++++++++++++++++++++ 3 files changed, 241 insertions(+), 23 deletions(-) create mode 100644 scripts/download.ps1 create mode 100755 scripts/download.sh diff --git a/README.md b/README.md index 1a399f963..c3dbc6f23 100644 --- a/README.md +++ b/README.md @@ -64,35 +64,16 @@ curl --location --request POST 'http://localhost:8000/api/v1/ingest' \ You can download and run the Parseable binary on your laptop. -- Linux +- Linux or MacOS ```bash -wget https://github.com/parseablehq/parseable/releases/download/v0.9.0/Parseable_x86_64-unknown-linux-gnu -O parseable -chmod +x parseable -./parseable local-store -``` - -- MacOS (Apple Silicon) - -```bash -wget https://github.com/parseablehq/parseable/releases/download/v0.9.0/Parseable_aarch64-apple-darwin -O parseable -chmod +x parseable -./parseable local-store -``` - -- MacOS (Intel) - -```bash -wget https://github.com/parseablehq/parseable/releases/download/v0.9.0/Parseable_x86_64-apple-darwin -O parseable -chmod +x parseable -./parseable local-store +curl https://raw.githubusercontent.com/parseablehq/parseable/main/scripts/download.sh | bash ``` - Windows -```bash -Invoke-WebRequest -Uri "https://github.com/parseablehq/parseable/releases/download/v0.9.0/Parseable_x86_64-pc-windows-msvc.exe" -OutFile "C:\parseable.exe" -C:\parseable.exe local-store +```pwsh +powershell -c "irm https://raw.githubusercontent.com/parseablehq/parseable/main/scripts/download.ps1 | iex" ``` Once this runs successfully, you'll see dashboard at [http://localhost:8000 ↗︎](http://localhost:8000). You can login to the dashboard default credentials `admin`, `admin`. diff --git a/scripts/download.ps1 b/scripts/download.ps1 new file mode 100644 index 000000000..fcdf32814 --- /dev/null +++ b/scripts/download.ps1 @@ -0,0 +1,155 @@ +#!/usr/bin/env pwsh + +<# only supports windows, +# `SUPPORTED_OS` array contains the supported linux and darwin for filtering only +# `SUPPORTED_ARCH` array contains the supported architectures but only x86_64/amd64 are +# available for now. both amd64 and x86_64 are there cause windows does report either +# 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" +} + +# util functions +function Get-Env { + param([String] $Key) + + $RegisterKey = Get-Item -Path 'HKCU:' + $EnvRegisterKey = $RegisterKey.OpenSubKey('Environment') + $EnvRegisterKey.GetValue($Key, $null, [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames) +} + +# These three environment functions are roughly copied from https://github.com/prefix-dev/pixi/pull/692 +# They are used instead of `SetEnvironmentVariable` because of unwanted variable expansions. +function Publish-Env { + if (-not ("Win32.NativeMethods" -as [Type])) { + <# dllimport should not be needed but still#> + Add-Type -Namespace Win32 -Name NativeMethods -MemberDefinition @" +[DllImport("user32.dll", SetLastError = true, CharSet = CharSet.Auto)] +public static extern IntPtr SendMessageTimeout( + IntPtr hWnd, uint Msg, UIntPtr wParam, string lParam, + uint fuFlags, uint uTimeout, out UIntPtr lpdwResult); +"@ + } + $HWND_BROADCAST = [IntPtr] 0xffff + $WM_SETTINGCHANGE = 0x1a + $result = [UIntPtr]::Zero + [Win32.NativeMethods]::SendMessageTimeout($HWND_BROADCAST, + $WM_SETTINGCHANGE, + [UIntPtr]::Zero, + "Environment", + 2, + 5000, + [ref] $result + ) | Out-Null +} +function Write-Env { + param([String]$Key, [String]$Value) + + [Microsoft.Win32.RegistryKey]$RegisterKey = Get-Item -Path 'HKCU:' + + + [Microsoft.Win32.RegistryKey]$EnvRegisterKey = $RegisterKey.OpenSubKey('Environment', $true) + if ($null -eq $Value) { + $EnvRegisterKey.DeleteValue($Key) + } + else { + $RegistryValueKind = if ($Value.Contains('%')) { + [Microsoft.Win32.RegistryValueKind]::ExpandString + } + elseif ($EnvRegisterKey.GetValue($Key)) { + $EnvRegisterKey.GetValueKind($Key) + } + else { + [Microsoft.Win32.RegistryValueKind]::String + } + $EnvRegisterKey.SetValue($Key, $Value, $RegistryValueKind) + } + + Publish-Env +} + +function Get-Env { + param([String] $Key) + + [Microsoft.Win32.RegistryKey]$RegisterKey = Get-Item -Path 'HKCU:' + [Microsoft.Win32.RegistryKey]$EnvRegisterKey = $RegisterKey.OpenSubKey('Environment') + $EnvRegisterKey.GetValue($Key, $null, [Microsoft.Win32.RegistryValueOptions]::DoNotExpandEnvironmentNames) +} + +# 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]$INSTALLDIR = "${HOME}\.parseable\bin" +[String]$BIN = "${INSTALLDIR}\parseable.exe" + +function Install-Parseable { + Write-Output "OS: $OS" + Write-Output "CPU arch: $CPU_ARCH" + + # Check if the CPU architecture is supported + if ($SUPPORTED_ARCH -notcontains $CPU_ARCH) { + 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) { + Write-Error "Parseable is already installed. Run 'parseable --version' to check the version." + Write-Error "Consider removing the existing installation" + exit 1 + } + + Write-Output "No existing installation found" + + Write-Output "Fetching latest release..." + # 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 + } + } + + mkdir -Force $INSTALLDIR + + Write-Output "Downloading Parseable Server..." + # 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 ';' + if ($Path -notcontains $INSTALLDIR) { + $Path += $INSTALLDIR + Write-Env -Key 'Path' -Value ($Path -join ';') + $env:PATH = $Path; + } +} + +Install-Parseable + +Write-Output "Parseable was downloaded successfully! at $INSTALLDIR" +Write-Output "To get started, restart your terminal/editor, then type `"parseable`"`n" diff --git a/scripts/download.sh b/scripts/download.sh new file mode 100755 index 000000000..305080b52 --- /dev/null +++ b/scripts/download.sh @@ -0,0 +1,82 @@ +#!/bin/zsh + +# supported CPU architectures and operating systems +SUPPORTED_ARCH=("x86_64" "arm64") +SUPPORTED_OS=("linux" "darwin") +# Associate binaries with CPU architectures and operating systems +declare -A 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" +) +# Get the system's CPU architecture and operating system +CPU_ARCH=$(uname -m) +OS=$(uname -s | tr '[:upper:]' '[:lower:]') + +printf "Detected CPU architecture: %s\n" "$CPU_ARCH" +printf "Detected operating system: %s\n" "$OS" + +SHELL_NAME=$(basename $SHELL) +RC_FILE=".${SHELL_NAME}rc" +RC_FILE_PATH="${HOME}/${RC_FILE}" +INSTALL_DIR="${HOME}/.parseable" +BIN_DIR="${INSTALL_DIR}/bin" +BIN_NAME="${BIN_DIR}/parseable" + +# Check if the CPU architecture is supported +if ! echo "${SUPPORTED_ARCH[@]}" | grep -q "\\b${CPU_ARCH}\\b"; then + echo "Error: Unsupported CPU architecture (${CPU_ARCH})." + exit 1 +fi +# Check if the OS is supported +if ! echo "${SUPPORTED_OS[@]}" | grep -q "\\b${OS}\\b"; then + echo "Error: Unsupported operating system (${OS})." + exit 1 +fi +# Get the latest release information using GitHub API +release=$(curl -s "https://api.github.com/repos/parseablehq/parseable/releases/latest") + +printf "Fetching release information for parseable...\n" + +# Loop through binaries in the release and find the appropriate one +for arch_os in "${CPU_ARCH}-${OS}"; do + binary_name="${BINARIES[$arch_os]}" + download_url=$(echo "$release" | grep -o "\"browser_download_url\":\s*\"[^\"]*${binary_name}\"" | cut -d '"' -f 4) + if [ -n "$download_url" ]; then + break + fi +done + +printf "Checking for existing installation...\n" +if [[ -d ${INSTALL_DIR} ]]; then + printf "A Previous version of parseable already exists. Run 'parseable --version' to check the version." + printf "or consider removing that before Installing" + exit 1 + +else + printf "No Previous installation found\n" + printf "Installing parseable...\n" + mkdir -p ${BIN_DIR} +fi + + +# Download the binary using curl or wget +if command -v curl &>/dev/null; then + curl -L -o "${BIN_NAME}" "$download_url" 2&>> /dev/null +elif command -v wget &>/dev/null; then + wget -O "${BIN_NAME}" "$download_url" 2&>> /dev/null +else + echo "Error: Neither curl nor wget found. Please install either curl or wget." + exit 1 +fi + +printf "Parseable Server was successfully installed at: ${BIN_NAME}\n" + +chmod +x "${BIN_NAME}" + +printf "Adding parseable to the path\n" +PATH_STR="export PATH=${BIN_DIR}"':$PATH' +echo ${PATH_STR} >> ${RC_FILE_PATH} + +echo "parseable was added to the path. Please refresh the environment by sourcing the ${RC_PATH}"