#!/bin/sh # ArcFlare CLI installer # curl -fsSL https://arcflare.net/install.sh | sh # curl -fsSL https://arcflare.net/install.sh | sh -s -- --dry-run (show what it would do) # curl -fsSL https://arcflare.net/install.sh | sh -s -- --no-engine (skip llama.cpp) # curl -fsSL https://arcflare.net/install.sh | sh -s -- --model (also download a model that fits this machine) # # Needs no root. If Node.js 18+ is missing, a private copy of the current # Node LTS goes into ~/.arcflare/node (checked against nodejs.org's SHA256 # list), and ArcFlare is installed with npm into a folder you own. Then # llama.cpp, the engine that runs models, is fetched for this machine with # `arcflare engine install` (checked against the SHA-256 GitHub publishes for # the download), unless you already have one. set -e DRY=0 NO_ENGINE=0 WITH_MODEL=0 for a in "$@"; do case "$a" in --dry-run|-n) DRY=1 ;; --no-engine) NO_ENGINE=1 ;; --model) WITH_MODEL=1 ;; esac done AF_HOME="${ARCFLARE_HOME:-$HOME/.arcflare}" NODE_DIR="$AF_HOME/node" NPM_PREFIX="$AF_HOME/npm-global" NODE_LINE="latest-v22.x" # GitHub's tarball of main: npm installs it without git (fresh Ubuntu, Fedora and Arch have none). PKG="https://codeload.github.com/Hakeperty/ArcFlare-Code/tar.gz/refs/heads/main" say() { printf '%s\n' "$*"; } run() { if [ "$DRY" = 1 ]; then say " [dry-run] $*"; else "$@"; fi } die() { printf 'ArcFlare install: %s\n' "$*" >&2; exit 1; } fetch() { # fetch URL FILE if command -v curl >/dev/null 2>&1; then curl -fsSL "$1" -o "$2" elif command -v wget >/dev/null 2>&1; then wget -q "$1" -O "$2" else die "needs curl or wget to download Node.js" fi } sha256() { if command -v sha256sum >/dev/null 2>&1; then sha256sum "$1" | cut -d' ' -f1 elif command -v shasum >/dev/null 2>&1; then shasum -a 256 "$1" | cut -d' ' -f1 else echo "" fi } node_ok() { # is there a node 18+ with npm on PATH? command -v node >/dev/null 2>&1 || return 1 command -v npm >/dev/null 2>&1 || return 1 major=$(node -p 'process.versions.node.split(".")[0]' 2>/dev/null || echo 0) [ "$major" -ge 18 ] 2>/dev/null } install_node() { case "$(uname -s)" in Darwin) os=darwin ;; Linux) os=linux ;; *) die "unsupported system $(uname -s); install Node.js 18+ from https://nodejs.org and re-run" ;; esac case "$(uname -m)" in x86_64|amd64) arch=x64 ;; arm64|aarch64) arch=arm64 ;; *) die "unsupported CPU $(uname -m); install Node.js 18+ from https://nodejs.org and re-run" ;; esac if [ "$os" = linux ] && ldd --version 2>&1 | grep -qi musl; then die "this Linux uses musl (e.g. Alpine); install Node.js with your package manager (apk add nodejs npm) and re-run" fi say "Node.js 18+ not found: installing a private Node LTS into $NODE_DIR (no root needed)..." base="https://nodejs.org/dist/$NODE_LINE" if [ "$DRY" = 1 ]; then say " [dry-run] download $base/SHASUMS256.txt and node--$os-$arch.tar.gz, verify SHA256, unpack to $NODE_DIR" return 0 fi tmp=$(mktemp -d 2>/dev/null || echo "/tmp/arcflare-node-$$") mkdir -p "$tmp" fetch "$base/SHASUMS256.txt" "$tmp/SHASUMS256.txt" file=$(grep " node-v[0-9.]*-$os-$arch.tar.gz\$" "$tmp/SHASUMS256.txt" | awk '{print $2}' | head -n 1) want=$(grep " node-v[0-9.]*-$os-$arch.tar.gz\$" "$tmp/SHASUMS256.txt" | awk '{print $1}' | head -n 1) [ -n "$file" ] || die "couldn't find a Node.js build for $os-$arch" fetch "$base/$file" "$tmp/$file" got=$(sha256 "$tmp/$file") if [ -z "$got" ]; then say " (no sha256 tool found; skipping the checksum)" elif [ "$got" != "$want" ]; then rm -rf "$tmp" die "checksum mismatch for $file: download corrupted or tampered with" fi rm -rf "$NODE_DIR" mkdir -p "$NODE_DIR" tar -xzf "$tmp/$file" -C "$NODE_DIR" --strip-components=1 rm -rf "$tmp" say " Node $("$NODE_DIR/bin/node" -v) installed" } # Add a line to the shell profile once, and say so. ADDED_PATH=0 add_path() { # add_path DIR dir="$1" shell_name=$(basename "${SHELL:-sh}") case "$shell_name" in zsh) profile="$HOME/.zshrc"; line="export PATH=\"$dir:\$PATH\"" ;; bash) if [ "$(uname -s)" = Darwin ]; then profile="$HOME/.bash_profile"; else profile="$HOME/.bashrc"; fi line="export PATH=\"$dir:\$PATH\"" ;; fish) profile="$HOME/.config/fish/config.fish"; line="fish_add_path \"$dir\"" ;; *) profile="$HOME/.profile"; line="export PATH=\"$dir:\$PATH\"" ;; esac if [ -f "$profile" ] && grep -F "$dir" "$profile" >/dev/null 2>&1; then return 0 fi ADDED_PATH=1 if [ "$DRY" = 1 ]; then say " [dry-run] add to $profile: $line" return 0 fi mkdir -p "$(dirname "$profile")" printf '\n# ArcFlare\n%s\n' "$line" >> "$profile" say " added $dir to your PATH in $profile" } if node_ok; then NODE_BIN="" say "Using Node $(node -v)." else install_node NODE_BIN="$NODE_DIR/bin" PATH="$NODE_BIN:$PATH" export PATH add_path "$NODE_BIN" fi # npm -g needs a folder we can write to. A private Node owns its own prefix; # a system Node often doesn't (it would need sudo), so use one under ~/.arcflare. PREFIX_ARGS="" if [ -n "$NODE_BIN" ]; then BIN_DIR="$NODE_BIN" else gprefix=$(npm prefix -g 2>/dev/null || echo "") if [ -n "$gprefix" ] && [ -w "$gprefix" ] && { [ ! -d "$gprefix/lib/node_modules" ] || [ -w "$gprefix/lib/node_modules" ]; }; then BIN_DIR="$gprefix/bin" else PREFIX_ARGS="--prefix $NPM_PREFIX" BIN_DIR="$NPM_PREFIX/bin" run mkdir -p "$NPM_PREFIX" fi fi say "Installing the ArcFlare CLI..." # shellcheck disable=SC2086 run npm install -g $PREFIX_ARGS "$PKG" if [ -n "$PREFIX_ARGS" ]; then add_path "$BIN_DIR" fi # llama.cpp: the engine. Without it the CLI installs fine but can't run a model. # A failure here (offline, GitHub rate limit) must not undo the install above. ENGINE=ok if [ "$NO_ENGINE" = 1 ]; then ENGINE=skipped elif [ "$DRY" = 1 ]; then say "" say "Getting llama.cpp (the engine that runs models)..." say " [dry-run] arcflare engine install --if-missing" else say "" say "Getting llama.cpp (the engine that runs models)..." AF="$BIN_DIR/arcflare" [ -x "$AF" ] || AF=$(command -v arcflare 2>/dev/null || echo "") if [ -z "$AF" ] || ! "$AF" engine install --if-missing; then ENGINE=failed fi fi # Opt-in: one model chosen for this machine's free GPU memory. It is a large # download, so it only happens when asked for. Failure doesn't undo the install. MODEL=skipped if [ "$WITH_MODEL" = 1 ]; then say "" say "Picking a model that fits this machine..." if [ "$DRY" = 1 ]; then say " [dry-run] arcflare shop best" MODEL=ok else AF="$BIN_DIR/arcflare" [ -x "$AF" ] || AF=$(command -v arcflare 2>/dev/null || echo "") if [ -n "$AF" ] && "$AF" shop best; then MODEL=ok; else MODEL=failed; fi fi fi say "" say "ArcFlare installed." [ "$MODEL" = failed ] && say "The model didn't download (the CLI itself is fine). Try again with: arcflare shop best" case "$ENGINE" in skipped) say "llama.cpp was skipped (--no-engine). Get it any time with: arcflare engine install" ;; failed) say "llama.cpp didn't download (the CLI itself is fine). Try again with: arcflare engine install" ;; esac if [ "$ADDED_PATH" = 1 ]; then say "Open a new terminal (or run: export PATH=\"$BIN_DIR:\$PATH\") so 'arcflare' is found." fi say "Next:" [ "$MODEL" = ok ] || say " arcflare shop best download a model that fits your GPU (or: arcflare shop, to choose)" say " arcflare doctor check your GPU and engine"