#!/bin/sh # m64 installer: curl -fsSL https://motif64.sh | sh # Every line lives inside main(), called last, so a truncated download runs nothing. set -eu main() { site="https://motif64.sh" s=$(uname -s) m=$(uname -m) case "$s/$m" in Linux/x86_64) ;; Linux/aarch64 | Linux/arm64) ;; Darwin/*) ;; *) echo "m64 install: unsupported platform $s/$m" >&2 exit 1 ;; esac if ! command -v uv >/dev/null 2>&1; then echo "m64 install: installing uv" >&2 curl -LsSf https://astral.sh/uv/install.sh | sh || true PATH="$HOME/.local/bin:$PATH" export PATH if ! command -v uv >/dev/null 2>&1; then echo "m64 install: could not install uv" >&2 exit 1 fi fi tmp=$(mktemp -d) trap 'rm -rf "$tmp"' EXIT trap 'exit 1' INT TERM HUP latest=$(curl -fsSL "$site/dist/latest.json" | tr -d '\n') version=$(printf '%s' "$latest" | sed -n 's/.*"version"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p') url=$(printf '%s' "$latest" | sed -n 's/.*"url"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p') want=$(printf '%s' "$latest" | sed -n 's/.*"sha256"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p') if [ -z "$version" ] || [ -z "$url" ] || [ -z "$want" ]; then echo "m64 install: cannot read $site/dist/latest.json" >&2 exit 1 fi bad="" case "$version" in [0-9]*) ;; *) bad=1 ;; esac case "$version" in *[!0-9A-Za-z.+-]*) bad=1 ;; esac name="m64-$version-py3-none-any.whl" [ "$url" = "$site/dist/$name" ] || bad=1 case "$want" in *[!0-9a-f]*) bad=1 ;; esac [ "${#want}" -eq 64 ] || bad=1 if [ -n "$bad" ]; then echo "m64 install: unexpected latest.json from $site" >&2 exit 1 fi wheel="$tmp/$name" curl -fsSL -o "$wheel" "$url" if [ "$s" = Darwin ]; then got=$(shasum -a 256 "$wheel" | cut -d ' ' -f 1) else got=$(sha256sum "$wheel" | cut -d ' ' -f 1) fi if [ "$got" != "$want" ]; then echo "m64 install: checksum mismatch for $url" >&2 exit 1 fi uv tool install --force "$wheel" bindir=$(uv tool dir --bin) m64bin="$bindir/m64" if [ "$site" != "https://motif64.sh" ]; then "$m64bin" config set site "$site" fi "$m64bin" doctor || echo "m64 install: m64 doctor reported problems (see above)" >&2 case ":$PATH:" in *":$bindir:"*) ;; *) echo "m64 install: add $bindir to your PATH (or run: uv tool update-shell)" ;; esac echo "Next: m64 find" echo "Home: $site" } main "$@"