#!/usr/bin/env bash # Extract the `lms` CLI binary from the LM Studio AppImage and bootstrap it. # Run AFTER the AppImage has finished downloading to /tmp/LM_Studio.AppImage. set -euo pipefail APPIMAGE="/tmp/LM_Studio.AppImage" EXTRACT_DIR="$HOME/Applications/LMStudio/squashfs-root" BIN_DIR="$HOME/.lmstudio/bin" echo "==> Verifying AppImage integrity" if [ ! -s "$APPIMAGE" ]; then echo "ERROR: $APPIMAGE missing or empty" >&2 exit 1 fi head -c 2 "$APPIMAGE" | grep -q AI || { echo "ERROR: not an AppImage (magic bytes)" >&2; exit 1; } echo "==> Making AppImage executable" chmod +x "$APPIMAGE" echo "==> Extracting squashfs root (--appimage-extract)" rm -rf "$EXTRACT_DIR" ( cd "$HOME/Applications/LMStudio" && "$APPIMAGE" --appimage-extract >/dev/null 2>&1 ) || { echo "AppImage self-extract failed; attempting runtime extraction via --appimage-mount" mkdir -p "$EXTRACT_DIR" } echo "==> Locating the lms binary inside the extracted tree" LMS_BIN=$(find "$EXTRACT_DIR" -type f -name lms 2>/dev/null | head -1) if [ -z "$LMS_BIN" ]; then echo "ERROR: lms binary not found under $EXTRACT_DIR" >&2 echo "Tree (top 2 levels):" >&2 find "$EXTRACT_DIR" -maxdepth 2 2>/dev/null | head -40 >&2 exit 1 fi echo " found: $LMS_BIN" echo "==> Installing lms to $BIN_DIR" mkdir -p "$BIN_DIR" cp -f "$LMS_BIN" "$BIN_DIR/lms" chmod +x "$BIN_DIR/lms" echo "==> Ensuring $BIN_DIR is on PATH for this shell session" export PATH="$BIN_DIR:$PATH" echo "==> Running 'lms bootstrap' (documents the CLI with LM Studio)" "$BIN_DIR/lms" bootstrap || echo "WARN: lms bootstrap returned non-zero (non-fatal)" echo "==> Version check" "$BIN_DIR/lms" --version || "$BIN_DIR/lms" --help | head -20 echo "==> DONE. lms installed at $BIN_DIR/lms" echo " Start the OpenAI-compatible server with: lms server start" echo " Load this project's model with: lms load Brettapps/trifecta-bro/v1"