#!/bin/sh set -eu BASE_URL="${LUMA_BASE_URL:-https://get.lumadb.dev}" PUBLIC_KEY="x8IOU3m9nhNvrQwKgLNcvRQD6D/5IoQvUBewuFSIPcU=" say() { printf '%s\n' "$*"; } fail() { printf 'luma install: %s\n' "$*" >&2; exit 1; } command -v curl >/dev/null 2>&1 || fail "curl is required" command -v tar >/dev/null 2>&1 || fail "tar is required" case "$(uname -s)" in Linux) ;; *) fail "only Linux is supported for now (found $(uname -s))" ;; esac case "$(uname -m)" in x86_64 | amd64) arch="x86_64" ;; *) fail "only x86_64 is supported for now (found $(uname -m)); build from source: https://lumadb.dev" ;; esac libc="musl" if command -v ldd >/dev/null 2>&1; then ldd_out="$(ldd --version 2>&1 || true)" case "$ldd_out" in *"GNU libc"* | *"GNU C Library"* | *"GLIBC"*) libc="gnu" ;; esac fi target="$arch-unknown-linux-$libc" channel="${LUMA_CHANNEL:-}" version="${LUMA_VERSION:-}" version="${version#v}" tmp="$(mktemp -d)" trap 'rm -rf "$tmp"' EXIT INT TERM resolve_latest() { ch="$1" out="$(curl -sS -o /dev/null -w '%{http_code} %{redirect_url}' "$BASE_URL/latest/$target?channel=$ch" || true)" code="${out%% *}" loc="${out#* }" if [ "$code" = "302" ] && [ -n "$loc" ]; then printf '%s' "$loc" return 0 fi return 1 } if [ -n "$version" ]; then asset="luma-v$version-$target.tar.gz" url="$BASE_URL/v$version/$asset" else if [ -n "$channel" ]; then url="$(resolve_latest "$channel")" || fail "no release found on channel $channel" elif url="$(resolve_latest stable)"; then : elif url="$(resolve_latest alpha)"; then say "note: no stable release yet, installing the newest pre-release" else fail "no release is published yet" fi asset="${url##*/}" version="${asset#luma-v}" version="${version%-$target.tar.gz}" fi say "Installing luma $version ($target)" curl -fsSL -o "$tmp/$asset" "$url" || fail "download failed: $url" curl -fsSL -o "$tmp/$asset.sha256" "$url.sha256" || fail "checksum download failed" expected="$(cut -d ' ' -f 1 "$tmp/$asset.sha256")" if command -v sha256sum >/dev/null 2>&1; then actual="$(sha256sum "$tmp/$asset" | cut -d ' ' -f 1)" elif command -v shasum >/dev/null 2>&1; then actual="$(shasum -a 256 "$tmp/$asset" | cut -d ' ' -f 1)" else fail "sha256sum or shasum is required" fi [ "$expected" = "$actual" ] || fail "checksum mismatch (expected $expected, got $actual)" say "checksum ok" verify_signature() { curl -fsSL -o "$tmp/$asset.sig" "$url.sig" || fail "signature download failed" printf '%s' "$PUBLIC_KEY" | base64 -d >"$tmp/key.raw" 2>/dev/null || fail "cannot decode the embedded public key" { printf '\060\052\060\005\006\003\053\145\160\003\041\000' cat "$tmp/key.raw" } >"$tmp/key.der" base64 -d <"$tmp/$asset.sig" >"$tmp/sig.raw" 2>/dev/null || fail "signature is not valid base64" openssl pkeyutl -verify -pubin -inkey "$tmp/key.der" -keyform DER -rawin \ -in "$tmp/$asset" -sigfile "$tmp/sig.raw" >/dev/null 2>&1 \ || fail "signature verification FAILED, refusing to install" say "signature ok" } if command -v openssl >/dev/null 2>&1 && command -v base64 >/dev/null 2>&1 \ && openssl pkeyutl -help 2>&1 | grep -q rawin; then verify_signature else say "note: openssl with ed25519 support not found, skipping signature check" fi tar -xzf "$tmp/$asset" -C "$tmp" bin="$tmp/luma-v$version-$target/luma" [ -f "$bin" ] || fail "archive does not contain luma" dir="${LUMA_INSTALL_DIR:-}" if [ -z "$dir" ]; then if [ -w /usr/local/bin ]; then dir="/usr/local/bin" else dir="$HOME/.local/bin" fi fi mkdir -p "$dir" install -m 0755 "$bin" "$dir/luma" 2>/dev/null || { cp "$bin" "$dir/luma" && chmod 0755 "$dir/luma"; } say "Installed $dir/luma" case ":$PATH:" in *":$dir:"*) ;; *) say "note: $dir is not on your PATH, add it to run luma directly" ;; esac say "" say "Next steps:" say " luma --version" say " luma upgrade update later" say " Quick start: https://lumadb.dev"