#!/bin/sh # memspine installer: downloads a prebuilt release tarball from # memspine.com, verifies its sha256, and installs memspine-server + # memspine-admin into ~/.local/bin (override with MEMSPINE_INSTALL_DIR). # # Usage: # curl -fsSL https://memspine.com/install.sh | sh # # Environment: # MEMSPINE_INSTALL_DIR install destination (default: ~/.local/bin) # MEMSPINE_BASE_URL download base (default: https://memspine.com/dl) set -eu BASE="${MEMSPINE_BASE_URL:-https://memspine.com/dl}" DEST="${MEMSPINE_INSTALL_DIR:-$HOME/.local/bin}" DEST="${DEST%/}" say() { printf '%s\n' "$*"; } die() { printf 'install.sh: %s\n' "$*" >&2; exit 1; } os="$(uname -s)" arch="$(uname -m)" case "$os/$arch" in Linux/x86_64) target="linux-x86_64" ;; Darwin/arm64) target="macos-arm64" ;; *) die "no prebuilt binary for $os/$arch yet (have: Linux/x86_64, Darwin/arm64). See memspine.com for updates." ;; esac command -v curl >/dev/null 2>&1 || die "curl not found" if command -v sha256sum >/dev/null 2>&1; then sha() { sha256sum "$1" | cut -d' ' -f1; } elif command -v shasum >/dev/null 2>&1; then sha() { shasum -a 256 "$1" | cut -d' ' -f1; } else die "need sha256sum or shasum to verify the download" fi tmp="$(mktemp -d "${TMPDIR:-/tmp}/memspine-install.XXXXXX")" trap 'rm -rf "$tmp"' EXIT INT TERM tarball="memspine-$target.tar.gz" say "Downloading $tarball ..." curl -fsSL -o "$tmp/$tarball.sha256" "$BASE/$tarball.sha256" want="$(cut -d' ' -f1 < "$tmp/$tarball.sha256")" # The checksum rides along as a query string. The CDN caches tarballs # by URL, so without it a new release keeps serving the old tarball (or # an old 404) against the new checksum until the cache expires. curl -fsSL -o "$tmp/$tarball" "$BASE/$tarball?sha256=$want" got="$(sha "$tmp/$tarball")" [ "$want" = "$got" ] || die "checksum mismatch: expected $want, got $got" say "Checksum OK." mkdir -p "$DEST" tar -C "$tmp" -xzf "$tmp/$tarball" install -m 0755 "$tmp/memspine-server" "$tmp/memspine-admin" "$DEST/" # Print the destination the way people write it: ~/.local/bin. shown="$DEST" home="${HOME:-}" if [ -n "$home" ]; then case "$DEST" in "$home"/*) shown="~/${DEST#"$home"/}" ;; esac fi say "Installed memspine-server and memspine-admin to $shown" case ":$PATH:" in *":$DEST:"*) ;; *) say "Note: $shown is not on your PATH. Add: export PATH=\"$DEST:\$PATH\"" ;; esac say "" say "Start the server:" say " MEMSPINE_BIND=127.0.0.1:7777 $shown/memspine-server"