|
| 1 | +#!/usr/bin/env sh |
| 2 | +# avm installer — downloads the avm manager + the `animus` shim and puts the |
| 3 | +# shim first on your PATH, so `animus` in any project uses that project's pinned |
| 4 | +# kernel version. Re-runnable (upgrades in place). |
| 5 | +# |
| 6 | +# curl -fsSL https://raw.githubusercontent.com/launchapp-dev/avm/main/install.sh | sh |
| 7 | +# |
| 8 | +# Honors: |
| 9 | +# AVM_VERSION release tag to install (default: latest) |
| 10 | +# AVM_HOME install root (default: ~/.avm) |
| 11 | +# AVM_NO_PROFILE=1 skip editing the shell profile (just print the PATH line) |
| 12 | +set -eu |
| 13 | + |
| 14 | +REPO="launchapp-dev/avm" |
| 15 | +AVM_HOME="${AVM_HOME:-$HOME/.avm}" |
| 16 | +BIN_DIR="$AVM_HOME/bin" |
| 17 | +SHIM_DIR="$AVM_HOME/shims" |
| 18 | + |
| 19 | +say() { printf '%s\n' "$*"; } |
| 20 | +err() { printf 'avm-install: %s\n' "$*" >&2; exit 1; } |
| 21 | + |
| 22 | +# --- detect target triple ------------------------------------------------- |
| 23 | +os="$(uname -s)" |
| 24 | +arch="$(uname -m)" |
| 25 | +case "$os" in |
| 26 | + Darwin) plat="apple-darwin" ;; |
| 27 | + Linux) plat="unknown-linux-gnu" ;; |
| 28 | + *) err "unsupported OS: $os" ;; |
| 29 | +esac |
| 30 | +case "$arch" in |
| 31 | + x86_64|amd64) cpu="x86_64" ;; |
| 32 | + arm64|aarch64) cpu="aarch64" ;; |
| 33 | + *) err "unsupported arch: $arch" ;; |
| 34 | +esac |
| 35 | +target="${cpu}-${plat}" |
| 36 | + |
| 37 | +# --- resolve version ------------------------------------------------------ |
| 38 | +version="${AVM_VERSION:-}" |
| 39 | +if [ -z "$version" ]; then |
| 40 | + version="$(curl -fsSL "https://api.github.com/repos/${REPO}/releases/latest" \ |
| 41 | + | sed -n 's/.*"tag_name"[[:space:]]*:[[:space:]]*"\([^"]*\)".*/\1/p' | head -1)" |
| 42 | + [ -n "$version" ] || err "could not resolve the latest avm release; set AVM_VERSION=vX.Y.Z" |
| 43 | +fi |
| 44 | + |
| 45 | +archive="avm-${target}.tar.gz" |
| 46 | +url="https://github.com/${REPO}/releases/download/${version}/${archive}" |
| 47 | +say "Installing avm ${version} (${target})…" |
| 48 | + |
| 49 | +tmp="$(mktemp -d)" |
| 50 | +trap 'rm -rf "$tmp"' EXIT |
| 51 | +curl -fsSL -o "$tmp/$archive" "$url" || err "download failed: $url" |
| 52 | +# Verify checksum when the sidecar is present. |
| 53 | +if curl -fsSL -o "$tmp/$archive.sha256" "${url}.sha256" 2>/dev/null; then |
| 54 | + ( cd "$tmp" && sed "s#\$# *${archive}#" "$archive.sha256" >/dev/null 2>&1 || true ) |
| 55 | + if command -v shasum >/dev/null 2>&1; then |
| 56 | + want="$(awk '{print $1}' "$tmp/$archive.sha256")" |
| 57 | + got="$(shasum -a 256 "$tmp/$archive" | awk '{print $1}')" |
| 58 | + [ "$want" = "$got" ] || err "checksum mismatch for $archive (want $want, got $got)" |
| 59 | + fi |
| 60 | +fi |
| 61 | + |
| 62 | +mkdir -p "$BIN_DIR" "$SHIM_DIR" |
| 63 | +tar -xzf "$tmp/$archive" -C "$tmp" |
| 64 | +install -m 0755 "$tmp/avm" "$BIN_DIR/avm" |
| 65 | +# The `animus` shim lives in the shims dir (first on PATH); `avm` lives in bin. |
| 66 | +install -m 0755 "$tmp/animus" "$SHIM_DIR/animus" |
| 67 | +say "Installed: $BIN_DIR/avm + $SHIM_DIR/animus" |
| 68 | + |
| 69 | +# --- PATH wiring ---------------------------------------------------------- |
| 70 | +path_line='export PATH="$HOME/.avm/shims:$HOME/.avm/bin:$PATH"' |
| 71 | +profile="" |
| 72 | +case "${SHELL:-}" in |
| 73 | + */zsh) profile="$HOME/.zshrc" ;; |
| 74 | + */bash) [ -f "$HOME/.bashrc" ] && profile="$HOME/.bashrc" || profile="$HOME/.bash_profile" ;; |
| 75 | + *) profile="$HOME/.profile" ;; |
| 76 | +esac |
| 77 | +if [ "${AVM_NO_PROFILE:-0}" != "1" ] && [ -n "$profile" ]; then |
| 78 | + if [ ! -f "$profile" ] || ! grep -q '.avm/shims' "$profile" 2>/dev/null; then |
| 79 | + printf '\n# avm — Animus Version Manager (shim first on PATH)\n%s\n' "$path_line" >> "$profile" |
| 80 | + say "Added avm to PATH in $profile" |
| 81 | + fi |
| 82 | +fi |
| 83 | + |
| 84 | +say "" |
| 85 | +say "avm ${version} installed. Open a new shell (or run: ${path_line#export }) then:" |
| 86 | +say " avm install <version> # e.g. avm install v0.6.9" |
| 87 | +say " avm use --global <version> # machine default" |
| 88 | +say " avm use <version> # pin THIS project (writes ./.animus-version)" |
0 commit comments