#!/usr/bin/env bash # RasterizedDB: download the latest server release for this Linux machine, # check it against the release's SHA256SUMS, and install the binary. # # Every setting below can be overridden from the environment, for example: # RDB_INSTALL_DIR=/usr/local/bin ./setup.sh set -euo pipefail RDB_INSTALL_DIR="${RDB_INSTALL_DIR:-$HOME/.local/bin}" # where the binary goes RDB_VERSION="${RDB_VERSION:-latest}" # e.g. 1.1.0, or latest RDB_FLAVOR="${RDB_FLAVOR:-auto}" # auto, glibc or musl RDB_ARCHIVE="${RDB_ARCHIVE:-}" # a release archive already on disk: skips the download RDB_REPO="${RDB_REPO:-milen-denev/rasterizeddb}" die() { echo "error: $*" >&2; exit 1; } [ "$(uname -s)" = "Linux" ] || die "release binaries exist for Linux and Windows only; on $(uname -s), build the server from source" case "$(uname -m)" in x86_64 | amd64) arch=x86_64 ;; aarch64 | arm64) arch=arm64 ;; *) die "no release binary for $(uname -m): there are x86_64 and arm64 builds" ;; esac if [ "$arch" = x86_64 ] && ! grep -qw avx2 /proc/cpuinfo; then die "this CPU has no AVX2; the x86_64 release binaries need it (x86-64-v3)" fi # The glibc build needs glibc 2.39 or newer; the musl build is static and runs anywhere. if [ "$RDB_FLAVOR" = auto ]; then glibc="$(getconf GNU_LIBC_VERSION 2>/dev/null | awk '{print $2}')" || glibc="" if [ -n "$glibc" ] && [ "$(printf '%s\n2.39\n' "$glibc" | sort -V | head -n1)" = "2.39" ]; then RDB_FLAVOR=glibc else RDB_FLAVOR=musl fi fi case "$RDB_FLAVOR" in glibc) platform="linux-$arch" ;; musl) platform="linux-$arch-musl" ;; *) die "RDB_FLAVOR must be auto, glibc or musl" ;; esac fetch() { # fetch if command -v curl >/dev/null 2>&1; then curl -fsSL --retry 3 -o "$2" "$1" elif command -v wget >/dev/null 2>&1; then wget -q -O "$2" "$1" else die "curl or wget is needed to download" fi } work="$(mktemp -d)" trap 'rm -rf "$work"' EXIT if [ -n "$RDB_ARCHIVE" ]; then [ -f "$RDB_ARCHIVE" ] || die "RDB_ARCHIVE=$RDB_ARCHIVE is not a file" archive="$RDB_ARCHIVE" echo "Using $archive (no download, no checksum check)" else if [ "$RDB_VERSION" = latest ]; then # The newest release whose tag is v..; other tags # (client-v…, server-v…) and pre-releases are skipped. fetch "https://api.github.com/repos/$RDB_REPO/releases?per_page=30" "$work/releases.json" RDB_VERSION="$(grep -o '"tag_name": *"v[0-9][0-9]*\.[0-9][0-9]*\.[0-9][0-9]*"' "$work/releases.json" \ | head -n1 | sed 's/.*"v\([^"]*\)"/\1/')" [ -n "$RDB_VERSION" ] || die "could not find a release; set RDB_VERSION, or RDB_ARCHIVE to a downloaded archive" fi RDB_VERSION="${RDB_VERSION#v}" name="rasterizeddb-server-$RDB_VERSION-$platform.tar.gz" base="https://github.com/$RDB_REPO/releases/download/v$RDB_VERSION" echo "Downloading $name" fetch "$base/$name" "$work/$name" fetch "$base/SHA256SUMS" "$work/SHA256SUMS" (cd "$work" && grep " $name\$" SHA256SUMS | sha256sum -c -) || die "checksum mismatch for $name" archive="$work/$name" fi tar -xzf "$archive" -C "$work" bin="$(find "$work" -type f -name rasterizeddb -perm -u+x | head -n1)" [ -n "$bin" ] || die "no rasterizeddb binary in $archive" mkdir -p "$RDB_INSTALL_DIR" install -m 0755 "$bin" "$RDB_INSTALL_DIR/rasterizeddb" echo "$RDB_INSTALL_DIR/rasterizeddb" --version echo "Installed $RDB_INSTALL_DIR/rasterizeddb" case ":$PATH:" in *":$RDB_INSTALL_DIR:"*) ;; *) echo "Add it to PATH: export PATH=\"$RDB_INSTALL_DIR:\$PATH\"" ;; esac echo "Next: rasterizeddb --help lists every option; the local-dev script starts a server to try."