#!/usr/bin/env bash # Inside The Machine · one-command install: Chat with your files # A private chat that answers questions about your own PDFs, notes and documents. # Page: https://insidethemachine.ai/do/docs Agent doc: https://insidethemachine.ai/install/docs.md # Run status: Partly checked: some paths were run, the rest only checked against docs. Install steps run on an Apple M4 Mac with 16 GB on 2026-10-15. File upload and the first Docling run are checked against the docs only. # This script: The wrapper scripts are generated from the site data. Every .sh passed bash -n and shellcheck and ran in plan mode on Linux (Debian 13). Every .ps1 passed the PowerShell parser and chat.ps1 ran in plan, verify and rollback mode under PowerShell 7 on Linux with Windows calls mocked. Not run on macOS or real Windows. # # Read it first: curl -fsSL https://insidethemachine.ai/install/docs.sh | less # curl -fsSL https://insidethemachine.ai/install/docs.sh | bash install, then check # curl -fsSL https://insidethemachine.ai/install/docs.sh | bash -s -- plan print every step, run nothing # curl -fsSL https://insidethemachine.ai/install/docs.sh | bash -s -- verify only the checks # curl -fsSL https://insidethemachine.ai/install/docs.sh | bash -s -- rollback --yes undo it (without --yes it only prints) # Options: ITM_RAM=32 (memory in GB instead of detecting it), ITM_MODEL= # Lines marked YOU RUN are left to you: servers that keep running, interactive apps, your own files. # shellcheck disable=SC2016,SC1090 set -u main() { ACT="${ITM_ACTION:-install}"; YES="${ITM_YES:-}" for a in "$@"; do case "$a" in --yes|-y) YES=1 ;; install|plan|verify|rollback) ACT="$a" ;; *) echo "unknown option: $a (use install, plan, verify or rollback)" >&2; exit 2 ;; esac; done START="$(pwd)"; FAILS=0; NEXT="" case "$(uname -s)" in Darwin) P=mac ;; Linux) P=linux ;; *) P=other ;; esac say() { printf '\n== %s\n' "$1"; } note() { printf ' # %s\n' "$1"; } die() { printf '\nSTOP: %s\nHelp: %s\n' "$1" 'https://insidethemachine.ai/do/docs#fix' >&2; exit 1; } run() { printf ' $ %s\n' "$1"; [ "$ACT" = plan ] && return 0; eval "$1" || die "this step failed: $1"; } mac() { if [ "$P" != mac ]; then printf ' (macOS only, skipped: use your package manager) %s\n' "$1"; return 0; fi case "$1" in xcode-select*) printf ' $ %s\n' "$1"; [ "$ACT" = plan ] || xcode-select -p >/dev/null 2>&1 || die "install Apple's command line tools first: run xcode-select --install, finish the window, then run this again"; return 0 ;; brew*) [ "$ACT" = plan ] || command -v brew >/dev/null 2>&1 || die "needs Homebrew first: https://brew.sh" ;; esac run "$1"; } you() { printf ' YOU RUN: %s\n' "$1"; [ -n "$2" ] && printf ' (%s)\n' "$2"; NEXT="$NEXT $1\n"; } undo() { if [ "${2:-}" = mac ] && [ "$P" != mac ]; then return 0; fi; printf ' $ %s\n' "$1"; if [ "$ACT" = rollback ] && [ -n "$YES" ]; then eval "$1" || echo " (failed, carrying on)"; fi; } check() { printf ' ? %s\n expect: %s\n' "$1" "$2"; [ "$ACT" = plan ] && return 0; if out=$(eval "$1" 2>&1) && ! printf '%s' "$out" | grep -q '^{"error"'; then echo " PASS"; else echo " FAIL"; FAILS=$((FAILS + 1)); fi; [ -n "$out" ] && printf '%s\n' "$out" | head -n 3 | sed 's/^/ | /'; return 0; } need_ollama() { [ "$ACT" = plan ] && return 0; ollama list >/dev/null 2>&1 && return 0; echo " starting 'ollama serve' in the background (log: /tmp/itm-ollama.log)"; nohup ollama serve >/tmp/itm-ollama.log 2>&1 & i=0; while [ $i -lt 30 ]; do sleep 1; ollama list >/dev/null 2>&1 && return 0; i=$((i + 1)); done; die "Ollama is not running. Open the Ollama app, then run this again."; } [ "$P" = other ] && die "this script is for macOS and Linux. On Windows: irm https://insidethemachine.ai/install/docs.ps1 | iex" mem_gb() { if [ -n "${ITM_RAM:-}" ]; then echo "$ITM_RAM"; return; fi if [ "$P" = mac ]; then echo $(( $(sysctl -n hw.memsize) / 1073741824 )); return; fi if command -v nvidia-smi >/dev/null 2>&1; then v=$(nvidia-smi --query-gpu=memory.total --format=csv,noheader,nounits 2>/dev/null | head -n 1 | tr -dc 0-9); [ -n "$v" ] && { echo $(( v / 1024 )); return; }; fi awk '/^MemTotal:/{printf "%d\n", $2/1048576 + 0.5}' /proc/meminfo } RAM="$(mem_gb)" # a size counts if the machine has at least 94% of it (Linux reports a bit less than the label) fits() { [ $((RAM * 100)) -ge $(($1 * 94)) ]; } MODEL="${ITM_MODEL:-}" if [ -z "$MODEL" ]; then for t in 8:qwen3.5:4b 16:gemma4:12b 24:gemma4:12b 32:qwen3.8:27b 48:qwen3.8:27b 64:qwen3.8:27b 96:qwen3.8:27b 128:qwen3.8:27b 192:qwen3.8-flash-next:125b-a6b 256:qwen3.8-flash-next:125b-a6b 512:qwen3.8-flash-next:125b-a6b; do fits "${t%%:*}" && MODEL="${t#*:}"; done; fi [ -n "$MODEL" ] || die "no model in our list fits ${RAM} GB. See https://insidethemachine.ai/models" install_any() { say '1. Install Ollama' run 'curl -fsSL https://ollama.com/install.sh | sh' say '2. Download your model' need_ollama run 'ollama pull $MODEL' say '3. Add a ChatGPT-style window' mac 'brew install python@3.11' run 'python3.11 -m venv ~/.venvs/openwebui && source ~/.venvs/openwebui/bin/activate' run 'pip install open-webui' you 'open-webui serve' 'starts a server that keeps running; run it in its own window' say '4. Add your files' note 'In a chat, click + and attach a file, then ask about it. For a whole folder, go to Workspace → Knowledge, make a collection and upload your files. Then type # in a chat to use it.' say '5. Messy PDF? Clean it first' run 'python3 -m venv ~/.venvs/docling && source ~/.venvs/docling/bin/activate' run 'pip install docling' you 'docling yourfile.pdf' 'needs your own file, folder or model name' } verify_any() { say 'Check' check 'ollama --version' 'a version number' check 'ollama list | grep -F "${MODEL%%:*}"' 'your model is in the list' check 'test -x ~/.venvs/openwebui/bin/open-webui' 'Open WebUI is installed' check 'test -x ~/.venvs/docling/bin/docling' 'Docling is installed' } rollback_any() { say 'Rollback' undo 'ollama rm $MODEL' undo 'rm -rf ~/.venvs/openwebui ~/.venvs/docling' undo 'rm -rf ~/Library/Caches/pip' } act() { return 0; } inwd() { return 0; } V=any printf 'Inside The Machine · Chat with your files · %s · %s%s\n' "$ACT" "$P" " · ${RAM} GB · model $MODEL" case "$ACT" in install|plan) "install_$V"; cd "$START" || exit 1; act; inwd; "verify_$V"; cd "$START" || exit 1; [ "$ACT" = plan ] && "rollback_$V" ;; verify) act; inwd; "verify_$V" ;; rollback) [ -n "$YES" ] || note 'print only: add --yes to run these'; act; "rollback_$V" ;; esac if [ -n "$NEXT" ]; then say 'Now you run these (in order)'; printf '%b' "$NEXT"; fi [ "$ACT" = install ] && printf '\nDone. %s check(s) failed. Next steps and fixes: %s\n' "$FAILS" 'https://insidethemachine.ai/do/docs' [ "$FAILS" -eq 0 ] } main "$@"