#!/bin/bash # ───────────────────────────────────────────────────────────────────────────── # TEROS INSTALLER # # curl -fsSL https://get.teros.ai | bash # # Written for bash. The lines up to "set +o posix" are plain POSIX sh on # purpose: when the script is piped into a `sh` that is not bash (dash on # Debian/Ubuntu) they hand over to bash before any bash syntax is read. # # Unattended (no terminal): set TEROS_ADMIN_EMAIL and TEROS_ADMIN_PASSWORD, # optionally TEROS_ADMIN_NAME, TEROS_INSTALL_REPORT=0|1, TEROS_AUTOLOGIN=0|1 and # TEROS_VERSION=x.y.z (or a pre-release such as 1.6.0-rc.1). Every variable is listed in the README of get.teros.ai. # ───────────────────────────────────────────────────────────────────────────── if [ -z "${BASH_VERSION:-}" ]; then if ! command -v bash >/dev/null 2>&1; then echo "The Teros installer needs bash. Install it and run the installer again." >&2 exit 1 fi if [ -f "$0" ]; then exec bash "$0" "$@" fi teros_url=${TEROS_INSTALL_URL:-https://get.teros.ai/install.sh} teros_script=$(curl -fsSL "$teros_url") || { echo "Could not download the installer again from $teros_url to run it with bash." >&2 echo "Check the connection, or run it with bash directly: curl -fsSL https://get.teros.ai | bash" >&2 exit 1 } exec bash -c "$teros_script" bash "$@" fi # macOS runs `sh` as bash in POSIX mode; leave it so the rest behaves as bash. set +o posix 2>/dev/null || true # Everything below lives in one function that is called on the last line. With # `curl … | sh` the shell reads this script from the pipe as it goes: wrapped # like this it has read all of it before running any of it, so a command that # reads standard input (docker exec does) cannot swallow the rest, and a # download cut short runs nothing. teros_install() { TEROS_DIR="$HOME/.teros" REPO_URL="${TEROS_REPO_URL:-https://github.com/teros-hq/teros.git}" GHCR="https://ghcr.io" TELEMETRY_URL="${TEROS_INSTALL_REPORT_URL:-https://get.teros.ai/telemetry}" TELEMETRY_MARK="# Installer report, opt-in: 1 sends one anonymous report per install or update (see get.teros.ai). Teros's own daily report is TEROS_TELEMETRY, chosen in Setup." # Installers before v1.5.0 saved their report answer as TEROS_TELEMETRY, which Teros # 1.5.0 reads for its daily report. That line is kept (it was the person's answer) # under DAILY_KEPT_NOTE, and only its old comment is replaced. TELEMETRY_MARK_OLD="# Installer report, opt-in: 1 sends one anonymous report per install or update (see get.teros.ai)" LEGACY_SAVED_NOTE="# Saved by the installer. Teros does not read these yet." DAILY_KEPT_NOTE="# Saved by an earlier installer: TEROS_TELEMETRY turns Teros's daily report on (1) or off (0). Delete it to choose in Setup." # A no to the usage data question also turns Teros's daily report off. A yes # writes nothing for it: the daily report is on by default and the Setup switch # stays usable (a TEROS_TELEMETRY line would lock it). DAILY_OFF_NOTE="# Saved by the installer: you answered no to usage data, so Teros's daily report is off. Delete this line and the next to choose in Setup." TTY_DEV="${TEROS_INSTALL_TTY:-/dev/tty}" DEFAULT_BACKEND_PORT=10001 DEFAULT_APP_PORT=10002 TEROS_PORT_MAP="10001 10002 10010 10011 10012 10013" NAMING_SINCE=1.4.18 NAMING=0 INSTALL_NAME=teros BACKEND_PORT=$DEFAULT_BACKEND_PORT FRONTEND_PORT=$DEFAULT_APP_PORT ADDRESS_MOVED="" PORTS_CHOSEN=0 MIN_DISK_GB=${MIN_DISK_GB:-10} BACKEND_WAIT=${TEROS_BACKEND_WAIT:-240} # Developer Mode (DEVM): asked after the download, only when the release has it. DEVMODE is the # answer (1/0), empty when the release has no Developer Mode; DEVMODE_WAS says # whether the install had it on. The first start installs the source copy's # dependencies, so the backend gets longer to answer. DEVMODE="" DEVMODE_WAS=0 DEVMODE_BRANCH="" # The first install of the source copy's dependencies, with the package manager the # release uses (DEVM-NFR-3); set once the checkout shows which one (devmode_deps_tool). # Measured on 2026-12-01 (MacBook, Docker Desktop, images already pulled): yarn 6m02s # and 16m17s; pnpm (releases with a pnpm-lock.yaml) 2m12s with an empty store. DEVMODE_DEPS_TOOL="yarn install" DEVMODE_EXTRA="5 to 15 minutes" DEVMODE_BACKEND_WAIT=${TEROS_BACKEND_WAIT:-1200} # How long the installer waits for the web app's first page to compile (DEVM-REQ-29). DEVMODE_WEB_WAIT=${TEROS_WEB_WAIT:-180} IMAGES="backend frontend mca-runtime mca-runtime-bash mca-runtime-playwright" RUNTIMES="mca-runtime mca-runtime-bash mca-runtime-playwright" export GIT_TERMINAL_PROMPT=0 umask 022 MODE=install STAGE="Start" TELEMETRY="" TELEMETRY_SAVED=0 TELEMETRY_SENT=0 TELEMETRY_ID=$(LC_ALL=C tr -dc 'a-f0-9' /dev/null | head -c 16) VERSION="" INSTALLED="" USERS="" OS_ID="unknown" ARCH="unknown" HAVE_TTY=0 if { exec 3<"$TTY_DEV"; } 2>/dev/null; then HAVE_TTY=1; fi # ───────────────────────────────────────────────────────────────────────────── # UI — one fixed-column line per step under phase headings, never wider than # 80 columns. On a terminal the running step is a single live line (spinner, # elapsed time, what it is doing) that becomes the final line. Command output # goes to a log file per step; a failed step prints the end of its log. # Colors on a terminal unless NO_COLOR is set. Portable to bash 3.2 (macOS). # ───────────────────────────────────────────────────────────────────────────── if [ -z "${NO_COLOR:-}" ] && [ "${FORCE_COLOR:-}" != 0 ] && { [ -t 1 ] || [ -n "${FORCE_COLOR:-}" ]; }; then C_RESET=$'\033[0m'; C_BOLD=$'\033[1m' C_DIM=$'\033[38;5;245m'; C_VIOLET=$'\033[38;5;141m'; C_LILAC=$'\033[38;5;183m' C_GREEN=$'\033[38;5;114m'; C_RED=$'\033[38;5;203m'; C_YELLOW=$'\033[38;5;221m' C_CYAN=$'\033[38;5;117m' C_PILL=$'\033[48;5;141m\033[38;5;16m\033[1m' else C_RESET=""; C_BOLD=""; C_DIM=""; C_VIOLET=""; C_LILAC=""; C_GREEN=""; C_RED="" C_YELLOW=""; C_CYAN=""; C_PILL="" fi UI_TTY=0 [ -t 1 ] && UI_TTY=1 UI_TOTAL=13 UI_NAME_W=22 UI_DETAIL_W=36 UI_TAIL_LINES=15 UI_STEP_N=0 UI_STEP_NAME="" UI_STEP_LOG="" UI_STEP_OPEN=0 UI_STEP_START_MS=0 UI_STEP_WARN="" UI_STEP_INFO="" FINAL_NOTES="" UI_TICK_PID="" UI_FRAMES=(⠋ ⠙ ⠹ ⠸ ⠼ ⠴ ⠦ ⠧ ⠇ ⠏) UI_TMP=${TMPDIR:-/tmp} UI_RUN_DIR=$(mktemp -d "${UI_TMP%/}/teros-install.XXXXXX") ui_now_ms() { local ns ns=$(date +%s%N 2>/dev/null) case "$ns" in *N*|"") perl -MTime::HiRes=time -e 'printf "%d", time * 1000' 2>/dev/null || echo $(( $(date +%s) * 1000 )) ;; *) echo $(( ns / 1000000 )) ;; esac } UI_START_MS=$(ui_now_ms) ui_fmt_duration() { local ms=$1 if [ "$ms" -lt 60000 ]; then printf '%d.%ds' $(( ms / 1000 )) $(( (ms % 1000) / 100 )) else printf '%dm%02ds' $(( ms / 60000 )) $(( (ms % 60000) / 1000 )) fi } # Characters of a UTF-8 string whatever the locale: every byte that is not a # continuation byte (10xxxxxx) starts one. ui_chars() { local LC_ALL=C s=$1 i=0 n=0 len len=${#s} while [ $i -lt "$len" ]; do case "${s:$i:1}" in [$'\200'-$'\277']) ;; *) n=$((n + 1)) ;; esac i=$((i + 1)) done echo "$n" } # ui_fit -> the text, cut to max characters with a trailing … ui_fit() { local LC_ALL=C s=$1 max=$2 i=0 n=0 len out="" if [ "$(ui_chars "$s")" -le "$max" ]; then printf '%s' "$s"; return 0; fi len=${#s} while [ $i -lt "$len" ]; do case "${s:$i:1}" in [$'\200'-$'\277']) ;; *) n=$((n + 1)); [ "$n" -ge "$max" ] && break ;; esac out="${out}${s:$i:1}" i=$((i + 1)) done printf '%s…' "$out" } ui_rule() { local i=0 out="" while [ $i -lt "$1" ]; do out="${out}─"; i=$((i + 1)); done printf '%s' "$out" } # ui_row ui_row() { printf ' %s%s %s%2d/%d%s %s%-*s%s %s%6s%s' \ "$1" "$C_RESET" "$C_DIM" "$UI_STEP_N" "$UI_TOTAL" "$C_RESET" \ "$2" "$UI_NAME_W" "$UI_STEP_NAME" "$C_RESET" \ "$3" "$4" "$C_RESET" if [ -n "$5" ]; then printf ' %s%s%s' "$C_DIM" "$(ui_fit "$5" "$UI_DETAIL_W")" "$C_RESET"; fi } ui_live_start() { [ "$UI_TTY" = 1 ] || return 0 : > "$UI_RUN_DIR/.live" rm -f "$UI_RUN_DIR/.follow" printf '\033[?25l\033[?7l' # no cursor, no auto-wrap ( i=0 while kill -0 $$ 2>/dev/null; do note="" if [ -f "$UI_RUN_DIR/.follow" ]; then # a command is running: show the last line it wrote to the step log note=$(tail -n 5 "$UI_STEP_LOG" 2>/dev/null | tr -d '\r' \ | sed -e $'s/\033\\[[0-9;]*[A-Za-z]//g' -e 's/^[[:space:]]*//' -e 's/^Image //' -e 's|ghcr.io/teros-hq/||' | grep -v '^+ ' | grep . | tail -n 1) fi [ -n "$note" ] || note=$(tail -n 1 "$UI_RUN_DIR/.live" 2>/dev/null) printf '\r\033[2K%s' "$(ui_row "${C_VIOLET}${UI_FRAMES[$(( i % 10 ))]}" "$C_BOLD" "$C_LILAC" "$(ui_fmt_duration $(( $(ui_now_ms) - UI_STEP_START_MS )))" "$note")" i=$((i + 1)) sleep 0.1 done ) 2>/dev/null & UI_TICK_PID=$! } ui_live_stop() { [ -n "$UI_TICK_PID" ] || return 0 kill "$UI_TICK_PID" 2>/dev/null || true wait "$UI_TICK_PID" 2>/dev/null || true UI_TICK_PID="" printf '\r\033[2K\033[?7h\033[?25h' } ui_phase() { STAGE=$1 echo "" printf ' %s%s%s %s%s%s\n' "${C_VIOLET}${C_BOLD}" "$1" "$C_RESET" "$C_DIM" "$(ui_rule $(( 64 - ${#1} )))" "$C_RESET" } ui_step() { UI_STEP_N=$((UI_STEP_N + 1)) UI_STEP_NAME=$1 UI_STEP_OPEN=1 UI_STEP_WARN="" UI_STEP_INFO="" UI_STEP_START_MS=$(ui_now_ms) UI_STEP_LOG=$(printf '%s/%02d.log' "$UI_RUN_DIR" "$UI_STEP_N") : > "$UI_STEP_LOG" ui_live_start } # What the step is doing right now, for the live line. ui_note() { [ -n "$UI_TICK_PID" ] && printf '%s\n' "$1" >> "$UI_RUN_DIR/.live"; return 0; } # A line printed above the live line while the step keeps running. ui_say() { ui_live_stop printf ' %s%s%s\n' "$C_YELLOW" "$1" "$C_RESET" printf '%s\n' "$1" >> "$UI_STEP_LOG" ui_live_start } # ui_run [args...] — output goes to the step log; while it runs the live # line shows the last thing it printed. Never pass a secret as an argument. ui_run() { local code=0 printf '\n+ %s\n' "$*" >> "$UI_STEP_LOG" : > "$UI_RUN_DIR/.follow" "$@" > "$UI_STEP_LOG" 2>&1 || code=$? rm -f "$UI_RUN_DIR/.follow" return $code } ui_close() { # ui_close local ms ui_live_stop ms=$(( $(ui_now_ms) - UI_STEP_START_MS )) ui_row "$1" "$2" "$3" "$(ui_fmt_duration "$ms")" "$4" echo "" UI_STEP_OPEN=0 } ui_ok() { if [ -n "$UI_STEP_WARN" ]; then ui_close "${C_YELLOW}⚠" "" "$C_DIM" "${1:-}" printf '%s\n' "$UI_STEP_WARN" | while IFS= read -r line; do printf ' %s⚠ %s%s\n' "$C_YELLOW" "$line" "$C_RESET" done else ui_close "${C_GREEN}✔" "" "$C_DIM" "${1:-}" fi if [ -n "$UI_STEP_INFO" ]; then printf '%s\n' "$UI_STEP_INFO" | while IFS= read -r line; do printf ' %s→%s %s\n' "$C_CYAN" "$C_RESET" "$line" done fi } # A fact about a choice the installer made, shown under the step and kept for # the final message: not a warning. ui_info() { if [ -n "$UI_STEP_INFO" ]; then UI_STEP_INFO="$UI_STEP_INFO"$'\n'"$1"; else UI_STEP_INFO=$1; fi if [ -n "$FINAL_NOTES" ]; then FINAL_NOTES="$FINAL_NOTES"$'\n'"$1"; else FINAL_NOTES=$1; fi printf '→ %s\n' "$1" >> "$UI_STEP_LOG" } ui_warn() { if [ -n "$UI_STEP_WARN" ]; then UI_STEP_WARN="$UI_STEP_WARN"$'\n'"$1"; else UI_STEP_WARN=$1; fi printf '⚠ %s\n' "$1" >> "$UI_STEP_LOG" } ui_tail() { [ -s "$UI_STEP_LOG" ] || return 0 printf ' %s╭─ last lines of the log%s\n' "$C_DIM" "$C_RESET" tail -n "$UI_TAIL_LINES" "$UI_STEP_LOG" | tr -d '\r' | grep . | cut -c1-70 | sed "s/^/ ${C_DIM}│${C_RESET} /" printf ' %s╰─%s\n' "$C_DIM" "$C_RESET" } # Where the step logs of a failed run are kept once the temp folder is gone. keep_logs() { local dest if [ -d "$TEROS_DIR/.git" ]; then dest="$TEROS_DIR/install-error.log"; else dest="${UI_TMP%/}/teros-install-error.log"; fi ( umask 077; cat "$UI_RUN_DIR"/[0-9]*.log > "$dest" ) 2>/dev/null || return 1 printf '%s' "$dest" } failed_step() { if [ "$UI_STEP_OPEN" = 1 ]; then printf '%s' "$UI_STEP_NAME"; else printf '%s' "$STAGE"; fi } # die [...] — ends the run: closes the open step as failed, shows # the end of its log and prints what to do. die() { local where="before the first step" log="" step step=$(failed_step) if [ "$UI_STEP_OPEN" = 1 ]; then ui_close "${C_RED}✖" "$C_BOLD" "$C_RED" "" ui_tail where="at step $UI_STEP_N of $UI_TOTAL ($step)" elif [ "$UI_STEP_N" -gt 0 ]; then where="after step $UI_STEP_N of $UI_TOTAL ($step)" else where="($step)" fi echo "" printf ' %s✖ Installation stopped%s %s%s, after %s%s\n' "${C_RED}${C_BOLD}" "$C_RESET" "$C_DIM" "$where" \ "$(ui_fmt_duration $(( $(ui_now_ms) - UI_START_MS )))" "$C_RESET" while [ $# -gt 0 ]; do printf ' %s\n' "$1" shift done log=$(keep_logs) [ -n "$log" ] && printf ' %sLog: %s%s\n' "$C_DIM" "$log" "$C_RESET" echo "" telemetry_send failed "$step" exit 1 } ui_interrupted() { local step step=$(failed_step) local open=$UI_STEP_OPEN ui_live_stop echo "" if [ "$open" = 1 ]; then step="at step $UI_STEP_N of $UI_TOTAL ($step)"; else step="($step)"; fi printf ' %s✖ Installation interrupted%s %s%s; run the installer again to finish%s\n\n' "${C_YELLOW}${C_BOLD}" "$C_RESET" "$C_DIM" "$step" "$C_RESET" step=$(failed_step) telemetry_send interrupted "$step" exit 130 } trap ui_interrupted INT TERM HUP trap '[ -n "$UI_TICK_PID" ] && kill "$UI_TICK_PID" 2>/dev/null; [ "$UI_TTY" = 1 ] && printf "\033[?7h\033[?25h"; rm -rf "$UI_RUN_DIR"' EXIT # ───────────────────────────────────────────────────────────────────────────── # QUESTIONS — an answer comes from its environment variable when set, else # from the terminal, else the default; a required answer with neither stops # the run and names the variable. # ───────────────────────────────────────────────────────────────────────────── ui_answer() { # ui_answer