#!/bin/sh # Free-LLM Router installer — https://free-llm.com/router # curl -fsSL https://free-llm.com/install.sh | sh # Installs into ~/.free-llm and adds a `free-llm` command to ~/.local/bin. # No sudo, no npm, no global changes. Node.js is not required: when it is missing # (or older than 18) a private copy is downloaded from nodejs.org into ~/.free-llm/node. # Uninstall: rm -rf ~/.free-llm ~/.local/bin/free-llm set -e URL="${FREE_LLM_TARBALL:-https://github.com/nejib1/Free-LLM/releases/latest/download/free-llm.tgz}" ROOT="${FREE_LLM_HOME:-$HOME/.free-llm}" APP="$ROOT/app" NODE_DIR="$ROOT/node" BIN="$HOME/.local/bin" say() { printf '%s\n' "$*"; } fail() { say ""; say "The installation stopped: $*"; say "Nothing was changed outside $ROOT. Help: https://github.com/nejib1/Free-LLM/issues"; exit 1; } fetch() { # fetch if command -v curl >/dev/null 2>&1; then curl -fsSL --retry 3 "$1" -o "$2" elif command -v wget >/dev/null 2>&1; then wget -q --tries=3 -O "$2" "$1" else fail "curl or wget is needed to download files."; fi } node_major() { "$1" -p 'process.versions.node.split(".")[0]' 2>/dev/null || echo 0; } sha256_of() { 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 } TMP=$(mktemp -d) trap 'rm -rf "$TMP"' EXIT mkdir -p "$ROOT" "$BIN" say "" say "⚡ Free-LLM Router — every free LLM API behind one local address." say " Installing for this user only: no sudo, nothing outside $ROOT and $BIN." say "" # ---- 1. Node.js: use the one that is installed, or fetch a private copy ---- NODE="" NODE_CMD="" # what the free-llm command calls: plain `node` when it is on PATH (version managers move it around) if command -v node >/dev/null 2>&1 && [ "$(node_major node)" -ge 18 ]; then NODE=$(command -v node); NODE_CMD="node" say "[1/3] Node.js found ($(node -v))" elif [ -x "$NODE_DIR/bin/node" ] && [ "$(node_major "$NODE_DIR/bin/node")" -ge 18 ]; then NODE="$NODE_DIR/bin/node" say "[1/3] Node.js: using the private copy already in $NODE_DIR" else OS=$(uname -s); CPU=$(uname -m); LINE="latest-v24.x" case "$OS" in Darwin) PLAT="darwin" ;; Linux) PLAT="linux" ;; *) fail "No ready-made Node.js for $OS. Install Node.js 18+ (https://nodejs.org) and run this installer again." ;; esac case "$CPU" in x86_64|amd64) ARCH="x64" ;; arm64|aarch64) ARCH="arm64" ;; armv7l) ARCH="armv7l"; LINE="latest-v22.x" ;; # Node 24 has no 32-bit ARM build *) fail "No ready-made Node.js for a $CPU processor. Install Node.js 18+ (https://nodejs.org) and run this installer again." ;; esac if [ "$PLAT" = "linux" ] && { [ -f /etc/alpine-release ] || (ldd --version 2>&1 | grep -qi musl); }; then [ "$ARCH" = "x64" ] || fail "On Alpine, install Node.js first: apk add nodejs then run this installer again." ARCH="x64-musl" fi EXT="tar.gz"; command -v xz >/dev/null 2>&1 && EXT="tar.xz" say "[1/3] Node.js is not installed: downloading a private copy from nodejs.org (30–55 MB, one time)…" BASE="https://nodejs.org/dist/$LINE" fetch "$BASE/SHASUMS256.txt" "$TMP/sums" || fail "Could not reach nodejs.org. Check your connection and run the installer again." FILE=$(grep -E " node-v[0-9.]+-$PLAT-$ARCH\.$EXT\$" "$TMP/sums" | head -n 1 | awk '{print $2}') WANT=$(grep -E " node-v[0-9.]+-$PLAT-$ARCH\.$EXT\$" "$TMP/sums" | head -n 1 | awk '{print $1}') [ -n "$FILE" ] || fail "No Node.js build for $PLAT-$ARCH. Install Node.js 18+ (https://nodejs.org) and run this installer again." fetch "$BASE/$FILE" "$TMP/$FILE" || fail "The Node.js download failed. Run the installer again." GOT=$(sha256_of "$TMP/$FILE") if [ -n "$GOT" ] && [ "$GOT" != "$WANT" ]; then fail "The Node.js download is damaged (checksum mismatch). Run the installer again."; fi # Only the node binary is needed. DIRNAME=${FILE%.$EXT} mkdir -p "$TMP/node" if [ "$EXT" = "tar.xz" ]; then xz -dc "$TMP/$FILE" | tar -xf - -C "$TMP/node" "$DIRNAME/bin/node" else tar -xzf "$TMP/$FILE" -C "$TMP/node" "$DIRNAME/bin/node"; fi mkdir -p "$NODE_DIR/bin" mv -f "$TMP/node/$DIRNAME/bin/node" "$NODE_DIR/bin/node" chmod +x "$NODE_DIR/bin/node" NODE="$NODE_DIR/bin/node" [ "$(node_major "$NODE")" -ge 18 ] || fail "The downloaded Node.js does not start on this system. Install Node.js 18+ (https://nodejs.org) and run this installer again." say " Node.js $("$NODE" -v) ready in $NODE_DIR (private to the router)" fi [ -n "$NODE_CMD" ] || NODE_CMD="\"$NODE\"" # ---- 2. The router itself ---- say "[2/3] Downloading Free-LLM Router…" fetch "$URL" "$TMP/r.tgz" || fail "Could not download the router from GitHub. Check your connection and run the installer again." tar -xzf "$TMP/r.tgz" -C "$TMP" || fail "Could not unpack the download." [ -d "$TMP/package" ] || fail "The download does not look like the router archive." WAS_RUNNING=0 if [ -f "$APP/router/bin/free-llm.js" ] && "$NODE" "$APP/router/bin/free-llm.js" status 2>/dev/null | grep -q "running" && ! "$NODE" "$APP/router/bin/free-llm.js" status 2>/dev/null | grep -q "not running"; then [ -f "$ROOT/router.pid" ] && WAS_RUNNING=1 fi rm -rf "$APP" mv "$TMP/package" "$APP" echo installer > "$APP/.install-method" # ---- 3. The `free-llm` command ---- say "[3/3] Adding the free-llm command…" cat > "$BIN/free-llm" <> "$rc" done say " (added ~/.local/bin to your PATH — open a new terminal, or run: export PATH=\"\$HOME/.local/bin:\$PATH\")" ;; esac say "" [ -z "$FREE_LLM_NO_START" ] || exit 0 if [ "$WAS_RUNNING" = 1 ]; then say "A router was running in the background: restarting it on the new version…" "$BIN/free-llm" stop >/dev/null 2>&1 || true exec "$BIN/free-llm" start --daemon fi if [ -t 1 ] && [ -r /dev/tty ]; then exec "$BIN/free-llm"