#!/bin/sh # ONE COMMAND to a LOCAL-ONLY Archilyzer (demo epic D5): the editor and umtool in # Docker, connected to a published archive as a source, every AI task on a local # model (ollama), and the Claude API refused — provably (`check`). # # ./docker/demo.sh up [--archive ] [--model ] [--gpu auto|vulkan|nvidia|none] # [--editor-port N] [--umtool-port N] [--site-port N] [--homepage-port N] # [--rebuild] [--dry-run] # ./docker/demo.sh down [--volumes] [--dry-run] # ./docker/demo.sh status # ./docker/demo.sh check the local-only proof (exit 1 when it fails) # ./docker/demo.sh voice install the Orpheus voice (about 4 GB, once) # # It needs docker and compose v2 on the host — no Node, no pnpm. Everything it # does is printed, one line per step; `--dry-run` prints the plan and writes and # starts nothing (it only asks docker for its version, df, /proc/meminfo and # /dev/dri). A missing prerequisite ends it with one sentence and exit 1. # # Idempotent: .env.demo (mode 600, gitignored) is written on the first `up` with # a random WORKER_TOKEN and the choices; a later `up` reuses it and changes only # what a flag names. Images are built only when missing (or with --rebuild); a # model already pulled is not pulled again; settings already local are left. # `down` never deletes a volume without --volumes. # # Nothing is bound off loopback: Caddy is the only front door, on 127.0.0.1 # (docker-compose.yml), and docker/guard-exposure.sh is unchanged. No secret is # asked for; the Claude API overlay is never part of this stack. # # POSIX sh: no bashisms (dash, busybox). set -eu # The checkout's root, with no external tool (a PATH with no coreutils must # still reach the "docker is not installed" sentence). case "$0" in */*) cd "${0%/*}/.." ;; *) cd .. ;; esac PROJECT="archilyzer-demo" ENV_FILE="${DEMO_ENV_FILE:-.env.demo}" DEFAULT_ARCHIVE="https://jeralyzer.pages.dev" DEFAULT_MODEL="qwen2.5:7b" MIN_RAM_GB=12 MIN_FREE_GB=25 HOST_OLLAMA_URL="${DEMO_HOST_OLLAMA_URL:-http://127.0.0.1:11434}" DRI_DIR="${DEMO_TEST_DRI_DIR:-/dev/dri}" MEMINFO="${DEMO_TEST_MEMINFO:-/proc/meminfo}" say() { printf 'demo: %s\n' "$*"; } refuse() { printf 'demo: %s\n' "$*" >&2 exit 1 } usage() { cat <<'EOF' ./docker/demo.sh up [--archive ] [--model ] [--gpu auto|vulkan|nvidia|none] [--editor-port N] [--umtool-port N] [--site-port N] [--homepage-port N] [--rebuild] [--dry-run] ./docker/demo.sh down [--volumes] [--dry-run] ./docker/demo.sh status ./docker/demo.sh check the local-only proof (exit 1 when it fails) ./docker/demo.sh voice install the Orpheus voice (about 4 GB, once) EOF } # ─── arguments ─── VERB="${1:-}" [ $# -gt 0 ] && shift case "${VERB}" in up | down | status | check | voice) ;; -h | --help | help | "") usage exit 0 ;; *) refuse "unknown command \"${VERB}\" — one of: up, down, status, check, voice." ;; esac # Every verb needs docker; say so before anything else is looked at. command -v docker >/dev/null 2>&1 || refuse "docker is not installed — install Docker Engine (or Docker Desktop) and run this again." ARCHIVE="" MODEL="" GPU="" EDITOR_PORT="" UMTOOL_PORT="" SITE_PORT="" HOMEPAGE_PORT="" REBUILD=0 DRY=0 VOLUMES=0 need_value() { [ $# -ge 2 ] && [ -n "$2" ] || refuse "$1 needs a value." } while [ $# -gt 0 ]; do case "$1" in --archive) need_value "$@"; ARCHIVE="$2"; shift 2 ;; --model) need_value "$@"; MODEL="$2"; shift 2 ;; --gpu) need_value "$@"; GPU="$2"; shift 2 ;; --editor-port) need_value "$@"; EDITOR_PORT="$2"; shift 2 ;; --umtool-port) need_value "$@"; UMTOOL_PORT="$2"; shift 2 ;; --site-port) need_value "$@"; SITE_PORT="$2"; shift 2 ;; --homepage-port) need_value "$@"; HOMEPAGE_PORT="$2"; shift 2 ;; --rebuild) REBUILD=1; shift ;; --dry-run) DRY=1; shift ;; --volumes) VOLUMES=1; shift ;; *) refuse "unknown flag \"$1\" for ${VERB} — see ./docker/demo.sh --help." ;; esac done if [ "${VERB}" != "up" ]; then for v in "${ARCHIVE}" "${MODEL}" "${GPU}" "${EDITOR_PORT}" "${UMTOOL_PORT}" "${SITE_PORT}" "${HOMEPAGE_PORT}"; do [ -z "$v" ] || refuse "only up takes --archive, --model, --gpu and the port flags." done [ "${REBUILD}" = 0 ] || refuse "only up takes --rebuild." fi [ "${VOLUMES}" = 0 ] || [ "${VERB}" = "down" ] || refuse "only down takes --volumes." # ─── .env.demo: the choices, kept between runs ─── env_get() { [ -f "${ENV_FILE}" ] || return 0 sed -n "s/^$1=//p" "${ENV_FILE}" | tail -n 1 } # The binds the base compose publishes Caddy's ports on. The demo publishes on # 127.0.0.1 only: a different one in .env.demo or in this shell is refused (no # flag turns that off), and demo.sh exports 127.0.0.1 for each before compose # runs — so the value compose interpolates is the one the exposure guard (in # the caddy container, docker-compose.yml passes it the same value) judges. BIND_VARS="SITE_BIND EDITOR_BIND HOMEPAGE_BIND UMTOOL_BIND" # Every line of .env.demo is checked BEFORE compose reads it (compose fills # ${…} in the compose files from it): a comment, or KEY=value for a key # demo.sh writes, its value from the same strict class as when it is written. # Anything else — another key, a bind off loopback, a value with a space, a # quote, a `$` or a control character — is refused in one sentence. ENV_KEYS="WORKER_TOKEN DEMO_ARCHIVE DEMO_MODEL DEMO_GPU_ASKED DEMO_OLLAMA_MEM ARCHILYZER_TAG EDITOR_HTTP_PORT UMTOOL_HTTP_PORT SITE_HTTP_PORT HOMEPAGE_HTTP_PORT" # Whether $1 holds only the characters of class $2 (and is not empty). only_chars() { [ -n "$1" ] || return 1 case "$1" in *[!$2]*) return 1 ;; esac return 0 } URL_CHARS='A-Za-z0-9._~:/?=&%+@,-' check_env_file() { [ -f "${ENV_FILE}" ] || return 0 n=0 while IFS= read -r line || [ -n "${line}" ]; do n=$((n + 1)) case "${line}" in '' | '#'*) continue ;; esac key="${line%%=*}" [ "${key}" != "${line}" ] || refuse "line ${n} of ${ENV_FILE} is not KEY=value — remove it, or delete ${ENV_FILE} to start again." value="${line#*=}" case " ${BIND_VARS} " in *" ${key} "*) [ "${value}" = "127.0.0.1" ] || refuse "${ENV_FILE} sets ${key} to something other than 127.0.0.1, which would publish a port beyond this machine — the demo binds 127.0.0.1 only; remove that line." continue ;; esac case " ${ENV_KEYS} " in *" ${key} "*) ;; *) refuse "line ${n} of ${ENV_FILE} sets a key demo.sh does not write — remove it, or delete ${ENV_FILE} to start again." ;; esac only_chars "${value}" "${URL_CHARS}" || refuse "line ${n} of ${ENV_FILE} (${key}) holds a character no demo value has (a space, a quote, \$, # or a control character) — fix it, or delete ${ENV_FILE} to start again." done <"${ENV_FILE}" } check_shell_binds() { for b in ${BIND_VARS}; do eval "v=\${${b}:-}" [ -z "${v}" ] || [ "${v}" = "127.0.0.1" ] || refuse "${b} is set in this shell to something other than 127.0.0.1, which would publish a port beyond this machine — unset it; the demo binds 127.0.0.1 only." done } check_env_file check_shell_binds prev_token="$(env_get WORKER_TOKEN)" if [ -n "${prev_token}" ]; then only_chars "${prev_token}" 'A-Za-z0-9_-' || refuse "WORKER_TOKEN in ${ENV_FILE} is not a token (letters, digits, - and _) — delete that line and a new one is made." fi [ -n "${ARCHIVE}" ] || ARCHIVE="$(env_get DEMO_ARCHIVE)" [ -n "${ARCHIVE}" ] || ARCHIVE="${DEFAULT_ARCHIVE}" [ -n "${MODEL}" ] || MODEL="$(env_get DEMO_MODEL)" [ -n "${MODEL}" ] || MODEL="${DEFAULT_MODEL}" [ -n "${GPU}" ] || GPU="$(env_get DEMO_GPU_ASKED)" [ -n "${GPU}" ] || GPU="auto" [ -n "${EDITOR_PORT}" ] || EDITOR_PORT="$(env_get EDITOR_HTTP_PORT)" [ -n "${EDITOR_PORT}" ] || EDITOR_PORT=8081 [ -n "${UMTOOL_PORT}" ] || UMTOOL_PORT="$(env_get UMTOOL_HTTP_PORT)" [ -n "${UMTOOL_PORT}" ] || UMTOOL_PORT=8083 [ -n "${SITE_PORT}" ] || SITE_PORT="$(env_get SITE_HTTP_PORT)" [ -n "${SITE_PORT}" ] || SITE_PORT=8080 [ -n "${HOMEPAGE_PORT}" ] || HOMEPAGE_PORT="$(env_get HOMEPAGE_HTTP_PORT)" [ -n "${HOMEPAGE_PORT}" ] || HOMEPAGE_PORT=8082 # Every value that is written to .env.demo is checked here, by character # class, with nothing but the shell: a value that fails is refused WITHOUT # echoing it (it may hold a newline). A newline, a space, a quote, `$`, a # backtick or `#` is in no class, so a value can never carry a second line. case "${ARCHIVE}" in http://* | https://*) ;; *) refuse "--archive is not an http(s) URL." ;; esac only_chars "${ARCHIVE}" "${URL_CHARS}" || refuse "--archive is not a single-line http(s) URL of URL characters (letters, digits and - . _ ~ : / ? = & % + @ ,)." [ "${#ARCHIVE}" -le 300 ] || refuse "--archive is longer than 300 characters." ARCHIVE="${ARCHIVE%/}" ARCHIVE="${ARCHIVE%/corpus.json}" case "${MODEL}" in *-cloud | *:cloud) refuse "--model is an ollama CLOUD model — the demo runs local models only." ;; claude*) refuse "--model is a Claude model — the demo runs local models only." ;; [!A-Za-z0-9]*) refuse "--model is not a model name (letters, digits and . _ : / -, starting with a letter or digit)." ;; esac only_chars "${MODEL}" 'A-Za-z0-9._:/-' && [ "${#MODEL}" -le 128 ] || refuse "--model is not a model name (letters, digits and . _ : / -, starting with a letter or digit)." case "${GPU}" in auto | vulkan | nvidia | none) ;; *) refuse "--gpu is auto, vulkan, nvidia or none." ;; esac for p in "${EDITOR_PORT}" "${UMTOOL_PORT}" "${SITE_PORT}" "${HOMEPAGE_PORT}"; do only_chars "$p" '0-9' && [ "${#p}" -le 5 ] || refuse "a port is a number from 1 to 65535." [ "$p" -ge 1 ] && [ "$p" -le 65535 ] || refuse "a port is a number from 1 to 65535." done for v in $(env_get DEMO_OLLAMA_MEM) $(env_get ARCHILYZER_TAG); do only_chars "${v}" 'A-Za-z0-9' || refuse "${ENV_FILE} holds a DEMO_OLLAMA_MEM or ARCHILYZER_TAG that is not one demo.sh writes — delete ${ENV_FILE} to start again." done # What compose interpolates is what was checked: the shell's own values (which # compose prefers to --env-file's) are these. # (WORKER_TOKEN, DEMO_OLLAMA_MEM and ARCHILYZER_TAG come from .env.demo alone.) unset WORKER_TOKEN DEMO_OLLAMA_MEM ARCHILYZER_TAG export DEMO_ARCHIVE="${ARCHIVE}" DEMO_MODEL="${MODEL}" for b in ${BIND_VARS}; do export "${b}=127.0.0.1"; done export EDITOR_HTTP_PORT="${EDITOR_PORT}" UMTOOL_HTTP_PORT="${UMTOOL_PORT}" SITE_HTTP_PORT="${SITE_PORT}" HOMEPAGE_HTTP_PORT="${HOMEPAGE_PORT}" # ─── prerequisites (read-only probes) ─── check_docker() { command -v docker >/dev/null 2>&1 || refuse "docker is not installed — install Docker Engine (or Docker Desktop) and run this again." if ! info_err="$(docker info 2>&1 >/dev/null)"; then case "${info_err}" in *"ermission denied"*) refuse "docker is installed, but this user may not use its socket (permission denied) — add yourself to the docker group (sudo usermod -aG docker \$USER, then log in again) and run this again." ;; esac refuse "the docker daemon is not answering — start it (sudo systemctl start docker) and run this again." fi cv="$(docker compose version --short 2>/dev/null || true)" [ -n "${cv}" ] || refuse "docker compose v2 is missing — install the compose plugin (docker-compose v1 is not enough) and run this again." cv="${cv#v}" major="${cv%%.*}" rest="${cv#*.}" minor="${rest%%.*}" case "${major}${minor}" in '' | *[!0-9]*) refuse "docker compose answered an unreadable version (\"${cv}\") — compose v2.24 or newer is needed." ;; esac if [ "${major}" -lt 2 ] || { [ "${major}" -eq 2 ] && [ "${minor}" -lt 24 ]; }; then refuse "docker compose ${cv} is too old — the demo needs compose v2.24 or newer." fi COMPOSE_VERSION="${cv}" DOCKER_VERSION="$(docker version --format '{{.Server.Version}}' 2>/dev/null || echo '?')" } ram_gb() { if [ -r "${MEMINFO}" ]; then kb="$(sed -n 's/^MemTotal:[[:space:]]*\([0-9]*\) kB/\1/p' "${MEMINFO}")" # Rounded, not floored: a "16 GB" machine's MemTotal is about 15.6 GiB. [ -n "${kb}" ] && echo $(((kb + 524288) / 1048576)) && return 0 fi if command -v sysctl >/dev/null 2>&1; then b="$(sysctl -n hw.memsize 2>/dev/null || true)" [ -n "${b}" ] && echo $(((b + 536870912) / 1073741824)) && return 0 fi echo "" } free_gb() { if [ -n "${DEMO_TEST_FREE_KB:-}" ]; then echo $((DEMO_TEST_FREE_KB / 1048576)) return 0 fi root="$(docker info --format '{{.DockerRootDir}}' 2>/dev/null || true)" kb="$(df -Pk "${root:-.}" 2>/dev/null | awk 'NR==2 {print $4}' || true)" [ -n "${kb}" ] || kb="$(df -Pk . 2>/dev/null | awk 'NR==2 {print $4}' || true)" [ -n "${kb}" ] && echo $((kb / 1048576)) || echo "" } # A port something already listens on (ss, else netstat; DEMO_TEST_BUSY_PORTS # in tests). Our own stack's ports are not "taken": a re-run finds them bound. port_busy() { if [ -n "${DEMO_TEST_BUSY_PORTS+x}" ]; then case " ${DEMO_TEST_BUSY_PORTS} " in *" $1 "*) return 0 ;; esac return 1 fi if command -v ss >/dev/null 2>&1; then ss -Hltn 2>/dev/null | awk '{print $4}' | grep -Eq "[:.]$1\$" return $? fi if command -v netstat >/dev/null 2>&1; then netstat -ltn 2>/dev/null | awk '{print $4}' | grep -Eq "[:.]$1\$" return $? fi return 1 } stack_running() { [ -n "${DEMO_TEST_STACK_RUNNING:-}" ] && return 0 [ -n "$(docker compose -p "${PROJECT}" ps -q caddy 2>/dev/null || true)" ] } # Any container of the project, running or stopped (what `down` stops). project_exists() { [ -n "${DEMO_TEST_STACK_RUNNING:-}" ] && return 0 [ -n "$(docker compose -p "${PROJECT}" ps -aq 2>/dev/null || true)" ] } # The name ollama lists a model under: a tagless name is `:latest`. listed_name() { case "$1" in *:*) printf '%s' "$1" ;; *) printf '%s:latest' "$1" ;; esac } # A pull's size, for the models whose size is known (ollama's library # listing); nothing for any other. model_size() { case "$(listed_name "$1")" in qwen2.5:7b) printf '4.7 GB' ;; qwen3:8b) printf '5.2 GB' ;; llama3.2:3b) printf '2.0 GB' ;; esac } detect_gpu() { case "${GPU}" in vulkan | nvidia | none) GPU_USED="${GPU}" return 0 ;; esac for n in "${DRI_DIR}"/renderD*; do if [ -e "$n" ]; then GPU_USED=vulkan GPU_NODE="${n}" return 0 fi done if command -v nvidia-smi >/dev/null 2>&1 && docker info 2>/dev/null | grep -qi nvidia; then GPU_USED=nvidia return 0 fi GPU_USED=none } # A host ollama answering with a model loaded: two servers would share the # card. Asked with GET /api/ps, which loads nothing. A warning, never a refusal. check_host_ollama() { ps_json="" if command -v curl >/dev/null 2>&1; then ps_json="$(curl -fsS -m 2 "${HOST_OLLAMA_URL}/api/ps" 2>/dev/null || true)" elif command -v wget >/dev/null 2>&1; then ps_json="$(wget -q -T 2 -O - "${HOST_OLLAMA_URL}/api/ps" 2>/dev/null || true)" else say "host ollama: not checked (no curl or wget on this machine)" return 0 fi [ -n "${ps_json}" ] || return 0 loaded="$(printf '%s' "${ps_json}" | tr ',' '\n' | sed -n 's/.*"name":"\([^"]*\)".*/\1/p' | head -n 3 | tr '\n' ' ')" if [ -n "${loaded}" ]; then say "WARNING: a host ollama at ${HOST_OLLAMA_URL} has ${loaded}loaded — two servers would share the GPU; unload it first (ollama stop )" else say "host ollama: answering at ${HOST_OLLAMA_URL} with no model loaded (stop it while the demo runs, so two servers never share the GPU)" fi } # ─── compose ─── overlays() { o="-f docker-compose.yml -f docker-compose.demo.yml" case "${GPU_USED:-none}" in vulkan) o="${o} -f docker-compose.ollama-vulkan.yml" ;; nvidia) o="${o} -f docker-compose.ollama-nvidia.yml" ;; esac printf '%s' "${o}" } compose_args() { # The env file once there is one (`up` writes it before its first compose # call; a dry run prints the commands as they will be). if [ -f "${ENV_FILE}" ] || [ "${VERB}" = "up" ]; then printf '%s' "-p ${PROJECT} --env-file ${ENV_FILE} $(overlays) --profile umtool --profile ollama" else printf '%s' "-p ${PROJECT} $(overlays) --profile umtool --profile ollama" fi } # Run a docker command, or print it under --dry-run. The words are split on # spaces on purpose (every argument here is space-free: the model name and the # ports are checked above); a JSON argument goes through `ops_json`. run() { if [ "${DRY}" = 1 ]; then printf ' would run: docker %s\n' "$*" return 0 fi # shellcheck disable=SC2086 docker $* } compose() { # shellcheck disable=SC2046 run compose $(compose_args) "$@" } # A step of `up` after which the stack may be partly up: on a failure, ONE # sentence that says what failed and how to stop what started, and exit 1. must() { what="$1" shift if "$@"; then return 0; fi refuse "${what} failed — the demo is partly up; ./docker/demo.sh down stops it." } # `docker compose exec -T editor pnpm --silent ops --json `: # the JSON is one argument, never split. ops_json() { if [ "${DRY}" = 1 ]; then printf " would run: docker compose %s exec -T editor pnpm --silent ops %s --json '%s'\n" "$(compose_args)" "$1" "$2" return 0 fi # shellcheck disable=SC2046 docker compose $(compose_args) exec -T editor pnpm --silent ops "$1" --json "$2" } new_token() { if [ -r /dev/urandom ]; then od -An -tx1 -N24 /dev/urandom | tr -d ' \n' else date +%s%N | sha256sum | cut -c1-48 fi } write_env() { token="${prev_token:-$(new_token)}" old="$(cat "${ENV_FILE}" 2>/dev/null || true)" # DEMO_OLLAMA_MEM: 40% of RAM, at most 8 GB, at least 4. mem=$((RAM_GB * 4 / 10)) [ "${mem}" -gt 8 ] && mem=8 [ "${mem}" -lt 4 ] && mem=4 next="# Written by ./docker/demo.sh (demo epic D5). Kept between runs; a flag changes its line. WORKER_TOKEN=${token} DEMO_ARCHIVE=${ARCHIVE} DEMO_MODEL=${MODEL} DEMO_GPU_ASKED=${GPU} DEMO_OLLAMA_MEM=${mem}g ARCHILYZER_TAG=demo EDITOR_HTTP_PORT=${EDITOR_PORT} UMTOOL_HTTP_PORT=${UMTOOL_PORT} SITE_HTTP_PORT=${SITE_PORT} HOMEPAGE_HTTP_PORT=${HOMEPAGE_PORT}" if [ "${old}" = "${next}" ]; then say "choices: ${ENV_FILE} unchanged" return 0 fi # Never the token itself: only whether it is the same one. if [ -n "${prev_token}" ]; then which="the same WORKER_TOKEN"; else which="a new WORKER_TOKEN"; fi if [ "${DRY}" = 1 ]; then say "choices: would write ${ENV_FILE} (mode 600, ${which})" return 0 fi ( umask 077 printf '%s\n' "${next}" >"${ENV_FILE}.tmp" ) chmod 600 "${ENV_FILE}.tmp" mv "${ENV_FILE}.tmp" "${ENV_FILE}" say "choices: wrote ${ENV_FILE} (mode 600, ${which})" } image_missing() { [ "${DRY}" = 1 ] && [ -n "${DEMO_TEST_IMAGES_PRESENT:-}" ] && return 1 ! docker image inspect "$1" >/dev/null 2>&1 } wait_editor() { if [ "${DRY}" = 1 ]; then printf ' would wait: the editor answering /api/pulse (up to 4 minutes)\n' return 0 fi i=0 while [ "${i}" -lt "${DEMO_TEST_WAIT_TRIES:-48}" ]; do # shellcheck disable=SC2046 if docker compose $(compose_args) exec -T editor curl -fsS -o /dev/null http://127.0.0.1:3001/api/pulse 2>/dev/null; then return 0 fi i=$((i + 1)) sleep "${DEMO_TEST_WAIT_SLEEP:-5}" done refuse "the editor did not answer within 4 minutes (docker compose -p ${PROJECT} logs editor says why) — the demo is partly up; ./docker/demo.sh down stops it." } # ollama's own word on its device: the first `inference compute` line. ollama_device_line() { if [ "${DRY}" = 1 ]; then printf ' would read: ollama'"'"'s "inference compute" log line (GPU or CPU)\n' return 0 fi line="" i=0 while [ "${i}" -lt 12 ] && [ -z "${line}" ]; do # shellcheck disable=SC2046 line="$(docker compose $(compose_args) logs --no-log-prefix ollama 2>/dev/null | grep -m 1 'inference compute' || true)" [ -n "${line}" ] || sleep 2 i=$((i + 1)) done if [ -z "${line}" ]; then say "ollama: no \"inference compute\" line yet — docker compose -p ${PROJECT} logs ollama says which device it found" return 0 fi lib="$(printf '%s' "${line}" | sed -n 's/.*library=\([^ ]*\).*/\1/p')" desc="$(printf '%s' "${line}" | sed -n 's/.*description="\([^"]*\)".*/\1/p')" total="$(printf '%s' "${line}" | sed -n 's/.*total="\([^"]*\)".*/\1/p')" case "${lib}" in cpu | CPU | "") say "ollama: CPU ONLY — no GPU is in use; models run about 10x slower" ;; *) say "ollama: GPU ${lib}${desc:+, ${desc}}${total:+ ${total}}" ;; esac } # ─── the verbs ─── do_up() { if [ "${DRY}" = 1 ]; then say "dry run: only read-only probes — docker version and info, df, /proc/meminfo, /dev/dri, the listening ports, and GET ${HOST_OLLAMA_URL}/api/ps (a host ollama, if one answers); nothing is written, built, pulled or started" fi check_docker RAM_GB="$(ram_gb)" [ -n "${RAM_GB}" ] || RAM_GB=0 FREE_GB="$(free_gb)" [ -n "${FREE_GB}" ] || FREE_GB=0 [ "${RAM_GB}" -ge "${MIN_RAM_GB}" ] || refuse "this machine has ${RAM_GB} GB of RAM; the demo needs at least ${MIN_RAM_GB} GB (a 7B model, the editor and a render)." [ "${FREE_GB}" -ge "${MIN_FREE_GB}" ] || refuse "${FREE_GB} GB is free where docker keeps its images; the demo needs ${MIN_FREE_GB} GB (images about 8, ollama about 6, a model about 5, the voice about 4)." say "docker ${DOCKER_VERSION}, compose v${COMPOSE_VERSION} · ${RAM_GB} GB RAM · ${FREE_GB} GB free · ok" if ! stack_running; then for pair in "editor-port ${EDITOR_PORT}" "umtool-port ${UMTOOL_PORT}" "site-port ${SITE_PORT}" "homepage-port ${HOMEPAGE_PORT}"; do flag="${pair%% *}" p="${pair#* }" if port_busy "${p}"; then refuse "port ${p} is already taken on this machine — pick another with --${flag} ." fi done fi detect_gpu # Intent, not result: ollama's own line after the start says what it uses. case "${GPU_USED}" in vulkan) say "GPU: ${GPU_NODE:-${DRI_DIR}} found -> will ask ollama for Vulkan" ;; nvidia) say "GPU: NVIDIA found -> will ask ollama for CUDA" ;; none) say "GPU: none -> ollama will run on the CPU (about 10x slower)" ;; esac check_host_ollama say "archive ${ARCHIVE} · model ${MODEL} · LOCAL ONLY (the Claude API is refused)" write_env if [ "${REBUILD}" = 1 ] || image_missing archilyzer:demo || image_missing archilyzer:demo-umtool; then say "building images (the first run takes about 10 minutes)" compose build editor umtool || refuse "building the images failed (the build's output is above) — nothing was started; fix it and run ./docker/demo.sh up again." else say "images: archilyzer:demo and archilyzer:demo-umtool present (--rebuild builds them again)" fi say "starting editor, umtool and ollama" must "starting the stack (docker compose up)" compose up -d wait_editor ollama_device_line size="$(model_size "${MODEL}")" # shellcheck disable=SC2046 if [ "${DRY}" = 0 ] && docker compose $(compose_args) exec -T ollama ollama list 2>/dev/null | awk 'NR>1 {print $1}' | grep -qxF "$(listed_name "${MODEL}")"; then say "model ${MODEL}: present" else if [ "${DRY}" = 1 ]; then say "model ${MODEL}: pulled unless ollama already has it (once${size:+, ${size}})"; else say "pulling ${MODEL} (once${size:+, ${size}})"; fi must "pulling ${MODEL}" compose exec -T ollama ollama pull "${MODEL}" fi say "generation: preset local, model ${MODEL} (every task on the local model)" must "setting the local preset (archilyzer gen preset local)" compose exec -T editor pnpm --silent archilyzer gen preset local must "setting the local model (archilyzer gen model local)" compose exec -T editor pnpm --silent archilyzer gen model local "${MODEL}" must "setting the extractor model (archilyzer gen model extractor)" compose exec -T editor pnpm --silent archilyzer gen model extractor "${MODEL}" voice_line if [ "${DRY}" = 1 ]; then say "dry run: nothing was written, built, pulled or started" return 0 fi say "ready. umtool http://localhost:${UMTOOL_PORT}/research · editor http://localhost:${EDITOR_PORT}" say "prove it stayed local any time: ./docker/demo.sh check" } # Is the Orpheus voice usable here? The image must carry a llama-server, and the # voice must be installed. voice_state() { if [ "${DRY}" = 1 ]; then VOICE_STATE="${DEMO_TEST_VOICE_STATE:-unknown}" return 0 fi # shellcheck disable=SC2046 if ! docker compose $(compose_args) exec -T editor test -x /usr/lib/ollama/llama-server 2>/dev/null; then VOICE_STATE=no-server return 0 fi # shellcheck disable=SC2046 if docker compose $(compose_args) exec -T editor pnpm --silent archilyzer tts setup --engine orpheus --check >/dev/null 2>&1; then VOICE_STATE=installed else VOICE_STATE=not-installed fi } voice_line() { voice_state case "${VOICE_STATE}" in installed) say "voice: Orpheus installed" ;; not-installed) say "voice: Orpheus not installed -> run ./docker/demo.sh voice (about 4 GB, once)" ;; no-server) say "voice: Orpheus is not available in this image (it carries no llama-server) -> ./docker/demo.sh voice says what is missing" ;; *) say "voice: would check whether Orpheus is installed (./docker/demo.sh voice installs it)" ;; esac } do_voice() { check_docker stack_running || refuse "the demo is not running — start it with ./docker/demo.sh up first." voice_state case "${VOICE_STATE}" in no-server) refuse "Orpheus needs a llama-server inside the editor image, and this image has none (/usr/lib/ollama/llama-server is missing) — the Orpheus voice is not available in this image yet; Kokoro is: docker compose -p ${PROJECT} exec editor pnpm archilyzer tts setup --engine kokoro" ;; installed) say "voice: Orpheus already installed" ;; *) say "installing the Orpheus voice (the Q8_0 GGUF and its decoder, about 4 GB, once)" compose exec -T editor pnpm --silent archilyzer tts setup --engine orpheus ;; esac ops_json settings '{"patch":{"tts":{"engine":"orpheus"}}}' say "voice: Orpheus is the narration voice (settings.tts.engine)" } do_down() { check_docker # The project is stopped whether or not .env.demo is still here (compose # needs no env file to take down what it started). if ! project_exists; then say "nothing to stop: no ${PROJECT} containers on this machine" return 0 fi GPU_USED=none if [ "${VOLUMES}" = 1 ]; then say "stopping the demo AND deleting its volumes (corpus, config, models, builds, reports, ollama's models)" compose down -v else say "stopping the demo (volumes kept; --volumes deletes them)" compose down fi } do_status() { check_docker GPU_USED=none compose ps stack_running || return 0 ollama_device_line compose exec -T editor pnpm --silent archilyzer gen policy voice_line } do_check() { check_docker stack_running || refuse "the demo is not running — start it with ./docker/demo.sh up first." GPU_USED=none failed=0 # shellcheck disable=SC2046 if docker compose $(compose_args) exec -T editor pnpm --silent archilyzer gen local-check; then :; else failed=1; fi # shellcheck disable=SC2046 cloud="$(docker compose $(compose_args) exec -T ollama printenv OLLAMA_NO_CLOUD 2>/dev/null | tr -d '\r' || true)" if [ "${cloud}" = "1" ]; then say "check: ok ollama runs with OLLAMA_NO_CLOUD=1" else say "check: FAIL ollama runs without OLLAMA_NO_CLOUD=1" failed=1 fi # shellcheck disable=SC2046 if docker compose $(compose_args) exec -T editor test -e /root/.config/archilyzer/anthropic.env 2>/dev/null; then say "check: FAIL a Claude API key file is mounted in the editor" failed=1 else say "check: ok no Claude API key file in the editor" fi [ "${failed}" = 0 ] && say "LOCAL ONLY: yes" || refuse "LOCAL ONLY: NOT proven — see the FAIL lines above." } case "${VERB}" in up) do_up ;; down) do_down ;; status) do_status ;; check) do_check ;; voice) do_voice ;; esac