Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

Server installer: one command from a fresh Ubuntu server to HTTPS on your domain

milind-soni0dc66b16b654
diff --git a/.github/workflows/server-installer.yml b/.github/workflows/server-installer.yml
new file mode 100644
index 0000000000..7fa47ced10
--- /dev/null
+++ b/.github/workflows/server-installer.yml
@@ -0,0 +1,65 @@
+name: Server installer
+
+# The self-hosted server's installer (deploy/install.sh) on a stock ubuntu-24.04 runner, as a person runs it on a fresh
+# server: shellcheck, its checks against made-up servers, then the checks and a real install of the published image
+# (deploy/e2e/run.sh). It talks to no production service and needs no secret.
+on:
+ pull_request:
+ paths:
+ - deploy/install.sh
+ - deploy/e2e/**
+ - deploy/Caddyfile
+ - deploy/docker-compose.yml
+ - scripts/server-installer.test.ts
+ - .github/workflows/server-installer.yml
+ workflow_dispatch:
+
+permissions:
+ contents: read
+
+concurrency:
+ group: server-installer-${{ github.ref }}
+ cancel-in-progress: true
+
+jobs:
+ e2e:
+ name: check, install, run again and uninstall on Ubuntu 24.04
+ runs-on: ubuntu-24.04
+ timeout-minutes: 30
+ steps:
+ - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
+ with:
+ persist-credentials: false
+ - name: shellcheck
+ run: shellcheck deploy/install.sh deploy/e2e/run.sh
+ - uses: pnpm/action-setup@ff378ebe6b225b0680b81c1ad4498ae0d1d3a5e3 # v6.0.10
+ - uses: actions/setup-node@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0
+ with:
+ node-version: 24
+ cache: pnpm
+ - run: pnpm install --frozen-lockfile
+ env:
+ ELECTRON_SKIP_BINARY_DOWNLOAD: "1"
+ - name: The installer's checks against made-up servers
+ run: pnpm exec vitest run scripts/server-installer.test.ts
+ - name: Leave the 20 GB a server needs free for Docker
+ # The installer refuses a server with less, as it should; a runner sometimes has less to start with.
+ run: |
+ set -euo pipefail
+ free_gb() { df -BG --output=avail /var/lib/docker | tail -n 1 | tr -dc '0-9'; }
+ echo "free for Docker: $(free_gb) GB"
+ if [ "$(free_gb)" -lt 30 ]; then
+ sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc /usr/local/.ghcup /opt/hostedtoolcache/CodeQL
+ echo "free for Docker now: $(free_gb) GB"
+ fi
+ - name: Check, install, run again and uninstall
+ env:
+ OUT: ${{ runner.temp }}/server-installer
+ run: bash deploy/e2e/run.sh
+ - name: Keep the evidence
+ if: always()
+ uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
+ with:
+ name: server-installer
+ path: ${{ runner.temp }}/server-installer
+ retention-days: 14
diff --git a/apps/docs/content/docs/self-hosting/deploy-vps.mdx b/apps/docs/content/docs/self-hosting/deploy-vps.mdx
index 41b94bd3dd..88f725b2bf 100644
--- a/apps/docs/content/docs/self-hosting/deploy-vps.mdx
+++ b/apps/docs/content/docs/self-hosting/deploy-vps.mdx
@@ -10,6 +10,71 @@ icon: Cloud
From a blank Linux server to MausBot running on it around the clock, reachable from your laptop, the desktop app and your phone, with your bots working while every laptop is closed. It assumes nothing beyond being able to open a terminal and paste commands. About twenty minutes, most of it waiting.
+## Quick start: one command on your own domain
+
+For a fresh Ubuntu 22.04 or 24.04 server (x86-64, at least 2 CPUs, 4 GB of memory and 20 GB of free disk) and a domain name whose A record already points at it:
+
+```sh
+curl -fsSL https://raw.githubusercontent.com/milind-soni/OpenMausBot/main/deploy/install.sh | sudo sh -s -- --domain maus.example.com
+```
+
+The installer ([`deploy/install.sh`](https://github.com/milind-soni/OpenMausBot/blob/main/deploy/install.sh)) does path B below for you and ends with MausBot answering at `https://maus.example.com`.
+
+**It checks the server first, and changes nothing while it checks.** Each check that fails prints one sentence saying what to fix, and nothing is installed until all pass:
+
+| Check | Passes when |
+|---|---|
+| Operating system | Ubuntu 22.04 or 24.04 |
+| Processor | x86-64, 2 cores or more |
+| Memory | 4 GB or more (8 GB suggested) |
+| Free disk | 20 GB or more, where the install and Docker keep their files |
+| Docker | Docker 24 or newer with the Compose plugin, running, not rootless |
+| Ports | 80 and 443 are free |
+| DNS | the domain resolves to this server's public address |
+| Outbound | HTTPS reaches the image registries (`ghcr.io`, `pkg-containers.githubusercontent.com`, Docker Hub) and Let's Encrypt |
+| User namespaces | switched on, for the bots' sandbox |
+| Clock | within five minutes of the internet's |
+| Version | a MausBot release to install was found |
+
+To run only the checks, add `--check`:
+
+```sh
+curl -fsSL https://raw.githubusercontent.com/milind-soni/OpenMausBot/main/deploy/install.sh | sudo sh -s -- --check --domain maus.example.com
+```
+
+If Docker is missing, the installer asks before installing it with Docker's official script (`get.docker.com`); `--install-docker` says yes ahead of time. It installs nothing else on the server.
+
+**Then it installs** everything under one folder, `/opt/openmausbot` (`--dir` picks another):
+
+| Path | What |
+|---|---|
+| `compose.yaml`, `Caddyfile` | the same server-plus-Caddy setup as path B; written again on every run |
+| `.env` | your settings: `DOMAIN`, the pinned version (`OMB_IMAGE`) and anything you add, such as [who may sign in with an email](/docs/self-hosting). The installer keeps your lines |
+| `data/` | everything MausBot stores: chats, bots, engine sign-ins, paired devices. Never touched once it exists |
+| `caddy/` | the HTTPS certificates |
+
+It runs the newest release, pinned by its version; once a `stable` channel is published it follows that instead. It never runs `latest`, which follows every commit. It then waits until the server reports healthy and `https://maus.example.com` answers with a valid certificate, and prints the address.
+
+**Sign in as the first admin** with a one-time link made on the server:
+
+```sh
+cd /opt/openmausbot && sudo docker compose exec omb openmausbot pair --label "First admin"
+```
+
+Open the link it prints, or paste it into the desktop app under **+ → Connect to a server**. To sign in with an emailed code instead, run the installer with `--email [email protected]`.
+
+- **Update or repair:** run the same command again. It checks the server, rewrites its own files, moves to the newest release and leaves `.env` and `data/` alone.
+- **Stop:** `--uninstall` stops the server and removes its containers. It deletes nothing: your data stays in `/opt/openmausbot/data`.
+- **Every other command in this guide** that starts `docker compose` for path B works from `/opt/openmausbot`.
+- **What the installer contacts:** the registries and Let's Encrypt from the table, GitHub's release list, and `cloudflare.com/cdn-cgi/trace` to learn the server's public address for the DNS check. It sends no telemetry.
+- **Behind a load balancer or NAT** that forwards ports 80 and 443 to the server, set `OMB_INSTALL_SKIP_DNS=1` to skip the DNS check.
+
+The installer also accepts the one-time code of a server connected to MausBot. That offering is not available yet.
+
+Not on Ubuntu, or prefer to do it by hand? Use one of the three ways below.
+
+## Three ways in, by hand
+
Three ways to make the server reachable are covered. Pick one; the rest of the guide is the same.
| | You need | Who can reach it | Best for |
@@ -95,6 +160,8 @@ Skip to "Install and sign the engines in".
One container for the server plus Caddy for HTTPS at `https://maus.example.com`.
+The [installer](#quick-start-one-command-on-your-own-domain) does these steps for you on Ubuntu. Do them by hand on another system, to build your own image with `ENGINES`, or to see what it does.
+
1. **Point a name at the server.** In your DNS provider add an **A record** (name `maus`, value the server's public IP). After a few minutes `ping maus.example.com` should answer with that IP. Ports 80 and 443 must be open; most providers open them by default.
2. **Install Docker:**
@@ -290,6 +357,7 @@ same release without an npm install prompt or an implicit upgrade.
Check that installation succeeded before starting. A service restart by itself
does not update the installed package. For foreground `npx` usage, specify the
desired release as `npx --yes [email protected] serve --tunnel`.
+- **Installed with the installer:** run the install command again.
- **Path B:** `cd OpenMausBot/deploy && docker compose pull omb && docker compose up -d`.
Routines and queued work survive a restart; a turn running at that moment does not, so update between runs.
@@ -326,6 +394,15 @@ backup_dir=$(mktemp -d "$PWD/openmausbot-backup.XXXXXX")
docker run --rm -v deploy_data:/data:ro -v "$backup_dir":/b alpine sh -c 'umask 077; tar czf /b/openmausbot-data.tgz -C /data .'
```
+With the installer, the data is a folder, not a volume. Archive it the same way:
+
+```sh
+cd /opt/openmausbot && sudo docker compose stop omb
+backup_dir=$(mktemp -d "$PWD/openmausbot-backup.XXXXXX")
+sudo tar czf "$backup_dir/openmausbot-data.tgz" -C /opt/openmausbot data
+sudo docker compose start omb
+```
+
Each command creates a fresh private folder in the current directory, so it
cannot overwrite an older archive with more permissive access. Keep the
archive inside that folder privately on another machine. Restore with the server stopped,
diff --git a/apps/docs/content/docs/self-hosting/index.mdx b/apps/docs/content/docs/self-hosting/index.mdx
index 47ced09d41..7a9a8651ce 100644
--- a/apps/docs/content/docs/self-hosting/index.mdx
+++ b/apps/docs/content/docs/self-hosting/index.mdx
@@ -6,7 +6,17 @@ icon: Server
MausBot is local-first by default: the harness listens on loopback, agent CLIs run on your machine, and application state lives under `~/.openmausbot`.
-## Typical self-hosted setup
+## On a server, with one command
+
+On a fresh Ubuntu 22.04 or 24.04 server (x86-64) with a domain name pointing at it, the installer checks the server, installs MausBot with Docker under `/opt/openmausbot` and ends with HTTPS on your domain:
+
+```bash
+curl -fsSL https://raw.githubusercontent.com/milind-soni/OpenMausBot/main/deploy/install.sh | sudo sh -s -- --domain maus.example.com
+```
+
+Add `--check` to only check the server; it changes nothing. Run the command again to update or repair, and `--uninstall` to stop the server while keeping your data. [Deploy on a VPS](/docs/self-hosting/deploy-vps#quick-start-one-command-on-your-own-domain) lists every check, the files it writes and how the first admin signs in.
+
+## On your own computer, or by hand
1. Run MausBot on your personal macOS, Windows, or Ubuntu computer.
2. Install and authenticate the agent CLIs you want to use separately; the npm OpenMausBot package does not include them. Use the same operating-system account for setup and the running server.
diff --git a/deploy/e2e/run.sh b/deploy/e2e/run.sh
new file mode 100755
index 0000000000..4963e885c0
--- /dev/null
+++ b/deploy/e2e/run.sh
@@ -0,0 +1,92 @@
+#!/usr/bin/env bash
+# The server installer (deploy/install.sh) on a stock Ubuntu 24.04 host with Docker, run as a person runs it: the checks
+# alone, then a real install of the published image, a second run, an uninstall that keeps the data, and an install on
+# top of that data. The host has no domain of its own, so the DNS check is shown to fail and is then skipped, and no
+# certificate can be issued: the installer must say exactly that, with the server healthy behind Caddy.
+# OUT=<evidence folder> bash deploy/e2e/run.sh
+set -euo pipefail
+ROOT=$(cd "$(dirname "$0")/../.." && pwd)
+OUT=${OUT:-$(mktemp -d)}
+mkdir -p "$OUT"
+DOMAIN=installer-e2e.invalid
+DIR=/opt/openmausbot
+INSTALL=(sudo env OMB_INSTALL_SKIP_DNS=1 OMB_INSTALL_HTTPS_WAIT_S=20 sh "$ROOT/deploy/install.sh")
+
+as_root() { sudo "$@"; }
+step() { printf '\n== %s\n' "$*"; }
+fail() {
+ printf 'FAILED: %s\n' "$*" >&2
+ as_root docker compose --project-directory "$DIR" logs --tail 80 >"$OUT/compose.log" 2>&1 || true
+ exit 1
+}
+contains() { # file words what
+ grep -qF -- "$2" "$1" || fail "$3: $(tail -n 20 "$1")"
+}
+# No certificate can be issued for a made-up name: the install must stop there, with the server up, and say so.
+install_until_https() { # evidence-file
+ local status=0
+ "${INSTALL[@]}" --domain "$DOMAIN" >"$1" 2>&1 || status=$?
+ cat "$1"
+ [ "$status" = 1 ] || fail "the install exited $status, not 1"
+ contains "$1" "MausBot is running, but https://$DOMAIN did not answer within 20 seconds" "the install did not end at the certificate"
+ [ "$(sudo docker inspect --format '{{.State.Health.Status}}' "$(cd "$DIR" && sudo docker compose ps -q omb)")" = healthy ] || fail "the server is not healthy"
+ (cd "$DIR" && sudo docker compose exec -T omb curl -sf http://127.0.0.1:8799/api/health) | grep -q openmausbot || fail "the server does not answer inside its container"
+ curl -sS -o /dev/null -w '%{http_code}' --max-time 10 -H "Host: $DOMAIN" http://127.0.0.1/ | grep -qx 308 || fail "Caddy does not redirect port 80 to HTTPS"
+}
+
+step "the checks alone, with a name that points nowhere: one thing to fix, nothing changed"
+status=0
+as_root sh "$ROOT/deploy/install.sh" --check --domain "$DOMAIN" >"$OUT/check.txt" 2>&1 || status=$?
+cat "$OUT/check.txt"
+[ "$status" = 1 ] || fail "--check exited $status, not 1"
+[ "$(grep -c '^ FIX ' "$OUT/check.txt")" = 1 ] || fail "--check found more than the DNS record to fix"
+contains "$OUT/check.txt" " FIX $DOMAIN does not resolve yet." "--check did not name the DNS record"
+for line in "operating system: Ubuntu 24.04" "processor: x86-64" "processor cores:" "memory:" "Docker:" "free disk:" "ports 80 and 443: free" "outbound:" "user namespaces: on" "clock: right" "version:"; do
+ contains "$OUT/check.txt" " ok $line" "--check did not pass: $line"
+done
+[ ! -e "$DIR" ] || fail "--check made $DIR"
+[ -z "$(sudo docker ps -aq)" ] || fail "--check started a container"
+
+step "the checks pass once the DNS record is set aside"
+sudo env OMB_INSTALL_SKIP_DNS=1 sh "$ROOT/deploy/install.sh" --check --domain "$DOMAIN" | tee "$OUT/check-ready.txt"
+contains "$OUT/check-ready.txt" "This server is ready for MausBot. Nothing was changed." "--check did not pass"
+
+step "install: the server is healthy behind Caddy, on a pinned release, with its data in one folder"
+install_until_https "$OUT/install.txt"
+image=$(sudo sed -n 's/^OMB_IMAGE=//p' "$DIR/.env")
+case "$image" in
+ ghcr.io/milind-soni/openmausbot:stable | ghcr.io/milind-soni/openmausbot:v[0-9]*) ;;
+ *) fail "the install pinned $image" ;;
+esac
+[ "$(sudo stat -c %a "$DIR/.env")" = 600 ] || fail ".env is readable by others"
+[ "$(sudo stat -c %a "$DIR/data")" = 700 ] || fail "the data folder is open to others"
+[ "$(sudo stat -c %u "$DIR/data")" = "$(sudo docker run --rm --entrypoint id "$image" -u)" ] || fail "the data folder is not the server's own"
+[ -n "$(sudo ls -A "$DIR/data")" ] || fail "the server did not write its data under $DIR/data"
+
+step "the first admin's sign-in link, made the way the installer says"
+(cd "$DIR" && sudo docker compose exec -T omb openmausbot pair --label "First admin") >"$OUT/pair.txt" 2>&1 || fail "pair failed: $(cat "$OUT/pair.txt")"
+grep -q "https://$DOMAIN/pair#code=" "$OUT/pair.txt" || fail "pair printed no link for $DOMAIN"
+rm -f "$OUT/pair.txt"
+
+step "run again: the same server, the person's settings and data untouched"
+echo "OMB_SERVER_NAME=Installer e2e" | sudo tee -a "$DIR/.env" >/dev/null
+echo kept | sudo tee "$DIR/data/e2e-marker" >/dev/null
+before=$(sudo stat -c '%u:%g:%a' "$DIR/data")
+install_until_https "$OUT/again.txt"
+sudo grep -qx "OMB_SERVER_NAME=Installer e2e" "$DIR/.env" || fail "the second run dropped a setting"
+[ "$(sudo cat "$DIR/data/e2e-marker")" = kept ] || fail "the second run touched the data"
+[ "$(sudo stat -c '%u:%g:%a' "$DIR/data")" = "$before" ] || fail "the second run changed the data folder"
+
+step "uninstall: the server stops, the data stays"
+sudo sh "$ROOT/deploy/install.sh" --uninstall | tee "$OUT/uninstall.txt"
+contains "$OUT/uninstall.txt" "Your data is kept in $DIR/data" "uninstall did not say where the data is"
+[ -z "$(sudo docker ps -aq --filter label=com.docker.compose.project=openmausbot)" ] || fail "uninstall left a container"
+[ "$(sudo cat "$DIR/data/e2e-marker")" = kept ] || fail "uninstall touched the data"
+
+step "install again on the kept data"
+"${INSTALL[@]}" >"$OUT/reinstall.txt" 2>&1 || true
+cat "$OUT/reinstall.txt"
+contains "$OUT/reinstall.txt" "MausBot is running, but https://$DOMAIN did not answer" "the reinstall did not come back up"
+[ "$(sudo cat "$DIR/data/e2e-marker")" = kept ] || fail "the reinstall touched the data"
+
+printf '\nAll steps passed. Evidence: %s\n' "$OUT"
diff --git a/deploy/install.sh b/deploy/install.sh
new file mode 100755
index 0000000000..bf400c4bd5
--- /dev/null
+++ b/deploy/install.sh
@@ -0,0 +1,772 @@
+#!/bin/sh
+# MausBot on a server of your own: checks the server, then installs the MausBot server with HTTPS on your domain.
+# Running it again repairs or updates the install and never touches your data.
+#
+# curl -fsSL https://raw.githubusercontent.com/milind-soni/OpenMausBot/main/deploy/install.sh | sudo sh -s -- --domain maus.example.com
+# ... | sudo sh -s -- --check --domain maus.example.com only checks the server; changes nothing
+# ... | sudo sh -s -- --uninstall stops the server; keeps your data
+# ... | sudo sh -s -- --domain maus.example.com <code> also connects the server to MausBot with a one-time code
+#
+# Nothing runs until the last line calls main, so a download that is cut off part-way runs nothing. It sends no
+# telemetry. The addresses it contacts are the ones the checks name: the image registries, Let's Encrypt, GitHub's
+# release list, and cloudflare.com/cdn-cgi/trace to learn this server's public address.
+set -eu
+
+settings() {
+ SYSROOT="${OMB_INSTALL_SYSROOT:-}"
+ INSTALL_DIR="${OMB_INSTALL_DIR:-/opt/openmausbot}"
+ IMAGE_REPO=milind-soni/openmausbot
+ RELEASES_URL=https://api.github.com/repos/milind-soni/OpenMausBot/releases/latest
+ ADMIN_URL="${MAUSBOT_ADMIN_URL:-https://cloud.openmausbot.com}"
+ SCRIPT_URL=https://raw.githubusercontent.com/milind-soni/OpenMausBot/main/deploy/install.sh
+ PROJECT=openmausbot
+ MIN_DOCKER=24
+ MIN_CPUS=2
+ MIN_MEMORY_MB=3500
+ MIN_DISK_GB=20
+ MAX_CLOCK_SKEW_S=300
+ HEALTH_WAIT_S="${OMB_INSTALL_HEALTH_WAIT_S:-240}"
+ HTTPS_WAIT_S="${OMB_INSTALL_HTTPS_WAIT_S:-180}"
+
+ MODE=install
+ DOMAIN=""
+ EMAIL=""
+ CODE=""
+ INSTALL_DOCKER="${OMB_INSTALL_DOCKER:-}"
+ FAILED=0
+ DOCKER_STATE=unknown
+ DOCKER_PROBLEM=""
+ IMAGE=""
+ PUBLIC_IP=""
+}
+
+say() { printf '%s\n' "$*"; }
+fail() {
+ printf '\n%s\n' "$*" >&2
+ exit 1
+}
+ok() { printf ' ok %s\n' "$*"; }
+note() { printf ' note %s\n' "$*"; }
+fix() {
+ printf ' FIX %s\n' "$*"
+ FAILED=$((FAILED + 1))
+}
+
+command_line() { # what to run again, as the person ran it
+ printf 'curl -fsSL %s | sudo sh -s -- %s' "$SCRIPT_URL" "$*"
+}
+
+usage() {
+ say "Usage: $(command_line '--domain maus.example.com')"
+ say " $(command_line '--check --domain maus.example.com') only checks this server; changes nothing"
+ say " $(command_line '--uninstall') stops the server; keeps your data"
+ say ""
+ say " --domain NAME the name people will open, already pointing at this server"
+ say " --email ADDRESS the first admin's email, so they can sign in with an emailed code"
+ say " --install-docker install Docker with Docker's official script when it is missing, without asking"
+ say " --dir PATH where the install lives (default /opt/openmausbot)"
+ say " <code> the one-time code MausBot shows, to also connect this server to MausBot"
+}
+
+parse() {
+ while [ $# -gt 0 ]; do
+ case "$1" in
+ --check) MODE=check ;;
+ --uninstall) MODE=uninstall ;;
+ --install-docker) INSTALL_DOCKER=1 ;;
+ --domain | --email | --dir)
+ [ $# -ge 2 ] || fail "$1 needs a value. $(usage)"
+ case "$1" in
+ --domain) DOMAIN=$2 ;;
+ --email) EMAIL=$2 ;;
+ --dir) INSTALL_DIR=$2 ;;
+ esac
+ shift
+ ;;
+ --domain=*) DOMAIN=${1#--domain=} ;;
+ --email=*) EMAIL=${1#--email=} ;;
+ --dir=*) INSTALL_DIR=${1#--dir=} ;;
+ -h | --help)
+ usage
+ exit 0
+ ;;
+ -*) fail "Unknown option $1. $(usage)" ;;
+ *) CODE=$1 ;;
+ esac
+ shift
+ done
+ DOMAIN=$(printf '%s' "$DOMAIN" | tr '[:upper:]' '[:lower:]')
+ case "$DOMAIN" in
+ "") ;;
+ *[!a-z0-9.-]* | .* | *. | -* | *..*) fail "$DOMAIN is not a domain name. Give the name alone, like maus.example.com, without https:// or a path." ;;
+ *.*) ;;
+ *) fail "$DOMAIN is not a full domain name. Give a name like maus.example.com." ;;
+ esac
+ case "$EMAIL" in
+ "") ;;
+ *[!A-Za-z0-9@._+-]* | *@*@*) fail "That email address doesn't look right. Give one address, like [email protected]." ;;
+ ?*@?*.?*) ;;
+ *) fail "That email address doesn't look right. Give one address, like [email protected]." ;;
+ esac
+ case "$CODE" in
+ *[!A-Za-z0-9-]*) fail "That code doesn't look right. Copy the install command from MausBot again." ;;
+ esac
+ case "$INSTALL_DIR" in
+ /?*) ;;
+ *) fail "--dir needs a full path, like /opt/openmausbot." ;;
+ esac
+ case "$INSTALL_DIR" in
+ *[!A-Za-z0-9/._-]*) fail "--dir may hold only letters, digits, / . _ and -." ;;
+ esac
+}
+
+is_root() { [ "$(id -u)" = 0 ]; }
+
+need_root() {
+ is_root || fail "Please run this as root: put sudo before sh, like this: $(command_line "$@")"
+}
+
+tty_available() {
+ [ -t 1 ] || return 1
+ (exec </dev/tty) 2>/dev/null
+}
+
+compose() {
+ docker compose --project-directory "$INSTALL_DIR" -f "$INSTALL_DIR/compose.yaml" "$@"
+}
+
+env_value() { # name: its value in the install's .env, or nothing
+ [ -r "$INSTALL_DIR/.env" ] || return 0
+ sed -n "s/^$1=//p" "$INSTALL_DIR/.env" | tail -n 1
+}
+
+reachable() { # url: any HTTP answer counts
+ curl -sS -o /dev/null --max-time 15 "$1" >/dev/null 2>&1
+}
+
+host_of() { printf '%s' "$1" | sed -e 's#^[a-z]*://##' -e 's#/.*##'; }
+
+# The checks. Each one that fails prints one sentence saying what to fix, and none of them changes anything.
+
+check_tools() {
+ command -v curl >/dev/null 2>&1 || fix "curl isn't installed. Run: sudo apt-get install -y curl and then run this again."
+}
+
+check_os() {
+ release="$SYSROOT/etc/os-release"
+ if [ ! -r "$release" ]; then
+ fix "This server's operating system can't be identified. MausBot's installer runs on Ubuntu 22.04 or 24.04: pick one of those."
+ return
+ fi
+ field() { sed -n "s/^$1=//p" "$release" | head -n 1 | tr -d '"'; }
+ os_id=$(field ID)
+ os_version=$(field VERSION_ID)
+ os_name=$(field PRETTY_NAME)
+ [ -n "$os_name" ] || os_name="$os_id $os_version"
+ case "$os_id $os_version" in
+ "ubuntu 22.04" | "ubuntu 24.04") ok "operating system: $os_name" ;;
+ *)
+ if [ "${OMB_INSTALL_ALLOW_UNTESTED_OS:-}" = 1 ]; then
+ note "This server runs $os_name, which the installer is not tested on; going on as asked."
+ else
+ fix "This server runs $os_name. MausBot's installer runs on Ubuntu 22.04 or 24.04: pick one of those, or run again with OMB_INSTALL_ALLOW_UNTESTED_OS=1 to try anyway."
+ fi
+ ;;
+ esac
+}
+
+check_arch() {
+ arch=$(uname -m)
+ if [ "$arch" = x86_64 ]; then
+ ok "processor: x86-64"
+ else
+ fix "This server's processor is $arch. The installer supports Intel and AMD (x86-64) servers for now: pick an x86-64 server."
+ fi
+}
+
+check_cpus() {
+ cpus=$(nproc 2>/dev/null || echo 0)
+ case "$cpus" in '' | *[!0-9]*) cpus=0 ;; esac
+ if [ "$cpus" -ge "$MIN_CPUS" ]; then
+ ok "processor cores: $cpus"
+ else
+ fix "This server has $cpus processor core. MausBot needs at least $MIN_CPUS: pick a bigger server."
+ fi
+}
+
+check_memory() {
+ memory_mb=$(awk '/^MemTotal:/ { print int($2 / 1024) }' "$SYSROOT/proc/meminfo" 2>/dev/null || true)
+ case "$memory_mb" in '' | *[!0-9]*) memory_mb=0 ;; esac
+ memory_gb=$(awk -v m="$memory_mb" 'BEGIN { printf "%.1f", m / 1024 }')
+ if [ "$memory_mb" -lt "$MIN_MEMORY_MB" ]; then
+ fix "This server has $memory_gb GB of memory. MausBot needs at least 4 GB: pick a bigger server."
+ return
+ fi
+ ok "memory: $memory_gb GB"
+ if [ "$memory_mb" -lt 7500 ]; then note "With $memory_gb GB of memory, bots will be slow when several work at once. We suggest at least 8 GB."; fi
+}
+
+existing_parent() {
+ path=$1
+ while [ ! -d "$path" ]; do path=$(dirname "$path"); done
+ printf '%s' "$path"
+}
+
+free_gb() { df -Pk "$1" 2>/dev/null | awk 'NR == 2 { print int($4 / 1048576) }'; }
+
+check_disk() {
+ places=$(existing_parent "$INSTALL_DIR")
+ if [ "$DOCKER_STATE" = ready ]; then
+ docker_root=$(docker info --format '{{.DockerRootDir}}' 2>/dev/null || true)
+ if [ -n "$docker_root" ] && [ -d "$docker_root" ]; then places="$places $docker_root"; fi
+ fi
+ least=""
+ for place in $places; do
+ free=$(free_gb "$place")
+ case "$free" in '' | *[!0-9]*) free=0 ;; esac
+ if [ -z "$least" ] || [ "$free" -lt "$least" ]; then
+ least=$free
+ least_place=$place
+ fi
+ done
+ if [ "$least" -ge "$MIN_DISK_GB" ]; then
+ ok "free disk: $least GB"
+ else
+ fix "This server has only $least GB free at $least_place. MausBot needs at least $MIN_DISK_GB GB: free some space or add a disk."
+ fi
+}
+
+# DOCKER_STATE: ready, or missing (the one thing the installer offers to install), or broken (the person fixes it).
+check_docker() {
+ DOCKER_PROBLEM=""
+ if ! command -v docker >/dev/null 2>&1; then
+ DOCKER_STATE=missing
+ DOCKER_PROBLEM="Docker isn't installed."
+ return
+ fi
+ DOCKER_STATE=broken
+ server=$(docker version --format '{{.Server.Version}}' 2>/dev/null || true)
+ if [ -z "$server" ]; then
+ if is_root; then
+ fix "Docker is installed but not running. Start it with: sudo systemctl enable --now docker and then run this again."
+ else
+ fix "Docker did not answer. Run this with sudo, or start Docker with: sudo systemctl enable --now docker"
+ fi
+ return
+ fi
+ major=${server%%.*}
+ case "$major" in '' | *[!0-9]*) major=0 ;; esac
+ if [ "$major" -lt "$MIN_DOCKER" ]; then
+ fix "Docker $server is too old; MausBot needs Docker $MIN_DOCKER or newer. Update it with: curl -fsSL https://get.docker.com | sudo sh and then run this again."
+ return
+ fi
+ security=$(docker info --format '{{json .SecurityOptions}}' 2>/dev/null || true)
+ case "$security" in
+ *rootless*)
+ fix "Docker runs in rootless mode here. MausBot needs the standard Docker service: run curl -fsSL https://get.docker.com | sudo sh and then run this again."
+ return
+ ;;
+ esac
+ if ! docker compose version >/dev/null 2>&1; then
+ fix "Docker is here without its Compose plugin. Run: sudo apt-get install -y docker-compose-plugin and then run this again."
+ return
+ fi
+ DOCKER_STATE=ready
+ ok "Docker: $server, with Compose"
+}
+
+report_docker_missing() {
+ if [ "$DOCKER_STATE" = missing ]; then
+ fix "$DOCKER_PROBLEM Run this again with --install-docker to install it with Docker's official script, or install it yourself with: curl -fsSL https://get.docker.com | sudo sh"
+ fi
+}
+
+listener_on() { # port: the listening line, or nothing
+ ss -Hltnp "sport = :$1" 2>/dev/null | head -n 1
+}
+
+check_ports() {
+ if ! command -v ss >/dev/null 2>&1; then
+ note "Ports 80 and 443 could not be checked because the ss tool is missing; if something else uses them, the install will say so."
+ return
+ fi
+ busy=""
+ for port in 80 443; do
+ line=$(listener_on "$port")
+ [ -n "$line" ] || continue
+ if [ "$DOCKER_STATE" = ready ] && [ -n "$(docker ps -q --filter "label=com.docker.compose.project=$PROJECT" --filter "publish=$port" 2>/dev/null)" ]; then continue; fi
+ owner=$(printf '%s' "$line" | sed -n 's/.*users:(("\([^"]*\)".*/\1/p')
+ if [ "$owner" = docker-proxy ]; then
+ fix "Port $port is already in use by another Docker container. Find it with: sudo docker ps and stop it, then run this again."
+ else
+ fix "Port $port is already in use${owner:+ by $owner}. Stop what uses it${owner:+ (for example: sudo systemctl disable --now $owner)}, then run this again."
+ fi
+ busy=yes
+ done
+ [ -n "$busy" ] || ok "ports 80 and 443: free"
+}
+
+public_address() {
+ curl -4 -fsS --max-time 10 https://cloudflare.com/cdn-cgi/trace 2>/dev/null | sed -n 's/^ip=//p' | head -n 1
+}
+
+local_addresses() {
+ ip -o -4 addr show scope global 2>/dev/null | awk '{ print $4 }' | cut -d/ -f1
+}
+
+check_dns() {
+ if [ -z "$DOMAIN" ]; then
+ note "No --domain was given, so its DNS record was not checked."
+ return
+ fi
+ if [ "${OMB_INSTALL_SKIP_DNS:-}" = 1 ]; then
+ note "The DNS record of $DOMAIN was not checked, as asked."
+ return
+ fi
+ PUBLIC_IP=$(public_address || true)
+ resolved=$(getent ahostsv4 "$DOMAIN" 2>/dev/null | awk '{ print $1 }' | sort -u | tr '\n' ' ' || true)
+ resolved=${resolved% }
+ target=${PUBLIC_IP:-this server\'s public address}
+ if [ -z "$resolved" ]; then
+ fix "$DOMAIN does not resolve yet. Add an A record for it pointing at $target at your DNS provider, wait a few minutes, then run this again."
+ return
+ fi
+ for address in $resolved; do
+ for mine in $PUBLIC_IP $(local_addresses); do
+ if [ "$address" = "$mine" ]; then
+ ok "DNS: $DOMAIN points at this server ($address)"
+ return
+ fi
+ done
+ done
+ fix "$DOMAIN points at $resolved, not at this server ($target). Change its A record to $target (on Cloudflare, set the record to DNS only), then run this again; or set OMB_INSTALL_SKIP_DNS=1 if a load balancer forwards ports 80 and 443 here."
+}
+
+check_outbound() {
+ targets="https://ghcr.io/v2/ https://pkg-containers.githubusercontent.com/ https://registry-1.docker.io/v2/ https://auth.docker.io/ https://production.cloudflare.docker.com/ https://acme-v02.api.letsencrypt.org/directory"
+ if [ "$DOCKER_STATE" = missing ]; then targets="$targets https://get.docker.com/ https://download.docker.com/"; fi
+ if [ -n "$CODE" ]; then targets="$targets $ADMIN_URL/"; fi
+ blocked=""
+ for url in $targets; do
+ reachable "$url" || blocked="$blocked $(host_of "$url")"
+ done
+ if [ -n "$blocked" ]; then
+ if [ -n "${https_proxy:-}${HTTPS_PROXY:-}" ]; then
+ fix "This server reaches the internet only through a web proxy, which the installer can't use. It needs direct outbound HTTPS (port 443) to:$blocked"
+ else
+ fix "This server can't reach$blocked over HTTPS (port 443). Allow outbound HTTPS to them in your firewall, then run this again."
+ fi
+ return
+ fi
+ ok "outbound: the image registries and Let's Encrypt are reachable"
+ if ! reachable https://accounts.openmausbot.com/; then
+ note "accounts.openmausbot.com is not reachable, so signing in with an emailed code needs a mail server of your own (OMB_SIGNIN_SMTP_URL). Pairing codes work without it."
+ fi
+}
+
+check_userns() {
+ max=$(cat "$SYSROOT/proc/sys/user/max_user_namespaces" 2>/dev/null || echo 1)
+ clone=$(cat "$SYSROOT/proc/sys/kernel/unprivileged_userns_clone" 2>/dev/null || echo 1)
+ if [ "$max" = 0 ] || [ "$clone" != 1 ]; then
+ fix "This server switches off user namespaces, which the bots' sandbox needs. Run: printf 'user.max_user_namespaces=63000\\nkernel.unprivileged_userns_clone=1\\n' | sudo tee /etc/sysctl.d/90-mausbot.conf && sudo sysctl --system and then run this again."
+ else
+ ok "user namespaces: on"
+ fi
+}
+
+check_clock() {
+ now=$(date -u +%s)
+ theirs=""
+ header=$(curl -sSI --max-time 15 https://ghcr.io/v2/ 2>/dev/null | tr -d '\r' | sed -n 's/^[Dd]ate: //p' | head -n 1 || true)
+ if [ -n "$header" ]; then theirs=$(date -u -d "$header" +%s 2>/dev/null || true); fi
+ case "$theirs" in '' | *[!0-9]*) theirs="" ;; esac
+ if [ -z "$theirs" ]; then
+ if [ "$(date -u +%Y)" -lt 2025 ]; then
+ fix "This server's clock says $(date -u +%Y), so HTTPS certificates will be refused. Run: sudo timedatectl set-ntp true and then run this again."
+ else
+ note "The clock could not be compared with the internet's; it says $(date -u '+%Y-%m-%d %H:%M') UTC."
+ fi
+ return
+ fi
+ skew=$((now - theirs))
+ [ "$skew" -ge 0 ] || skew=$((-skew))
+ if [ "$skew" -gt "$MAX_CLOCK_SKEW_S" ]; then
+ fix "This server's clock is $((skew / 60)) minutes off, so HTTPS certificates will be refused. Run: sudo timedatectl set-ntp true and then run this again."
+ return
+ fi
+ ok "clock: right"
+ if command -v timedatectl >/dev/null 2>&1 && [ "$(timedatectl show -p NTPSynchronized --value 2>/dev/null || echo yes)" != yes ]; then
+ note "This server's clock is not kept in time. Run: sudo timedatectl set-ntp true"
+ fi
+}
+
+registry_has() { # tag: 0 when the image has it, 1 when it does not, 2 when the registry could not be asked
+ token=$(curl -fsS --max-time 15 "https://ghcr.io/token?scope=repository:$IMAGE_REPO:pull" 2>/dev/null | sed -n 's/.*"token":"\([^"]*\)".*/\1/p' || true)
+ [ -n "$token" ] || return 2
+ # The pull token goes to curl on its standard input, never on a command line.
+ status=$(printf 'header = "Authorization: Bearer %s"\n' "$token" | curl -K - -s -o /dev/null -w '%{http_code}' --max-time 15 -I \
+ -H "Accept: application/vnd.oci.image.index.v1+json, application/vnd.docker.distribution.manifest.list.v2+json, application/vnd.oci.image.manifest.v1+json, application/vnd.docker.distribution.manifest.v2+json" \
+ "https://ghcr.io/v2/$IMAGE_REPO/manifests/$1" 2>/dev/null || true)
+ case "$status" in
+ 200) return 0 ;;
+ 404) return 1 ;;
+ *) return 2 ;;
+ esac
+}
+
+newest_release() {
+ curl -fsS --max-time 15 "$RELEASES_URL" 2>/dev/null | sed -n 's/.*"tag_name": *"\(v[0-9][0-9.]*\)".*/\1/p' | head -n 1
+}
+
+# The stable channel when it is published, else the newest release. Never `latest`, which follows every commit.
+check_version() {
+ chosen="${OMB_INSTALL_IMAGE:-}"
+ if [ -n "$chosen" ]; then
+ case "$chosen" in
+ *[!A-Za-z0-9/:._@-]*)
+ fix "OMB_INSTALL_IMAGE is not an image name."
+ return
+ ;;
+ esac
+ case "${chosen##*/}" in
+ *:latest) fix "OMB_INSTALL_IMAGE names the latest tag, which follows every commit. Name a release, like ghcr.io/$IMAGE_REPO:v0.1.151." ;;
+ *:?*)
+ IMAGE=$chosen
+ ok "version: $IMAGE, as asked"
+ ;;
+ *) fix "OMB_INSTALL_IMAGE needs a release tag, like ghcr.io/$IMAGE_REPO:v0.1.151." ;;
+ esac
+ return
+ fi
+ asked=0
+ registry_has stable || asked=$?
+ if [ "$asked" = 0 ]; then
+ IMAGE="ghcr.io/$IMAGE_REPO:stable"
+ ok "version: the stable channel"
+ return
+ fi
+ if [ "$asked" = 2 ]; then
+ fix "The image registry ghcr.io did not answer, so the version to install is unknown. Check this server's outbound HTTPS, then run this again."
+ return
+ fi
+ release=$(newest_release || true)
+ if [ -z "$release" ]; then
+ fix "The newest MausBot release could not be read from api.github.com. Check this server's outbound HTTPS, then run this again in a few minutes."
+ return
+ fi
+ asked=0
+ registry_has "$release" || asked=$?
+ if [ "$asked" != 0 ]; then
+ fix "MausBot $release has no server image yet. Run this again in a few minutes."
+ return
+ fi
+ IMAGE="ghcr.io/$IMAGE_REPO:$release"
+ ok "version: $release, the newest release"
+}
+
+preflight() {
+ say "Checking this server..."
+ check_tools
+ check_os
+ check_arch
+ check_cpus
+ check_memory
+ check_docker
+ check_disk
+ check_ports
+ check_dns
+ check_outbound
+ check_userns
+ check_clock
+ check_version
+}
+
+install_docker() {
+ say "Installing Docker with Docker's official script (get.docker.com)..."
+ tmp_docker=$(mktemp)
+ curl -fsSL https://get.docker.com -o "$tmp_docker" || fail "Docker's install script could not be downloaded. Check that this server can reach https://get.docker.com, then run this again."
+ sh "$tmp_docker" || fail "Docker's install script failed (its output is above). Fix that, then run this again."
+ rm -f "$tmp_docker"
+ if command -v systemctl >/dev/null 2>&1; then systemctl enable --now docker >/dev/null 2>&1 || true; fi
+}
+
+# Docker is the one thing the installer installs for you, and only when you say so: the flag, or yes at the prompt.
+offer_docker() {
+ if [ "$INSTALL_DOCKER" != 1 ]; then
+ answer=n
+ if tty_available; then
+ printf "%s Install the current Docker now with Docker's official script (get.docker.com)? [Y/n] " "$DOCKER_PROBLEM" >/dev/tty
+ read -r answer </dev/tty || answer=n
+ fi
+ case "$answer" in
+ "" | y | Y | yes | Yes) ;;
+ *) fail "$DOCKER_PROBLEM Install it with: curl -fsSL https://get.docker.com | sudo sh and then run this again, or run this again with --install-docker." ;;
+ esac
+ fi
+ install_docker
+ FAILED=0
+ check_docker
+ report_docker_missing
+ [ "$FAILED" = 0 ] || fail "Docker still isn't usable after its install. Fix the line above, then run this again."
+}
+
+write_file() { # path, with the content on standard input: replaced in one step
+ tmp_file=$(mktemp "$1.XXXXXX")
+ cat >"$tmp_file"
+ chmod "${2:-644}" "$tmp_file"
+ mv "$tmp_file" "$1"
+}
+
+write_compose() {
+ write_file "$INSTALL_DIR/compose.yaml" <<'COMPOSE'
+# Written by MausBot's installer (deploy/install.sh), and written again each time it runs: put your own settings in
+# .env beside this file, which the installer keeps. Caddy shares the server's network, so the server itself only
+# listens on loopback.
+name: openmausbot
+services:
+ omb:
+ image: ${OMB_IMAGE:?run the installer again}
+ restart: unless-stopped
+ init: true
+ shm_size: 512m
+ volumes:
+ - ./data:/data
+ ports:
+ - "80:80"
+ - "443:443"
+ environment:
+ OMB_PORT: "8799"
+ OMB_WEBHOOK_PORT: "8800"
+ OMB_WEBHOOK_PUBLIC_URL: https://${DOMAIN}
+ OMB_PUBLIC_URL: https://${DOMAIN}
+ OMB_SERVER_NAME: ${OMB_SERVER_NAME:-${DOMAIN}}
+ OMB_SIGNIN_EMAILS: ${OMB_SIGNIN_EMAILS:-}
+ OMB_SIGNIN_MEMBER_EMAILS: ${OMB_SIGNIN_MEMBER_EMAILS:-}
+ OMB_SIGNIN_SMTP_URL: ${OMB_SIGNIN_SMTP_URL:-}
+ OMB_SIGNIN_SMTP_FROM: ${OMB_SIGNIN_SMTP_FROM:-}
+ healthcheck:
+ test: ["CMD-SHELL", "curl -sf http://127.0.0.1:8799/api/health | grep -q openmausbot"]
+ interval: 30s
+ timeout: 5s
+ retries: 3
+
+ caddy:
+ image: caddy:2
+ restart: unless-stopped
+ network_mode: "service:omb"
+ depends_on:
+ omb:
+ condition: service_healthy
+ environment:
+ DOMAIN: ${DOMAIN}
+ volumes:
+ - ./Caddyfile:/etc/caddy/Caddyfile:ro
+ - ./caddy/data:/data
+ - ./caddy/config:/config
+COMPOSE
+}
+
+write_caddyfile() {
+ write_file "$INSTALL_DIR/Caddyfile" <<'CADDY'
+{$DOMAIN} {
+ encode zstd gzip
+
+ # Webhook ingress is designed to be reachable by third parties (it has its
+ # own per-hook secrets), so it sits outside any login. The path is passed
+ # through unchanged: the receiver routes on /hooks/<id>.
+ handle /hooks/* {
+ reverse_proxy 127.0.0.1:8800
+ }
+
+ handle {
+ # Optional second wall in front of pairing (a shared password):
+ # basic_auth {
+ # {$BASIC_AUTH_USER} {$BASIC_AUTH_HASH}
+ # }
+ # and set both variables in .env (hash with `caddy hash-password`,
+ # every `$` doubled for Compose).
+ reverse_proxy 127.0.0.1:8799 {
+ # SSE: stream events as they arrive
+ flush_interval -1
+ }
+ }
+}
+CADDY
+}
+
+set_env() { # name value: that one line of .env, leaving every other line as the person wrote it
+ env_file="$INSTALL_DIR/.env"
+ {
+ if [ -f "$env_file" ]; then grep -v "^$1=" "$env_file" || true; fi
+ printf '%s=%s\n' "$1" "$2"
+ } | write_file "$env_file" 600
+}
+
+write_settings() {
+ if [ ! -f "$INSTALL_DIR/.env" ]; then
+ write_file "$INSTALL_DIR/.env" 600 <<'ENV'
+# MausBot's settings on this server. The installer sets DOMAIN and OMB_IMAGE and keeps every other line.
+# Who may sign in with an emailed code: OMB_SIGNIN_EMAILS (admins) and OMB_SIGNIN_MEMBER_EMAILS, comma-separated.
+ENV
+ fi
+ set_env DOMAIN "$DOMAIN"
+ set_env OMB_IMAGE "$IMAGE"
+ if [ -n "$EMAIL" ]; then
+ current=$(env_value OMB_SIGNIN_EMAILS)
+ case ",$(printf '%s' "$current" | tr -d ' ')," in
+ *",$EMAIL,"*) ;;
+ *) set_env OMB_SIGNIN_EMAILS "${current:+$current,}$EMAIL" ;;
+ esac
+ fi
+}
+
+# A new data folder is handed to the user the image runs as. A folder that already exists is never touched.
+prepare_data() {
+ if [ -d "$INSTALL_DIR/data" ]; then return; fi
+ owner=$(docker run --rm --network none --entrypoint id "$IMAGE" -u 2>/dev/null || true)
+ group=$(docker run --rm --network none --entrypoint id "$IMAGE" -g 2>/dev/null || true)
+ case "$owner:$group" in
+ *[!0-9:]* | : | :* | *:) fail "The MausBot image did not say which user it runs as. Run this again; if it still fails, send us this line." ;;
+ esac
+ mkdir -m 700 "$INSTALL_DIR/data"
+ chown "$owner:$group" "$INSTALL_DIR/data"
+}
+
+wait_healthy() {
+ waited=0
+ while [ "$waited" -lt "$HEALTH_WAIT_S" ]; do
+ container=$(compose ps -q omb 2>/dev/null | head -n 1 || true)
+ if [ -n "$container" ] && [ "$(docker inspect --format '{{.State.Health.Status}}' "$container" 2>/dev/null || true)" = healthy ]; then return 0; fi
+ sleep 5
+ waited=$((waited + 5))
+ done
+ return 1
+}
+
+https_answers() {
+ curl -fsS --max-time 10 --resolve "$DOMAIN:443:127.0.0.1" "https://$DOMAIN/api/health" 2>/dev/null | grep -q openmausbot
+}
+
+wait_https() {
+ waited=0
+ while [ "$waited" -lt "$HTTPS_WAIT_S" ]; do
+ if https_answers; then return 0; fi
+ sleep 5
+ waited=$((waited + 5))
+ done
+ return 1
+}
+
+install_server() {
+ say ""
+ say "Installing MausBot in $INSTALL_DIR..."
+ mkdir -p "$INSTALL_DIR" "$INSTALL_DIR/caddy/data" "$INSTALL_DIR/caddy/config"
+ write_compose
+ write_caddyfile
+ write_settings
+ say "Downloading MausBot (${IMAGE##*:})..."
+ compose pull -q || fail "MausBot could not be downloaded (Docker's message is above). Check this server's outbound HTTPS, then run this again."
+ prepare_data
+ say "Starting MausBot..."
+ compose up -d --remove-orphans >/dev/null || fail "MausBot could not be started (Docker's message is above). Fix that, then run this again."
+ wait_healthy || fail "MausBot started but did not report healthy within $HEALTH_WAIT_S seconds. Its log: cd $INSTALL_DIR && sudo docker compose logs omb --tail 50"
+ say "Waiting for the HTTPS certificate of $DOMAIN..."
+ wait_https || fail "MausBot is running, but https://$DOMAIN did not answer within $HTTPS_WAIT_S seconds, usually because the certificate could not be issued. Check that $DOMAIN points at this server and that ports 80 and 443 are open in your provider's firewall, then run this again. Caddy's reason: cd $INSTALL_DIR && sudo docker compose logs caddy --tail 30"
+}
+
+# The connector has its own installer, which MausBot serves with its address and the connector's image filled in.
+# It is run as it is, with the code.
+connect_server() {
+ say ""
+ say "Connecting this server to MausBot..."
+ connector_script="${MAUSBOT_CONNECTOR_INSTALLER:-}"
+ fetched=""
+ if [ -z "$connector_script" ]; then
+ fetched=$(mktemp)
+ connector_script=$fetched
+ if ! curl -fsSL --max-time 60 "$ADMIN_URL/install.sh" -o "$connector_script"; then
+ rm -f "$fetched"
+ fail "MausBot is installed and running here, but the connector's installer could not be downloaded from $ADMIN_URL. Nothing needs reinstalling: run this again with your code once that address answers."
+ fi
+ fi
+ if ! grep -q 'mausbot-connector' "$connector_script" 2>/dev/null; then
+ [ -z "$fetched" ] || rm -f "$fetched"
+ fail "MausBot is installed and running here, but what $ADMIN_URL sent is not the connector's installer. Nothing needs reinstalling: copy the install command from MausBot again."
+ fi
+ status=0
+ if [ "$INSTALL_DOCKER" = 1 ]; then
+ MAUSBOT_ADMIN_URL="$ADMIN_URL" sh "$connector_script" --install-docker "$CODE" || status=$?
+ else
+ MAUSBOT_ADMIN_URL="$ADMIN_URL" sh "$connector_script" "$CODE" || status=$?
+ fi
+ [ -z "$fetched" ] || rm -f "$fetched"
+ [ "$status" = 0 ] || fail "MausBot is installed and running here, but connecting it did not finish (the reason is above). Nothing needs reinstalling: fix that and run this again with a new code."
+}
+
+finish() {
+ say ""
+ say "MausBot is running at https://$DOMAIN"
+ say ""
+ say "To sign in as the first admin, make a one-time link on this server and open it in your browser:"
+ say " cd $INSTALL_DIR && sudo docker compose exec omb openmausbot pair --label \"First admin\""
+ admins=$(env_value OMB_SIGNIN_EMAILS)
+ if [ -n "$admins" ]; then
+ say "Or open https://$DOMAIN/pair and sign in with an emailed code as: $admins"
+ fi
+ say ""
+ say "Settings: $INSTALL_DIR/.env Your data: $INSTALL_DIR/data Run this command again to update or repair."
+}
+
+run_install() {
+ need_root "--domain ${DOMAIN:-maus.example.com}"
+ if [ -z "$DOMAIN" ]; then DOMAIN=$(env_value DOMAIN); fi
+ [ -n "$DOMAIN" ] || fail "Say which name people will open, like this: $(command_line '--domain maus.example.com')"
+ preflight
+ if [ "$FAILED" != 0 ]; then
+ report_docker_missing
+ fail "This server is not ready: fix the $FAILED line(s) marked FIX above, then run this again. Nothing was changed."
+ fi
+ if [ "$DOCKER_STATE" = missing ]; then offer_docker; fi
+ install_server
+ if [ -n "$CODE" ]; then connect_server; fi
+ finish
+}
+
+run_check() {
+ if [ -z "$DOMAIN" ]; then DOMAIN=$(env_value DOMAIN); fi
+ preflight
+ report_docker_missing
+ if [ "$FAILED" != 0 ]; then
+ fail "This server is not ready: fix the $FAILED line(s) marked FIX above. Nothing was changed."
+ fi
+ say ""
+ say "This server is ready for MausBot. Nothing was changed."
+}
+
+# Stops the server and removes its containers. The data, the settings and the certificates stay where they are.
+run_uninstall() {
+ need_root --uninstall
+ [ -f "$INSTALL_DIR/compose.yaml" ] || fail "MausBot isn't installed in $INSTALL_DIR, so there is nothing to stop."
+ command -v docker >/dev/null 2>&1 || fail "Docker isn't installed here, so MausBot isn't running. Your data is in $INSTALL_DIR/data."
+ say "Stopping MausBot..."
+ compose down --remove-orphans >/dev/null || fail "MausBot could not be stopped (Docker's message is above)."
+ say "MausBot is stopped and its containers are removed."
+ say "Your data is kept in $INSTALL_DIR/data, your settings in $INSTALL_DIR/.env and the HTTPS certificates in $INSTALL_DIR/caddy."
+ say "To start it again: $(command_line "--domain $(env_value DOMAIN)")"
+ say "This command never deletes your data. To delete it yourself: sudo rm -rf $INSTALL_DIR"
+ if [ -n "$(docker ps -aq --filter name=mausbot-connector 2>/dev/null || true)" ]; then
+ say "This server is still connected to MausBot. To disconnect it, run the uninstall command MausBot shows for the connector."
+ fi
+}
+
+main() {
+ settings
+ parse "$@"
+ case "$MODE" in
+ check) run_check ;;
+ uninstall) run_uninstall ;;
+ *) run_install ;;
+ esac
+}
+
+main "$@"
diff --git a/docs/deploy-vps.md b/docs/deploy-vps.md
index 4ec5e9eb25..251d7d72eb 100644
--- a/docs/deploy-vps.md
+++ b/docs/deploy-vps.md
@@ -2,6 +2,71 @@
From a blank Linux server to OpenMausBot running on it around the clock, reachable from your laptop, the desktop app and your phone, with your bots working while every laptop is closed. It assumes nothing beyond being able to open a terminal and paste commands. About twenty minutes, most of it waiting.
+## Quick start: one command on your own domain
+
+For a fresh Ubuntu 22.04 or 24.04 server (x86-64, at least 2 CPUs, 4 GB of memory and 20 GB of free disk) and a domain name whose A record already points at it:
+
+```sh
+curl -fsSL https://raw.githubusercontent.com/milind-soni/OpenMausBot/main/deploy/install.sh | sudo sh -s -- --domain maus.example.com
+```
+
+The installer ([`deploy/install.sh`](https://github.com/milind-soni/OpenMausBot/blob/main/deploy/install.sh)) does path B below for you and ends with MausBot answering at `https://maus.example.com`.
+
+**It checks the server first, and changes nothing while it checks.** Each check that fails prints one sentence saying what to fix, and nothing is installed until all pass:
+
+| Check | Passes when |
+|---|---|
+| Operating system | Ubuntu 22.04 or 24.04 |
+| Processor | x86-64, 2 cores or more |
+| Memory | 4 GB or more (8 GB suggested) |
+| Free disk | 20 GB or more, where the install and Docker keep their files |
+| Docker | Docker 24 or newer with the Compose plugin, running, not rootless |
+| Ports | 80 and 443 are free |
+| DNS | the domain resolves to this server's public address |
+| Outbound | HTTPS reaches the image registries (`ghcr.io`, `pkg-containers.githubusercontent.com`, Docker Hub) and Let's Encrypt |
+| User namespaces | switched on, for the bots' sandbox |
+| Clock | within five minutes of the internet's |
+| Version | a MausBot release to install was found |
+
+To run only the checks, add `--check`:
+
+```sh
+curl -fsSL https://raw.githubusercontent.com/milind-soni/OpenMausBot/main/deploy/install.sh | sudo sh -s -- --check --domain maus.example.com
+```
+
+If Docker is missing, the installer asks before installing it with Docker's official script (`get.docker.com`); `--install-docker` says yes ahead of time. It installs nothing else on the server.
+
+**Then it installs** everything under one folder, `/opt/openmausbot` (`--dir` picks another):
+
+| Path | What |
+|---|---|
+| `compose.yaml`, `Caddyfile` | the same server-plus-Caddy setup as path B; written again on every run |
+| `.env` | your settings: `DOMAIN`, the pinned version (`OMB_IMAGE`) and anything you add, such as [who may sign in with an email](self-hosting.md#sign-in-with-your-email). The installer keeps your lines |
+| `data/` | everything MausBot stores: chats, bots, engine sign-ins, paired devices. Never touched once it exists |
+| `caddy/` | the HTTPS certificates |
+
+It runs the newest release, pinned by its version; once a `stable` channel is published it follows that instead. It never runs `latest`, which follows every commit. It then waits until the server reports healthy and `https://maus.example.com` answers with a valid certificate, and prints the address.
+
+**Sign in as the first admin** with a one-time link made on the server:
+
+```sh
+cd /opt/openmausbot && sudo docker compose exec omb openmausbot pair --label "First admin"
+```
+
+Open the link it prints, or paste it into the desktop app under **+ → Connect to a server**. To sign in with an emailed code instead, run the installer with `--email [email protected]`.
+
+- **Update or repair:** run the same command again. It checks the server, rewrites its own files, moves to the newest release and leaves `.env` and `data/` alone.
+- **Stop:** `--uninstall` stops the server and removes its containers. It deletes nothing: your data stays in `/opt/openmausbot/data`.
+- **Every other command in this guide** that starts `docker compose` for path B works from `/opt/openmausbot`.
+- **What the installer contacts:** the registries and Let's Encrypt from the table, GitHub's release list, and `cloudflare.com/cdn-cgi/trace` to learn the server's public address for the DNS check. It sends no telemetry.
+- **Behind a load balancer or NAT** that forwards ports 80 and 443 to the server, set `OMB_INSTALL_SKIP_DNS=1` to skip the DNS check.
+
+The installer also accepts the one-time code of a server connected to MausBot. That offering is not available yet.
+
+Not on Ubuntu, or prefer to do it by hand? Use one of the three ways below.
+
+## Three ways in, by hand
+
Three ways to make the server reachable are covered. Pick one; the rest of the guide is the same. The short version of every path, including `--lan` and your own cloudflared or proxy (`--public-url`), is at the top of [Self-hosting](self-hosting.md#pick-a-way-in); this guide adds the server setup around it.
| | You need | Who can reach it | Best for |
@@ -92,6 +157,8 @@ Skip to "Install and sign the engines in".
One container for the server plus Caddy for HTTPS at `https://maus.example.com`.
+The [installer](#quick-start-one-command-on-your-own-domain) does these steps for you on Ubuntu. Do them by hand on another system, to build your own image with `ENGINES`, or to see what it does.
+
1. **Point a name at the server.** In your DNS provider add an **A record** (name `maus`, value the server's public IP). After a few minutes `ping maus.example.com` should answer with that IP. Ports 80 and 443 must be open; most providers open them by default.
2. **Install Docker:**
@@ -270,6 +337,7 @@ same release without an npm install prompt or an implicit upgrade.
Check that installation succeeded before starting. A service restart by itself
does not update the installed package. For foreground `npx` usage, specify the
desired release as `npx --yes [email protected] serve --tunnel`.
+- **Installed with the installer:** run the install command again.
- **Path B:** `cd OpenMausBot/deploy && docker compose pull omb && docker compose up -d`.
Routines and queued work survive a restart. A teammate turn running at that moment runs again once at the next start, told to check what it already did, and the bot that asked for it is told. A person's own turn and a running routine are not run again: the conversation says it was interrupted. Update between runs where you can.
@@ -306,6 +374,15 @@ backup_dir=$(mktemp -d "$PWD/openmausbot-backup.XXXXXX")
docker run --rm -v deploy_data:/data:ro -v "$backup_dir":/b alpine sh -c 'umask 077; tar czf /b/openmausbot-data.tgz -C /data .'
```
+With the installer, the data is a folder, not a volume. Archive it the same way:
+
+```sh
+cd /opt/openmausbot && sudo docker compose stop omb
+backup_dir=$(mktemp -d "$PWD/openmausbot-backup.XXXXXX")
+sudo tar czf "$backup_dir/openmausbot-data.tgz" -C /opt/openmausbot data
+sudo docker compose start omb
+```
+
Each command creates a fresh private folder in the current directory, so it
cannot overwrite an older archive with more permissive access. Keep the
archive inside that folder privately on another machine. Restore with the server stopped,
diff --git a/docs/self-hosting.md b/docs/self-hosting.md
index 4d795a1a89..a3e73f57c7 100644
--- a/docs/self-hosting.md
+++ b/docs/self-hosting.md
@@ -112,6 +112,22 @@ would answer the whole internet over plain http. More options are in
### Docker with your own domain
+On a fresh Ubuntu 22.04 or 24.04 server (x86-64), one command checks the
+server, installs MausBot under `/opt/openmausbot` and ends with HTTPS on your
+domain:
+
+```sh
+curl -fsSL https://raw.githubusercontent.com/milind-soni/OpenMausBot/main/deploy/install.sh | sudo sh -s -- --domain maus.example.com
+cd /opt/openmausbot && sudo docker compose exec omb openmausbot pair # Link https://<DOMAIN>/pair#code=…
+```
+
+Add `--check` to only check the server. Running it again updates or repairs;
+`--uninstall` stops the server and keeps your data. The checks, the files it
+writes and what it contacts are in
+[Deploy on a VPS](deploy-vps.md#quick-start-one-command-on-your-own-domain).
+
+By hand, on any system with Docker:
+
```sh
git clone https://github.com/milind-soni/OpenMausBot && cd OpenMausBot/deploy
cp .env.example .env # set DOMAIN (and ENGINES)
@@ -330,6 +346,10 @@ For local Docker Desktop or private Tailscale access without a public domain,
use the [local Compose setup](../deploy/local/README.md). It defaults to
`http://localhost:8080` and supports optional `.env` overrides.
+On Ubuntu, the [installer](deploy-vps.md#quick-start-one-command-on-your-own-domain)
+sets this up with one command, keeping the data in `/opt/openmausbot/data`.
+The rest of this section is the same setup by hand.
+
One tenant = one container for the server plus Caddy for HTTPS.
Requirements: Docker with Compose, a DNS name pointing at the machine, and
ports 80/443 open.
@@ -1441,6 +1461,9 @@ as the service user while the server is stopped, then start it again.
For a foreground invocation, `npx --yes [email protected] serve --tunnel`
selects a particular published release; replace `X.Y.Z` with that version.
+A server installed with the [installer](deploy-vps.md#quick-start-one-command-on-your-own-domain)
+updates by running the install command again.
+
```sh
docker compose -f deploy/docker-compose.yml pull omb && docker compose -f deploy/docker-compose.yml up -d # Docker
git pull && pnpm install && sudo systemctl restart openmausbot # from source
diff --git a/scripts/server-installer.test.ts b/scripts/server-installer.test.ts
new file mode 100644
index 0000000000..81235622fd
--- /dev/null
+++ b/scripts/server-installer.test.ts
@@ -0,0 +1,394 @@
+import { spawnSync } from "node:child_process";
+import { chmodSync, existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, statSync, symlinkSync, writeFileSync } from "node:fs";
+import { tmpdir } from "node:os";
+import { join } from "node:path";
+import { afterAll, afterEach, beforeAll, describe, expect, it } from "vitest";
+
+const ROOT = join(import.meta.dirname, "..");
+const SCRIPT = join(ROOT, "deploy", "install.sh");
+const script = readFileSync(SCRIPT, "utf8");
+const posix = process.platform !== "win32";
+const dirs: string[] = [];
+afterEach(() => {
+ for (const dir of dirs.splice(0)) rmSync(dir, { recursive: true, force: true });
+});
+
+const TOKEN = "t0ken-of-the-registry";
+const CODE = "ABCD-1234-EFGH";
+const REAL_TOOLS = ["sed", "awk", "grep", "cat", "head", "tail", "tr", "sort", "cut", "mkdir", "mktemp", "chmod", "chown", "mv", "rm", "dirname", "sh"];
+
+/** A server that passes every check: Ubuntu 24.04, x86-64, 4 cores, 8 GB, 80 GB free, Docker 27, free ports, a domain that points here. */
+const HEALTHY = {
+ FAKE_UID: "0", FAKE_ARCH: "x86_64", FAKE_CPUS: "4", FAKE_FREE_GB: "80", FAKE_DOCKER: "27.3.1", FAKE_SECURITY: '["name=apparmor","name=seccomp,profile=builtin"]',
+ FAKE_COMPOSE: "0", FAKE_PUBLIC_IP: "203.0.113.7", FAKE_LOCAL_IP: "10.0.0.5", FAKE_DNS: "203.0.113.7", FAKE_NOW: "1794268800", FAKE_THEIRS: "1794268790",
+ FAKE_STABLE: "404", FAKE_RELEASE: "v0.1.151", FAKE_RELEASE_STATUS: "200", FAKE_HEALTH: "healthy", FAKE_HTTPS: "openmausbot",
+};
+
+interface Server {
+ env?: Record<string, string>;
+ osRelease?: string | null;
+ memoryKb?: number;
+ userns?: { max?: string; clone?: string };
+ /** Leave these stand-ins out, as on a server without the tool. */
+ without?: string[];
+}
+
+/** Stand-ins for every tool install.sh asks about the machine, written once: what each answers comes from the run's FAKE_ settings. */
+const STUBS: Record<string, string> = {
+ id: 'echo "$FAKE_UID"',
+ uname: 'echo "$FAKE_ARCH"',
+ nproc: 'echo "$FAKE_CPUS"',
+ sleep: 'echo "sleep $*" >> "$FAKE_LOG"',
+ df: 'echo "Filesystem 1024-blocks Used Available Capacity Mounted on"; echo "/dev/sda1 0 0 $((FAKE_FREE_GB * 1048576)) 10% /"',
+ ss: `case "$*" in *":80") printf '%s' "\${FAKE_SS_80:-}" ;; *":443") printf '%s' "\${FAKE_SS_443:-}" ;; esac`,
+ getent: 'for address in ${FAKE_DNS:-}; do echo "$address STREAM $2"; done',
+ ip: 'echo "2: eth0 inet $FAKE_LOCAL_IP/24 brd 10.0.0.255 scope global eth0"',
+ date: `case "$*" in
+ "-u +%s") echo "$FAKE_NOW" ;;
+ "-u -d "*) echo "$FAKE_THEIRS" ;;
+ "-u +%Y") echo "\${FAKE_YEAR:-2026}" ;;
+ *) echo "2026-11-10 12:00" ;;
+esac`,
+ curl: `echo "curl $*" >> "$FAKE_LOG"
+blocked() { case " \${FAKE_BLOCKED:-} " in *" $1 "*) return 0 ;; esac; return 1; }
+case "$*" in
+ *"-K -"*) cat >> "$FAKE_LOG.stdin"
+ if blocked ghcr.io; then exit 7; fi
+ case "$*" in */manifests/stable) printf '%s' "$FAKE_STABLE" ;; *) printf '%s' "$FAKE_RELEASE_STATUS" ;; esac ;;
+ *cdn-cgi/trace*) printf 'fl=1\\nip=%s\\nts=1\\n' "$FAKE_PUBLIC_IP" ;;
+ "-sSI "*) printf 'HTTP/2 405\\r\\ndate: Tue, 10 Nov 2026 12:00:00 GMT\\r\\n' ;;
+ *ghcr.io/token*) if blocked ghcr.io; then exit 7; fi; printf '{"token":"${TOKEN}"}' ;;
+ *releases/latest*) printf '{\\n "tag_name": "%s",\\n "name": "x"\\n}\\n' "$FAKE_RELEASE" ;;
+ *--resolve*) printf '%s' "\${FAKE_HTTPS:-}" ;;
+ *"/install.sh -o "*) exit 22 ;;
+ *"get.docker.com -o "*) exit 22 ;;
+ *) for last; do :; done
+ host=$(printf '%s' "$last" | sed -e 's#^[a-z]*://##' -e 's#/.*##')
+ if blocked "$host"; then exit 7; fi ;;
+esac`,
+ docker: `echo "docker $*" >> "$FAKE_LOG"
+case "$*" in
+ "version --format"*) [ -n "$FAKE_DOCKER" ] || exit 1; echo "$FAKE_DOCKER" ;;
+ "info --format {{json .SecurityOptions}}") echo "$FAKE_SECURITY" ;;
+ "info --format {{.DockerRootDir}}") echo /nonexistent/docker ;;
+ "compose version") exit "$FAKE_COMPOSE" ;;
+ "ps -q --filter label=com.docker.compose.project=openmausbot --filter publish="*) printf '%s' "\${FAKE_OURS:-}" ;;
+ "ps -aq --filter name=mausbot-connector") printf '%s' "\${FAKE_CONNECTOR:-}" ;;
+ "run --rm --network none --entrypoint id "*" -u") /usr/bin/id -u ;;
+ "run --rm --network none --entrypoint id "*" -g") /usr/bin/id -g ;;
+ compose*" ps -q omb") echo c1 ;;
+ "inspect --format {{.State.Health.Status}} c1") echo "$FAKE_HEALTH" ;;
+esac`,
+};
+
+let stubs = "";
+beforeAll(() => {
+ stubs = mkdtempSync(join(tmpdir(), "omb-server-install-stubs-"));
+ for (const [name, body] of Object.entries(STUBS)) {
+ writeFileSync(join(stubs, name), `#!/bin/sh\n${body}\n`);
+ chmodSync(join(stubs, name), 0o755);
+ }
+});
+afterAll(() => rmSync(stubs, { recursive: true, force: true }));
+
+/** Runs install.sh on a made-up server: only the stand-ins and a few plain tools on its PATH, and its files under a folder of the test's. */
+function run(args: string[], server: Server = {}, kept?: { dir: string }) {
+ const dir = kept?.dir ?? mkdtempSync(join(tmpdir(), "omb-server-install-"));
+ if (!kept) dirs.push(dir);
+ const bin = join(dir, "bin");
+ const sysroot = join(dir, "sysroot");
+ const install = join(dir, "opt", "openmausbot");
+ const log = join(dir, "calls.log");
+ rmSync(bin, { recursive: true, force: true });
+ rmSync(log, { force: true });
+ rmSync(sysroot, { recursive: true, force: true });
+ mkdirSync(bin, { recursive: true });
+ mkdirSync(join(dir, "opt"), { recursive: true });
+ for (const name of REAL_TOOLS) {
+ const found = ["/usr/bin", "/bin", "/usr/sbin", "/sbin"].map((folder) => join(folder, name)).find((path) => existsSync(path));
+ if (found) symlinkSync(found, join(bin, name));
+ }
+ for (const name of Object.keys(STUBS)) if (!server.without?.includes(name)) symlinkSync(join(stubs, name), join(bin, name));
+ mkdirSync(join(sysroot, "etc"), { recursive: true });
+ mkdirSync(join(sysroot, "proc", "sys", "user"), { recursive: true });
+ mkdirSync(join(sysroot, "proc", "sys", "kernel"), { recursive: true });
+ if (server.osRelease !== null) {
+ writeFileSync(join(sysroot, "etc", "os-release"), server.osRelease ?? 'PRETTY_NAME="Ubuntu 24.04.1 LTS"\nNAME="Ubuntu"\nVERSION_ID="24.04"\nID=ubuntu\nID_LIKE=debian\n');
+ }
+ writeFileSync(join(sysroot, "proc", "meminfo"), `MemTotal: ${server.memoryKb ?? 8_100_000} kB\nMemFree: 1000000 kB\n`);
+ writeFileSync(join(sysroot, "proc", "sys", "user", "max_user_namespaces"), `${server.userns?.max ?? "63000"}\n`);
+ if (server.userns?.clone !== undefined) writeFileSync(join(sysroot, "proc", "sys", "kernel", "unprivileged_userns_clone"), `${server.userns.clone}\n`);
+ const result = spawnSync("/bin/sh", [SCRIPT, ...args], {
+ encoding: "utf8",
+ env: { PATH: bin, FAKE_LOG: log, OMB_INSTALL_SYSROOT: sysroot, OMB_INSTALL_DIR: install, MAUSBOT_ADMIN_URL: "https://admin.example.test", ...HEALTHY, ...server.env },
+ timeout: 60_000,
+ });
+ const calls = existsSync(log) ? readFileSync(log, "utf8").trim().split("\n").filter(Boolean) : [];
+ const fixes = result.stdout.split("\n").filter((line) => line.startsWith(" FIX ")).map((line) => line.slice(8));
+ return { ...result, calls, fixes, dir, install, docker: calls.filter((call) => call.startsWith("docker ")), all: result.stdout + result.stderr };
+}
+
+const READS = /^docker (version --format|info --format|compose version$|ps -q --filter)/;
+
+describe.skipIf(!posix)("deploy/install.sh", () => {
+ it("is plain POSIX sh, as `curl … | sh` runs it", () => {
+ expect(spawnSync("sh", ["-n", SCRIPT]).status).toBe(0);
+ const dash = spawnSync("dash", ["-n", SCRIPT]);
+ if (!dash.error) expect(dash.status).toBe(0);
+ expect(script.startsWith("#!/bin/sh\n")).toBe(true);
+ for (const bashism of [/\[\[/, /\bfunction\s+\w+/, /\blocal\s/, /<<</, /\$\{[A-Za-z_]+\[/, /\bsource\s/, /&>/]) expect(script, String(bashism)).not.toMatch(bashism);
+ });
+
+ it("runs nothing when the download is cut off, wherever the cut falls", () => {
+ expect(script.trimEnd().split("\n").at(-1)).toBe('main "$@"');
+ const lines = script.split("\n");
+ const dir = mkdtempSync(join(tmpdir(), "omb-server-install-cut-"));
+ dirs.push(dir);
+ const marker = join(dir, "ran");
+ const bin = join(dir, "bin");
+ mkdirSync(bin);
+ for (const name of [...REAL_TOOLS.filter((tool) => tool !== "sh"), "docker", "curl", "id", "uname", "nproc", "df", "ss", "getent", "ip", "date", "sleep"]) {
+ writeFileSync(join(bin, name), `#!/bin/sh\necho "${name} $*" >> "${marker}"\n`);
+ chmodSync(join(bin, name), 0o755);
+ }
+ for (let cut = 1; cut < lines.length - 1; cut += 7) {
+ const partial = join(dir, "partial.sh");
+ writeFileSync(partial, lines.slice(0, cut).join("\n"));
+ spawnSync("/bin/sh", [partial, "--domain", "maus.example.com"], { env: { PATH: bin, OMB_INSTALL_DIR: join(dir, "opt") }, timeout: 20_000 });
+ expect(existsSync(marker), `cut after line ${cut}`).toBe(false);
+ expect(existsSync(join(dir, "opt")), `cut after line ${cut}`).toBe(false);
+ }
+ });
+
+ it("--check passes a ready server, names every check, and changes nothing", () => {
+ const result = run(["--check", "--domain", "Maus.Example.com"], { env: { FAKE_UID: "1000" } });
+ expect(result.all).toContain("This server is ready for MausBot. Nothing was changed.");
+ expect(result.status).toBe(0);
+ expect(result.fixes).toEqual([]);
+ for (const line of [
+ "operating system: Ubuntu 24.04.1 LTS", "processor: x86-64", "processor cores: 4", "memory: 7.7 GB", "Docker: 27.3.1, with Compose", "free disk: 80 GB",
+ "ports 80 and 443: free", "DNS: maus.example.com points at this server (203.0.113.7)", "outbound: the image registries and Let's Encrypt are reachable",
+ "user namespaces: on", "clock: right", "version: v0.1.151, the newest release",
+ ]) expect(result.stdout).toContain(` ok ${line}`);
+ expect(result.docker.filter((call) => !READS.test(call))).toEqual([]);
+ expect(existsSync(result.install)).toBe(false);
+ expect(result.calls.some((call) => call.includes("get.docker.com"))).toBe(false);
+ });
+
+ it.each<[string, Server, RegExp]>([
+ ["Debian", { osRelease: 'PRETTY_NAME="Debian GNU/Linux 12 (bookworm)"\nVERSION_ID="12"\nID=debian\n' }, /^This server runs Debian GNU\/Linux 12 \(bookworm\)\. MausBot's installer runs on Ubuntu 22\.04 or 24\.04/],
+ ["an old Ubuntu", { osRelease: 'PRETTY_NAME="Ubuntu 20.04.6 LTS"\nVERSION_ID="20.04"\nID=ubuntu\n' }, /^This server runs Ubuntu 20\.04\.6 LTS\./],
+ ["no os-release", { osRelease: null }, /operating system can't be identified/],
+ ["an ARM processor", { env: { FAKE_ARCH: "aarch64" } }, /^This server's processor is aarch64\..*pick an x86-64 server\.$/],
+ ["one core", { env: { FAKE_CPUS: "1" } }, /^This server has 1 processor core\. MausBot needs at least 2/],
+ ["2 GB of memory", { memoryKb: 2_000_000 }, /^This server has 1\.9 GB of memory\. MausBot needs at least 4 GB/],
+ ["a full disk", { env: { FAKE_FREE_GB: "5" } }, /^This server has only 5 GB free at .*MausBot needs at least 20 GB/],
+ ["no Docker", { without: ["docker"] }, /^Docker isn't installed\. Run this again with --install-docker/],
+ ["Docker stopped", { env: { FAKE_DOCKER: "" } }, /^Docker is installed but not running\. Start it with: sudo systemctl enable --now docker/],
+ ["an old Docker", { env: { FAKE_DOCKER: "20.10.24" } }, /^Docker 20\.10\.24 is too old; MausBot needs Docker 24 or newer/],
+ ["rootless Docker", { env: { FAKE_SECURITY: '["name=seccomp","name=rootless"]' } }, /^Docker runs in rootless mode here/],
+ ["Docker without Compose", { env: { FAKE_COMPOSE: "1" } }, /^Docker is here without its Compose plugin\. Run: sudo apt-get install -y docker-compose-plugin/],
+ ["port 80 taken", { env: { FAKE_SS_80: 'LISTEN 0 511 0.0.0.0:80 0.0.0.0:* users:(("nginx",pid=812,fd=6))' } }, /^Port 80 is already in use by nginx\. Stop what uses it \(for example: sudo systemctl disable --now nginx\)/],
+ ["port 80 taken by another container", { env: { FAKE_SS_80: 'LISTEN 0 4096 0.0.0.0:80 0.0.0.0:* users:(("docker-proxy",pid=9,fd=4))' } }, /^Port 80 is already in use by another Docker container\. Find it with: sudo docker ps/],
+ ["port 443 taken by an unnamed program", { env: { FAKE_SS_443: "LISTEN 0 511 0.0.0.0:443 0.0.0.0:*" } }, /^Port 443 is already in use\. Stop what uses it, then run this again\.$/],
+ ["a domain with no record", { env: { FAKE_DNS: "" } }, /^maus\.example\.com does not resolve yet\. Add an A record for it pointing at 203\.0\.113\.7/],
+ ["a domain that points elsewhere", { env: { FAKE_DNS: "198.51.100.9" } }, /^maus\.example\.com points at 198\.51\.100\.9, not at this server \(203\.0\.113\.7\)\. Change its A record to 203\.0\.113\.7/],
+ ["Let's Encrypt blocked", { env: { FAKE_BLOCKED: "acme-v02.api.letsencrypt.org" } }, /^This server can't reach acme-v02\.api\.letsencrypt\.org over HTTPS \(port 443\)\. Allow outbound HTTPS/],
+ ["user namespaces off", { userns: { max: "0" } }, /^This server switches off user namespaces, which the bots' sandbox needs\. Run: printf/],
+ ["unprivileged user namespaces off", { userns: { clone: "0" } }, /^This server switches off user namespaces/],
+ ["a clock an hour off", { env: { FAKE_THEIRS: "1794265200" } }, /^This server's clock is 60 minutes off, so HTTPS certificates will be refused\. Run: sudo timedatectl set-ntp true/],
+ ["a release without an image", { env: { FAKE_RELEASE_STATUS: "404" } }, /^MausBot v0\.1\.151 has no server image yet/],
+ ["the latest tag asked for", { env: { OMB_INSTALL_IMAGE: "ghcr.io/milind-soni/openmausbot:latest" } }, /^OMB_INSTALL_IMAGE names the latest tag/],
+ ])("--check on %s prints the one thing to fix", (_name, server, sentence) => {
+ const result = run(["--check", "--domain", "maus.example.com"], server);
+ expect(result.fixes).toHaveLength(1);
+ expect(result.fixes[0]).toMatch(sentence);
+ expect(result.status).toBe(1);
+ expect(result.stderr).toContain("fix the 1 line(s) marked FIX above. Nothing was changed.");
+ expect(result.docker.filter((call) => !READS.test(call))).toEqual([]);
+ expect(existsSync(result.install)).toBe(false);
+ });
+
+ it("names every blocked address in one line, and both ghcr.io failures when the registry is cut off", () => {
+ const result = run(["--check", "--domain", "maus.example.com"], { env: { FAKE_BLOCKED: "ghcr.io registry-1.docker.io" } });
+ expect(result.fixes).toEqual([
+ "This server can't reach ghcr.io registry-1.docker.io over HTTPS (port 443). Allow outbound HTTPS to them in your firewall, then run this again.",
+ "The image registry ghcr.io did not answer, so the version to install is unknown. Check this server's outbound HTTPS, then run this again.",
+ ]);
+ });
+
+ it("accepts ports its own install holds, a domain that names a local address, and a skipped DNS check", () => {
+ const listening = 'LISTEN 0 4096 0.0.0.0:80 0.0.0.0:* users:(("docker-proxy",pid=9,fd=4))';
+ const own = run(["--check", "--domain", "maus.example.com"], { env: { FAKE_SS_80: listening, FAKE_SS_443: listening, FAKE_OURS: "c1" } });
+ expect(own.fixes).toEqual([]);
+ const local = run(["--check", "--domain", "maus.example.com"], { env: { FAKE_DNS: "10.0.0.5" } });
+ expect(local.stdout).toContain("DNS: maus.example.com points at this server (10.0.0.5)");
+ const skipped = run(["--check", "--domain", "maus.example.com"], { env: { FAKE_DNS: "198.51.100.9", OMB_INSTALL_SKIP_DNS: "1" } });
+ expect(skipped.fixes).toEqual([]);
+ expect(skipped.stdout).toContain("note The DNS record of maus.example.com was not checked, as asked.");
+ });
+
+ it("refuses a domain, an email or a code that is not one, before anything else", () => {
+ for (const [args, sentence] of [
+ [["--domain", "https://maus.example.com"], "is not a domain name"],
+ [["--domain", "localhost"], "is not a full domain name"],
+ [["--domain", "maus.example.com", "--email", "a [email protected]"], "email address doesn't look right"],
+ [["--domain", "maus.example.com", "code;rm"], "That code doesn't look right"],
+ [["--domain", "maus.example.com", "--dir", "relative"], "--dir needs a full path"],
+ [["--frobnicate"], "Unknown option --frobnicate"],
+ ] as const) {
+ const result = run([...args]);
+ expect(result.stderr).toContain(sentence);
+ expect(result.status).toBe(1);
+ expect(result.calls).toEqual([]);
+ }
+ });
+
+ it("installs only as root, and only once every check passes", () => {
+ const user = run(["--domain", "maus.example.com"], { env: { FAKE_UID: "1000" } });
+ expect(user.stderr).toContain("Please run this as root: put sudo before sh, like this: curl -fsSL https://raw.githubusercontent.com/milind-soni/OpenMausBot/main/deploy/install.sh | sudo sh -s -- --domain maus.example.com");
+ expect(user.calls).toEqual([]);
+ const small = run(["--domain", "maus.example.com"], { env: { FAKE_CPUS: "1" } });
+ expect(small.status).toBe(1);
+ expect(small.stderr).toContain("This server is not ready: fix the 1 line(s) marked FIX above, then run this again. Nothing was changed.");
+ expect(small.docker.filter((call) => !READS.test(call))).toEqual([]);
+ expect(existsSync(small.install)).toBe(false);
+ });
+
+ it("never installs Docker unasked", () => {
+ const result = run(["--domain", "maus.example.com"], { without: ["docker"] });
+ expect(result.status).toBe(1);
+ expect(result.stderr).toContain("Docker isn't installed. Install it with: curl -fsSL https://get.docker.com | sudo sh and then run this again, or run this again with --install-docker.");
+ expect(result.calls.some((call) => call.includes("get.docker.com -o"))).toBe(false);
+ expect(existsSync(result.install)).toBe(false);
+ const asked = run(["--domain", "maus.example.com", "--install-docker"], { without: ["docker"] });
+ expect(asked.calls.some((call) => call.includes("https://get.docker.com -o"))).toBe(true);
+ expect(asked.stderr).toContain("Docker's install script could not be downloaded.");
+ });
+
+ it("installs under one folder, pinned to the newest release, and says how the first admin signs in", () => {
+ const result = run(["--domain", "maus.example.com", "--email", "[email protected]"]);
+ expect(result.all).toContain("MausBot is running at https://maus.example.com");
+ expect(result.status).toBe(0);
+ expect(readFileSync(join(result.install, ".env"), "utf8")).toContain("DOMAIN=maus.example.com\nOMB_IMAGE=ghcr.io/milind-soni/openmausbot:v0.1.151\[email protected]\n");
+ expect(statSync(join(result.install, ".env")).mode & 0o777).toBe(0o600);
+ expect(statSync(join(result.install, "data")).mode & 0o777).toBe(0o700);
+ for (const file of ["compose.yaml", "Caddyfile", "caddy/data", "caddy/config"]) expect(existsSync(join(result.install, file)), file).toBe(true);
+ const compose = `docker compose --project-directory ${result.install} -f ${result.install}/compose.yaml`;
+ const changes = result.docker.filter((call) => !READS.test(call) && !call.includes(" ps -q omb") && !call.startsWith("docker inspect"));
+ expect(changes).toEqual([
+ `${compose} pull -q`,
+ "docker run --rm --network none --entrypoint id ghcr.io/milind-soni/openmausbot:v0.1.151 -u",
+ "docker run --rm --network none --entrypoint id ghcr.io/milind-soni/openmausbot:v0.1.151 -g",
+ `${compose} up -d --remove-orphans`,
+ ]);
+ expect(result.stdout).toContain(` cd ${result.install} && sudo docker compose exec omb openmausbot pair --label "First admin"`);
+ expect(result.stdout).toContain("Or open https://maus.example.com/pair and sign in with an emailed code as: [email protected]");
+ expect(result.stdout).toContain(`Your data: ${result.install}/data`);
+ });
+
+ it("uses the stable channel once it is published, and never the latest tag", () => {
+ const result = run(["--domain", "maus.example.com"], { env: { FAKE_STABLE: "200" } });
+ expect(result.stdout).toContain(" ok version: the stable channel");
+ expect(readFileSync(join(result.install, ".env"), "utf8")).toContain("OMB_IMAGE=ghcr.io/milind-soni/openmausbot:stable\n");
+ expect(script).not.toMatch(/openmausbot:latest/);
+ expect(result.calls.some((call) => call.includes("releases/latest"))).toBe(false);
+ });
+
+ it("keeps the registry's token and the one-time code out of its output, and the token off every command line", () => {
+ const connector = mkdtempSync(join(tmpdir(), "omb-server-install-connector-"));
+ dirs.push(connector);
+ writeFileSync(join(connector, "install.sh"), `# stands in for mausbot-connector's installer\necho "$MAUSBOT_ADMIN_URL $#" > "${connector}/ran"\nprintf '%s' "$1" > "${connector}/code"\n`);
+ const result = run(["--domain", "maus.example.com", CODE], { env: { MAUSBOT_CONNECTOR_INSTALLER: join(connector, "install.sh") } });
+ expect(result.status).toBe(0);
+ expect(result.all).not.toContain(TOKEN);
+ expect(result.all).not.toContain(CODE);
+ expect(result.calls.join("\n")).not.toContain(TOKEN);
+ expect(result.calls.join("\n")).not.toContain(CODE);
+ expect(readFileSync(join(result.dir, "calls.log.stdin"), "utf8")).toContain(`header = "Authorization: Bearer ${TOKEN}"`);
+ expect(readFileSync(join(connector, "ran"), "utf8")).toBe("https://admin.example.test 1\n");
+ expect(readFileSync(join(connector, "code"), "utf8")).toBe(CODE);
+ });
+
+ it("with a code, checks that MausBot is reachable and hands the code to the connector's own installer, unchanged", () => {
+ const blocked = run(["--check", "--domain", "maus.example.com", CODE], { env: { FAKE_BLOCKED: "admin.example.test" } });
+ expect(blocked.fixes).toEqual(["This server can't reach admin.example.test over HTTPS (port 443). Allow outbound HTTPS to them in your firewall, then run this again."]);
+ const connectorScript = readFileSync(join(ROOT, "connector", "install.sh"), "utf8");
+ expect(connectorScript).toContain("CONNECTOR=mausbot-connector");
+ expect(connectorScript).toContain("--install-docker) MAUSBOT_INSTALL_DOCKER=1 ;;");
+ expect(connectorScript).toContain('ADMIN_URL="${MAUSBOT_ADMIN_URL:-@MAUSBOT_ADMIN_URL@}"');
+ expect(script).toContain('curl -fsSL --max-time 60 "$ADMIN_URL/install.sh"');
+ const missing = run(["--domain", "maus.example.com", CODE]);
+ expect(missing.status).toBe(1);
+ expect(missing.stderr).toContain("MausBot is installed and running here, but the connector's installer could not be downloaded from https://admin.example.test. Nothing needs reinstalling");
+ expect(existsSync(join(missing.install, "data"))).toBe(true);
+ });
+
+ it("run again, it repairs its own files and keeps the person's settings and data", () => {
+ const first = run(["--domain", "maus.example.com"]);
+ expect(first.status).toBe(0);
+ const env = join(first.install, ".env");
+ writeFileSync(env, `${readFileSync(env, "utf8")}OMB_SIGNIN_SMTP_URL=smtps://mail.example.com\n`);
+ writeFileSync(join(first.install, "data", "messages.db"), "chats");
+ writeFileSync(join(first.install, "compose.yaml"), "broken");
+ const before = statSync(join(first.install, "data"));
+ const listening = 'LISTEN 0 4096 0.0.0.0:80 0.0.0.0:* users:(("docker-proxy",pid=9,fd=4))';
+ const second = run([], { env: { FAKE_SS_80: listening, FAKE_SS_443: listening, FAKE_OURS: "c1", FAKE_RELEASE: "v0.1.152" } }, { dir: first.dir });
+ expect(second.all).toContain("MausBot is running at https://maus.example.com");
+ expect(second.status).toBe(0);
+ expect(readFileSync(env, "utf8").split("\n").filter((line) => /^[A-Z_]+=/.test(line))).toEqual([
+ "OMB_SIGNIN_SMTP_URL=smtps://mail.example.com", "DOMAIN=maus.example.com", "OMB_IMAGE=ghcr.io/milind-soni/openmausbot:v0.1.152",
+ ]);
+ expect(readFileSync(join(first.install, "compose.yaml"), "utf8")).toContain("name: openmausbot");
+ expect(readFileSync(join(first.install, "data", "messages.db"), "utf8")).toBe("chats");
+ const after = statSync(join(first.install, "data"));
+ expect([after.mode, after.uid, after.gid]).toEqual([before.mode, before.uid, before.gid]);
+ expect(second.docker.some((call) => call.includes("--entrypoint id"))).toBe(false);
+ });
+
+ it("says so when the server does not come up, or HTTPS does not answer", () => {
+ const sick = run(["--domain", "maus.example.com"], { env: { FAKE_HEALTH: "starting", OMB_INSTALL_HEALTH_WAIT_S: "10" } });
+ expect(sick.status).toBe(1);
+ expect(sick.stderr).toContain("MausBot started but did not report healthy within 10 seconds.");
+ const noCertificate = run(["--domain", "maus.example.com"], { env: { FAKE_HTTPS: "", OMB_INSTALL_HTTPS_WAIT_S: "10" } });
+ expect(noCertificate.status).toBe(1);
+ expect(noCertificate.stderr).toContain("MausBot is running, but https://maus.example.com did not answer within 10 seconds, usually because the certificate could not be issued.");
+ expect(noCertificate.all).not.toContain("MausBot is running at");
+ });
+
+ it("--uninstall stops the server and keeps the data, saying where it is", () => {
+ const nothing = run(["--uninstall"]);
+ expect(nothing.stderr).toContain("MausBot isn't installed in");
+ const installed = run(["--domain", "maus.example.com"]);
+ writeFileSync(join(installed.install, "data", "messages.db"), "chats");
+ const result = run(["--uninstall"], { env: { FAKE_CONNECTOR: "c9" } }, { dir: installed.dir });
+ expect(result.status).toBe(0);
+ expect(result.docker).toEqual([
+ `docker compose --project-directory ${result.install} -f ${result.install}/compose.yaml down --remove-orphans`,
+ "docker ps -aq --filter name=mausbot-connector",
+ ]);
+ expect(result.stdout).toContain(`Your data is kept in ${result.install}/data, your settings in ${result.install}/.env and the HTTPS certificates in ${result.install}/caddy.`);
+ expect(result.stdout).toContain("This command never deletes your data.");
+ expect(result.stdout).toContain("This server is still connected to MausBot.");
+ expect(readFileSync(join(result.install, "data", "messages.db"), "utf8")).toBe("chats");
+ for (const file of [".env", "compose.yaml", "Caddyfile"]) expect(existsSync(join(result.install, file)), file).toBe(true);
+ expect(script).not.toMatch(/down[^\n]*(-v\b|--volumes)/);
+ expect(script.split("\n").filter((line) => /\brm -r/.test(line) && !line.includes("To delete it yourself"))).toEqual([]);
+ });
+
+ it("writes the Caddyfile and the server's settings the manual Compose setup uses", () => {
+ const caddyfile = readFileSync(join(ROOT, "deploy", "Caddyfile"), "utf8");
+ const result = run(["--domain", "maus.example.com"]);
+ expect(readFileSync(join(result.install, "Caddyfile"), "utf8")).toBe(caddyfile.slice(caddyfile.indexOf("{$DOMAIN} {")));
+ const manual = readFileSync(join(ROOT, "deploy", "docker-compose.yml"), "utf8");
+ const written = readFileSync(join(result.install, "compose.yaml"), "utf8");
+ const settings = (text: string) => [...text.matchAll(/^ {6}(OMB_[A-Z_]+: .*)$/gm)].map((match) => match[1]);
+ expect(settings(written)).toEqual(settings(manual));
+ for (const line of ['test: ["CMD-SHELL", "curl -sf http://127.0.0.1:8799/api/health | grep -q openmausbot"]', 'network_mode: "service:omb"', "init: true", "shm_size: 512m", '- "80:80"', '- "443:443"']) {
+ expect(written).toContain(line);
+ expect(manual).toContain(line);
+ }
+ expect(written).toContain("- ./data:/data");
+ expect(written).not.toContain("build:");
+ });
+});