#!/usr/bin/env bash # Tuffy installer for macOS and Linux. # # From a checkout: ./scripts/install.sh # From anywhere: curl -fsSL https://raw.githubusercontent.com/CodebyKumar/tuffy-cli/main/scripts/install.sh | bash # # It installs the dependencies, asks how Tuffy should get its language model (download a local # one, use a Groq API key, both, or neither), and creates a `tuffy` command. Safe to re-run. # On a Jetson Orin use scripts/setup_jetson.sh instead (it builds the CUDA stack). # # Options: # --model local|api|both|none skip the question # --api-key KEY Groq API key (with --model api|both) # --voice | --no-voice install voice mode (Whisper + Piper) or not # --dir PATH where to put the code when cloning (default ~/.local/share/tuffy) # --no-launcher do not create the `tuffy` command # --no-path do not edit shell startup files # -y, --yes accept defaults, never prompt # -h, --help # Environment: TUFFY_HOME (data folder, default ~/.tuffy), TUFFY_BIN_DIR (default ~/.local/bin), # TUFFY_REPO (git URL to clone). set -euo pipefail REPO_URL="${TUFFY_REPO:-https://github.com/CodebyKumar/tuffy-cli.git}" TUFFY_HOME="${TUFFY_HOME:-$HOME/.tuffy}" BIN_DIR="${TUFFY_BIN_DIR:-$HOME/.local/bin}" CLONE_DIR="$HOME/.local/share/tuffy" MODEL_CHOICE="" API_KEY="${GROQ_API_KEY:-}" WANT_VOICE="" MAKE_LAUNCHER=1 EDIT_PATH=1 ASSUME_YES=0 # Local model files (Qwen3-VL 2B, Q4_K_M plus its vision projector), paths as local.py expects. HF_BASE="https://huggingface.co/Qwen/Qwen3-VL-2B-Instruct-GGUF/resolve/main" WEIGHTS=( "qwen3vl-2b-instruct-q4km/Qwen3VL-2B-Instruct-Q4_K_M.gguf|Qwen3VL-2B-Instruct-Q4_K_M.gguf|1100000000" "qwen3vl-2b-instruct-q80/mmproj-Qwen3VL-2B-Instruct-Q8_0.gguf|mmproj-Qwen3VL-2B-Instruct-Q8_0.gguf|440000000" ) if [[ -t 1 ]]; then B=$'\033[1m'; D=$'\033[2m'; G=$'\033[32m'; Y=$'\033[33m'; R=$'\033[31m'; Z=$'\033[0m'; else B=""; D=""; G=""; Y=""; R=""; Z=""; fi step() { printf '\n%s==>%s %s%s%s\n' "$G" "$Z" "$B" "$*" "$Z"; } info() { printf ' %s\n' "$*"; } warn() { printf '%s warning:%s %s\n' "$Y" "$Z" "$*" >&2; } die() { printf '%serror:%s %s\n' "$R" "$Z" "$*" >&2; exit 1; } usage() { sed -n '2,23p' "$0" | sed 's/^# \{0,1\}//'; exit 0; } while [[ $# -gt 0 ]]; do case "$1" in --model) MODEL_CHOICE="${2:-}"; shift 2 ;; --api-key) API_KEY="${2:-}"; shift 2 ;; --voice) WANT_VOICE=1; shift ;; --no-voice) WANT_VOICE=0; shift ;; --dir) CLONE_DIR="${2:-}"; shift 2 ;; --no-launcher) MAKE_LAUNCHER=0; shift ;; --no-path) EDIT_PATH=0; shift ;; -y|--yes) ASSUME_YES=1; shift ;; -h|--help) usage ;; *) die "unknown option: $1 (see --help)" ;; esac done case "$MODEL_CHOICE" in ""|local|api|both|none) ;; *) die "--model must be local, api, both or none" ;; esac # ask "question" default -> REPLY. Reads from the terminal even when the script itself is piped. ask() { REPLY="$2" [[ $ASSUME_YES -eq 1 ]] && return 0 if [[ -t 0 ]]; then read -r -p "$1" REPLY || REPLY="$2" elif [[ -r /dev/tty ]]; then read -r -p "$1" REPLY REPLY (not echoed) ask_secret() { REPLY="" [[ $ASSUME_YES -eq 1 ]] && return 0 if [[ -t 0 ]]; then read -r -s -p "$1" REPLY || true; echo elif [[ -r /dev/tty ]]; then read -r -s -p "$1" REPLY /dev/null 2>&1 || die "curl is required" if ! command -v cc >/dev/null 2>&1 && ! command -v gcc >/dev/null 2>&1 && ! command -v clang >/dev/null 2>&1; then if [[ "$OS" == "Darwin" ]]; then die "a C compiler is needed to build llama-cpp-python. Run: xcode-select --install" else die "a C compiler is needed to build llama-cpp-python. Debian/Ubuntu: sudo apt install build-essential cmake" fi fi # ---------------------------------------------------------------- 2. code SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" 2>/dev/null && pwd || true)" if [[ -n "$SCRIPT_DIR" && -f "$SCRIPT_DIR/../main.py" && -d "$SCRIPT_DIR/../src" ]]; then APP_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" step "Using the checkout at $APP_DIR" else step "Getting Tuffy" command -v git >/dev/null 2>&1 || die "git is required to download Tuffy" APP_DIR="$CLONE_DIR" if [[ -d "$APP_DIR/.git" ]]; then info "updating $APP_DIR" git -C "$APP_DIR" pull --ff-only else info "cloning into $APP_DIR" mkdir -p "$(dirname "$APP_DIR")" git clone --depth 1 "$REPO_URL" "$APP_DIR" fi fi cd "$APP_DIR" # ---------------------------------------------------------------- 3. uv step "Python tooling (uv)" if ! command -v uv >/dev/null 2>&1; then info "installing uv (https://astral.sh/uv)" curl -LsSf https://astral.sh/uv/install.sh | sh export PATH="$HOME/.local/bin:$HOME/.cargo/bin:$PATH" fi command -v uv >/dev/null 2>&1 || die "uv was installed but is not on PATH; open a new shell and re-run" info "$(uv --version)" # ---------------------------------------------------------------- 4. choices if [[ -z "$MODEL_CHOICE" ]]; then step "Language model" cat </dev/null || true # ---------------------------------------------------------------- 6. local model if [[ $NEED_LOCAL -eq 1 ]]; then step "Downloading the local model" free_kb="$(df -Pk "$APP_DIR" | awk 'NR==2 {print $4}')" if [[ -n "$free_kb" && "$free_kb" -lt 3000000 ]]; then warn "less than 3 GB free on this disk; the download may fail" fi for entry in "${WEIGHTS[@]}"; do IFS='|' read -r rel file min_bytes <<<"$entry" dest="$APP_DIR/src/models/weights/$rel" mkdir -p "$(dirname "$dest")" if [[ -f "$dest" && "$(wc -c <"$dest")" -ge "$min_bytes" ]]; then info "already present: $file" continue fi info "downloading $file" if ! curl -L --fail --retry 3 -C - --progress-bar -o "$dest.part" "$HF_BASE/$file"; then rm -f "$dest.part" die "download of $file failed. Check your connection and re-run; finished files are kept." fi mv "$dest.part" "$dest" done fi # ---------------------------------------------------------------- 7. API key if [[ $NEED_API -eq 1 ]]; then step "Groq API key" ENV_FILE="$TUFFY_HOME/.env" existing="" [[ -f "$ENV_FILE" ]] && existing="$(grep -E '^GROQ_API_KEY=' "$ENV_FILE" | tail -1 | cut -d= -f2- || true)" if [[ -z "$API_KEY" && -n "$existing" ]]; then info "a key is already saved in $ENV_FILE; keeping it" else if [[ -z "$API_KEY" ]]; then ask_secret " Paste your Groq API key (input is hidden, Enter to skip): " API_KEY="$REPLY" fi if [[ -z "$API_KEY" ]]; then warn "no key given. Add it later with: echo 'GROQ_API_KEY=...' >> $ENV_FILE" else code="$(curl -s -o /dev/null -w '%{http_code}' --max-time 15 \ -H "Authorization: Bearer $API_KEY" https://api.groq.com/openai/v1/models || true)" case "$code" in 200) info "key accepted by Groq" ;; 401|403) warn "Groq rejected this key (HTTP $code). Saving it anyway; fix it in $ENV_FILE" ;; *) warn "could not verify the key (HTTP ${code:-none}); saving it anyway" ;; esac touch "$ENV_FILE"; chmod 600 "$ENV_FILE" grep -v '^GROQ_API_KEY=' "$ENV_FILE" >"$ENV_FILE.tmp" || true printf 'GROQ_API_KEY=%s\n' "$API_KEY" >>"$ENV_FILE.tmp" mv "$ENV_FILE.tmp" "$ENV_FILE"; chmod 600 "$ENV_FILE" info "saved to $ENV_FILE (readable only by you)" fi fi fi # ---------------------------------------------------------------- 8. embedder step "Caching the memory embedding model (~67 MB, one time)" if ! TUFFY_HOME="$TUFFY_HOME" "$PY" -c " from src import embedder state = embedder.prepare(offline=False, announce=print) print(' memory embedder:', state) " 2>&1 | tail -3; then warn "could not cache it now; memory search falls back to keywords until you go online once" fi # ---------------------------------------------------------------- 9. launcher if [[ $MAKE_LAUNCHER -eq 1 ]]; then step "Creating the 'tuffy' command" mkdir -p "$BIN_DIR" LAUNCHER="$BIN_DIR/tuffy" { echo '#!/bin/sh' echo "# Generated by scripts/install.sh" [[ "$TUFFY_HOME" != "$HOME/.tuffy" ]] && echo "export TUFFY_HOME=\"\${TUFFY_HOME:-$TUFFY_HOME}\"" echo "exec \"$PY\" \"$APP_DIR/main.py\" \"\$@\"" } >"$LAUNCHER" chmod +x "$LAUNCHER" info "$LAUNCHER" case ":$PATH:" in *":$BIN_DIR:"*) ;; *) rc="" case "${SHELL:-}" in */zsh) rc="$HOME/.zshrc" ;; */bash) if [[ "$OS" == "Darwin" ]]; then rc="$HOME/.bash_profile"; else rc="$HOME/.bashrc"; fi ;; esac line="export PATH=\"$BIN_DIR:\$PATH\"" if [[ $EDIT_PATH -eq 1 && -n "$rc" ]] && yes_no " $BIN_DIR is not on your PATH. Add it to $rc? [Y/n]: " "y"; then grep -qsF "$line" "$rc" || printf '\n# Added by the Tuffy installer\n%s\n' "$line" >>"$rc" info "added to $rc (open a new terminal to pick it up)" else warn "add this to your shell startup file: $line" fi ;; esac fi # ---------------------------------------------------------------- 10. verify step "Verifying" if TUFFY_HOME="$TUFFY_HOME" TUFFY_SKIP_EMBEDDER_PREWARM=1 "$PY" -c " import src.models, src.cli.repl, tuffy_core from src.models.registry import registry print(' ok:', len(registry.list_ids()), 'models registered')"; then :; else die "verification failed"; fi cat <