Open-source Grok Bot alternative with a virtual machine that bots can use
TypeScript ai-agentsclaude-codecodexcomputer-usedockerelectrongrokgrok-botgrok-bot-alternativeself-hostedtypescript
Installer: prepare the server for the bots' sandbox, place update.sh, keep its pin
milind-soni317235d018a6
diff --git a/.github/workflows/server-installer.yml b/.github/workflows/server-installer.ymlindex 7fa47ced10..13475bdf0f 100644--- a/.github/workflows/server-installer.yml+++ b/.github/workflows/server-installer.yml@@ -8,6 +8,9 @@ on:paths:- deploy/install.sh- deploy/e2e/**+ - deploy/box/**+ - deploy/update.sh+ - connector/profiles/**- deploy/Caddyfile- deploy/docker-compose.yml- scripts/server-installer.test.ts@@ -25,7 +28,7 @@ jobs:e2e:name: check, install, run again and uninstall on Ubuntu 24.04runs-on: ubuntu-24.04- timeout-minutes: 30+ timeout-minutes: 60steps:- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1with:@@ -52,9 +55,25 @@ jobs:sudo rm -rf /usr/local/lib/android /usr/share/dotnet /opt/ghc /usr/local/.ghcup /opt/hostedtoolcache/CodeQLecho "free for Docker now: $(free_gb) GB"fi+ - name: This checkout's server image, served from a registry on the runner+ # Only an image with the hardened profile can run the bots' sandbox; until a release has it, the published+ # image cannot show the installer turning the sandbox on, so this checkout's is built and installed instead.+ id: image+ run: |+ set -euo pipefail+ if ! grep -q 'OMB_IMAGE=server' Dockerfile; then+ echo "this checkout's image has no hardened profile; installing the published release"+ exit 0+ fi+ docker run -d --name installer-registry -p 127.0.0.1:5000:5000 registry:2 >/dev/null+ docker build -q -t localhost:5000/openmausbot:e2e .+ docker push -q localhost:5000/openmausbot:e2e+ docker image rm localhost:5000/openmausbot:e2e >/dev/null+ echo "image=localhost:5000/openmausbot:e2e" >> "$GITHUB_OUTPUT"- name: Check, install, run again and uninstallenv:OUT: ${{ runner.temp }}/server-installer+ OMB_INSTALL_IMAGE: ${{ steps.image.outputs.image }}run: bash deploy/e2e/run.sh- name: Keep the evidenceif: always()diff --git a/apps/docs/content/docs/self-hosting/deploy-vps.mdx b/apps/docs/content/docs/self-hosting/deploy-vps.mdxindex 88f725b2bf..5b6ba003ea 100644--- a/apps/docs/content/docs/self-hosting/deploy-vps.mdx+++ b/apps/docs/content/docs/self-hosting/deploy-vps.mdx@@ -31,8 +31,9 @@ The installer ([`deploy/install.sh`](https://github.com/milind-soni/OpenMausBot/| 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 |+| Outbound | HTTPS reaches the image registries (`ghcr.io`, `pkg-containers.githubusercontent.com`, Docker Hub), Let's Encrypt and `raw.githubusercontent.com` || User namespaces | switched on, for the bots' sandbox |+| Bots' sandbox | AppArmor is on with its tools, as it is on a stock Ubuntu || Clock | within five minutes of the internet's || Version | a MausBot release to install was found |@@ -52,9 +53,13 @@ If Docker is missing, the installer asks before installing it with Docker's offi| `.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 |+| `update.sh` | the update command, once this repository has it (see below) |+| `compose.box.yaml`, `box/` | the sandbox's settings and the files that prepare the server for it, as this repository has them |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.+**The bots' sandbox.** A MausBot version with the hardened profile runs every bot in a sandbox, away from the server's settings, keys and other bots' files, and Docker's defaults do not let a container build one. For such a version the installer prepares the server (a seccomp profile in `/etc/mausbot` and an AppArmor profile in `/etc/apparmor.d`, the two the MausBot connector installs), starts the server with the four security settings in `compose.box.yaml` (no `--privileged`, no added capability), and then runs the server's own self-check, which among other things confirms that a bot cannot read `config.json`. If the check fails the installer says so and does not report success. For a version without the hardened profile it says the sandbox is not there yet; run the install command again after updating to one that has it. `--no-sandbox` skips all of this, for a server only you sign in to on a host without AppArmor.+**Sign in as the first admin** with a one-time link made on the server:```sh@@ -63,10 +68,11 @@ cd /opt/openmausbot && sudo docker compose exec omb openmausbot pair --label "FiOpen 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.+- **Update:** `sudo /opt/openmausbot/update.sh`, which backs the data up, checks the new version's health and puts the old one back if it fails. The installer places it once this repository has it and prints the command when it finishes; until then, running the install command again moves to the newest release. `update.sh` pins the version by digest in `.env`, and a later run of the installer keeps that pin.+- **Repair:** run the install command again. It checks the server, rewrites its own files 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.+- **What the installer contacts:** the registries and Let's Encrypt from the table, GitHub's release list, this repository's files on `raw.githubusercontent.com`, 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.diff --git a/deploy/e2e/run.sh b/deploy/e2e/run.shindex 4963e885c0..97e44ad07f 100755--- a/deploy/e2e/run.sh+++ b/deploy/e2e/run.sh@@ -3,6 +3,10 @@# 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.+# The files the installer places (update.sh, the sandbox's host preparation) come from this checkout. Where the image+# runs the hardened profile the bots' sandbox must be on and hold: a bot cannot read config.json. With+# OMB_INSTALL_IMAGE set (the workflow builds this checkout's image and serves it from a registry on the runner), that+# image is installed instead of the published release.# OUT=<evidence folder> bash deploy/e2e/run.shset -euo pipefailROOT=$(cd "$(dirname "$0")/../.." && pwd)@@ -10,7 +14,12 @@ OUT=${OUT:-$(mktemp -d)}mkdir -p "$OUT"DOMAIN=installer-e2e.invalidDIR=/opt/openmausbot-INSTALL=(sudo env OMB_INSTALL_SKIP_DNS=1 OMB_INSTALL_HTTPS_WAIT_S=20 sh "$ROOT/deploy/install.sh")+SETTINGS=(OMB_INSTALL_SKIP_DNS=1 OMB_INSTALL_HTTPS_WAIT_S=20 "OMB_INSTALL_SOURCE=file://$ROOT")+# Without a version asked for: what a person's later run is, which must keep the version update.sh pinned.+PLAIN_INSTALL=(sudo env "${SETTINGS[@]}" sh "$ROOT/deploy/install.sh")+if [ -n "${OMB_INSTALL_IMAGE:-}" ]; then SETTINGS+=("OMB_INSTALL_IMAGE=$OMB_INSTALL_IMAGE"); fi+INSTALL=(sudo env "${SETTINGS[@]}" sh "$ROOT/deploy/install.sh")+box_check() { (cd "$DIR" && sudo docker compose exec -T omb node dist-server/bot-box/box-check.js --public=none "$@"); }as_root() { sudo "$@"; }step() { printf '\n== %s\n' "$*"; }@@ -23,9 +32,13 @@ contains() { # file words whatgrep -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=$?+install_until_https() { # evidence-file [the install command, when not the usual one]+ local status=0 file=$1+ shift+ if [ $# = 0 ]; then set -- "${INSTALL[@]}"; fi+ set -- "$@" --domain "$DOMAIN"+ "$@" >"$file" 2>&1 || status=$?+ set -- "$file"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"@@ -41,14 +54,14 @@ 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+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" "bots' sandbox: AppArmor is on" "clock: right" "version:"; docontains "$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"+"${INSTALL[@]}" --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"@@ -56,13 +69,44 @@ install_until_https "$OUT/install.txt"image=$(sudo sed -n 's/^OMB_IMAGE=//p' "$DIR/.env")case "$image" inghcr.io/milind-soni/openmausbot:stable | ghcr.io/milind-soni/openmausbot:v[0-9]*) ;;- *) fail "the install pinned $image" ;;+ *) [ "$image" = "${OMB_INSTALL_IMAGE:-}" ] || 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 bots' sandbox: on and holding where the image has it, left out with a sentence where it does not"+if sudo grep -qx "COMPOSE_FILE=compose.yaml:compose.box.yaml" "$DIR/.env"; then+ contains "$OUT/install.txt" "The bots' sandbox is on: a bot cannot read the server's settings, keys or other bots' files." "the install did not say the sandbox is on"+ sudo cmp "$ROOT/deploy/box/compose.box.yaml" "$DIR/compose.box.yaml" || fail "the sandbox's Compose settings are not the repository's"+ sudo cmp "$ROOT/connector/profiles/seccomp-omb-home.json" /etc/mausbot/seccomp-omb-home.json || fail "the seccomp profile on the host is not the repository's"+ sudo grep -q '^omb-home-narrow ' /sys/kernel/security/apparmor/profiles || fail "the AppArmor profile is not loaded"+ container=$(cd "$DIR" && sudo docker compose ps -q omb)+ [ "$(sudo docker inspect -f '{{.AppArmorProfile}}' "$container")" = omb-home-narrow ] || fail "the server does not run under the sandbox's AppArmor profile"+ [ "$(sudo docker inspect -f '{{.HostConfig.Privileged}} {{json .HostConfig.CapAdd}}' "$container")" = "false null" ] || fail "the server was given privileges"+ (cd "$DIR" && sudo docker compose logs omb 2>&1) | grep -F "bot box: on (bubblewrap" || fail "the server did not start its bot box"+ checks=$(box_check) || fail "the sandbox self-check failed: $checks"+ printf '%s\n' "$checks" >"$OUT/box-check.json"+ jq -e '.box == "bwrap" and .failed == [] and .passed == .total and ([.results[] | select(.ok) | .id] | index("config-hidden") != null and index("messages-db-hidden") != null)' <<<"$checks" >/dev/null || fail "the sandbox does not hide config.json: $checks"+ # The check has teeth: with the data folder's cover taken away, config.json is readable and the check says so.+ bound=$(box_check --mutate=bind-data || true)+ jq -e '.failed | index("config-hidden") != null' <<<"$bound" >/dev/null || fail "the self-check did not notice an uncovered data folder: $bound"+ echo "sandbox: $(jq -r '"\(.passed)/\(.total) checks passed"' <<<"$checks"); uncovered, it fails $(jq -c '.failed' <<<"$bound")"+else+ contains "$OUT/install.txt" "has no bots' sandbox yet." "the install neither turned the sandbox on nor said why not"+ echo "this image has no sandbox; the install said so"+fi++step "update.sh is placed as the repository has it"+if [ -f "$ROOT/deploy/update.sh" ]; then+ sudo cmp "$ROOT/deploy/update.sh" "$DIR/update.sh" || fail "update.sh was not placed"+ sudo test -x "$DIR/update.sh" || fail "update.sh cannot be run"+else+ sudo test ! -e "$DIR/update.sh" || fail "an update.sh appeared from nowhere"+ echo "this checkout has no deploy/update.sh; nothing to place"+fi+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"@@ -77,6 +121,14 @@ sudo grep -qx "OMB_SERVER_NAME=Installer e2e" "$DIR/.env" || fail "the second ru[ "$(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 "a version pinned by digest, as update.sh pins it, survives a run of the installer"+pin=$(sudo docker image inspect -f '{{index .RepoDigests 0}}' "$image")+case "$pin" in *@sha256:*) ;; *) fail "the installed image has no digest: $pin" ;; esac+sudo sed -i "s|^OMB_IMAGE=.*|OMB_IMAGE=$pin|" "$DIR/.env"+install_until_https "$OUT/pinned.txt" "${PLAIN_INSTALL[@]}"+contains "$OUT/pinned.txt" "version: the one update.sh pinned here" "the installer did not keep the pin"+sudo grep -qx "OMB_IMAGE=$pin" "$DIR/.env" || fail "the installer overwrote the pinned version"+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"diff --git a/deploy/install.sh b/deploy/install.shindex 9e67f661ef..c248ab8dae 100755--- a/deploy/install.sh+++ b/deploy/install.sh@@ -9,7 +9,7 @@## 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.+# release list and this repository's files, and cloudflare.com/cdn-cgi/trace to learn this server's public address.set -eusettings() {@@ -19,6 +19,10 @@ settings() {RELEASES_URL=https://api.github.com/repos/milind-soni/OpenMausBot/releases/latestADMIN_URL="${MAUSBOT_ADMIN_URL:-https://cloud.openmausbot.com}"SCRIPT_URL=https://raw.githubusercontent.com/milind-soni/OpenMausBot/main/deploy/install.sh+ # Where the files this installer places come from: this repository, or a copy of it (https://… or file:///…).+ SOURCE="${OMB_INSTALL_SOURCE:-https://raw.githubusercontent.com/milind-soni/OpenMausBot/main}"+ SECCOMP=seccomp-omb-home.json+ APPARMOR_PROFILE=omb-home-narrowPROJECT=openmausbotMIN_DOCKER=24MIN_CPUS=2@@ -33,6 +37,7 @@ settings() {EMAIL=""CODE=""INSTALL_DOCKER="${OMB_INSTALL_DOCKER:-}"+ SANDBOX=yesFAILED=0DOCKER_STATE=unknownDOCKER_PROBLEM=""@@ -67,6 +72,7 @@ usage() {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 " --no-sandbox do not prepare this server for the bots' sandbox (only for a server you alone sign in to)"say " <code> the one-time code MausBot shows, to also connect this server to MausBot"}@@ -76,6 +82,7 @@ parse() {--check) MODE=check ;;--uninstall) MODE=uninstall ;;--install-docker) INSTALL_DOCKER=1 ;;+ --no-sandbox) SANDBOX=no ;;--domain | --email | --dir)[ $# -ge 2 ] || fail "$1 needs a value. $(usage)"case "$1" in@@ -133,8 +140,9 @@ tty_available() {(exec </dev/tty) 2>/dev/null}+# From the install's folder, as a person and update.sh run it: Compose reads .env there, COMPOSE_FILE included.compose() {- docker compose --project-directory "$INSTALL_DIR" -f "$INSTALL_DIR/compose.yaml" "$@"+ (cd "$INSTALL_DIR" && docker compose "$@")}env_value() { # name: its value in the install's .env, or nothing@@ -353,6 +361,7 @@ 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/"; fiif [ -n "$CODE" ]; then targets="$targets $ADMIN_URL/"; fi+ case "$SOURCE" in https://*) targets="$targets https://$(host_of "$SOURCE")/" ;; esacblocked=""for url in $targets; doreachable "$url" || blocked="$blocked $(host_of "$url")"@@ -381,6 +390,20 @@ check_userns() {fi}+# The bots' sandbox needs two profiles on the host, which the install puts there. This only looks.+check_sandbox() {+ if [ "$SANDBOX" != yes ]; then+ note "This server will not be prepared for the bots' sandbox, as asked. Do this only on a server you alone sign in to."+ return+ fi+ enabled=$(cat "$SYSROOT/sys/module/apparmor/parameters/enabled" 2>/dev/null || true)+ if [ "$enabled" != Y ] || ! command -v apparmor_parser >/dev/null 2>&1; then+ fix "This server is missing AppArmor or its tools, which the bots' sandbox needs. Run: sudo apt-get install -y apparmor then restart the server and run this again; or add --no-sandbox to install without the sandbox, on a server you alone sign in to."+ return+ fi+ ok "bots' sandbox: AppArmor is on, so this server can be prepared for it"+}+check_clock() {now=$(date -u +%s)theirs=""@@ -454,6 +477,14 @@ check_version() {esacreturnfi+ pinned=$(env_value OMB_IMAGE)+ case "$pinned" in+ *@sha256:*)+ IMAGE=$pinned+ ok "version: the one update.sh pinned here; it stays until update.sh changes it"+ return+ ;;+ esacregistry_ask stableif [ "$REGISTRY_STATUS" = 200 ]; thenIMAGE="ghcr.io/$IMAGE_REPO:stable"@@ -493,6 +524,7 @@ preflight() {check_diskcheck_portscheck_userns+ check_sandboxif ! command -v curl >/dev/null 2>&1; thennote "The domain, outbound reach, the clock and the version were not checked, because they need curl."return@@ -624,10 +656,17 @@ set_env() { # name value: that one line of .env, leaving every other line as the} | write_file "$env_file" 600}+unset_env() { # name+ env_file="$INSTALL_DIR/.env"+ if grep -q "^$1=" "$env_file" 2>/dev/null; then+ { grep -v "^$1=" "$env_file" || true; } | write_file "$env_file" 600+ fi+}+write_settings() {if [ ! -f "$INSTALL_DIR/.env" ]; thenwrite_file "$INSTALL_DIR/.env" 600 <<'ENV'-# MausBot's settings on this server. The installer sets DOMAIN and OMB_IMAGE and keeps every other line.+# MausBot's settings on this server. The installer sets DOMAIN, OMB_IMAGE and COMPOSE_FILE and keeps every other line.# Who may sign in with an emailed code: OMB_SIGNIN_EMAILS (admins) and OMB_SIGNIN_MEMBER_EMAILS, comma-separated.ENVfi@@ -642,6 +681,78 @@ ENVfi}+fetch() { # path-in-the-repository destination [mode]: 1 when it is not there+ tmp_fetch=$(mktemp "$2.XXXXXX")+ if curl -fsSL --max-time 60 "$SOURCE/$1" -o "$tmp_fetch" 2>/dev/null && [ -s "$tmp_fetch" ]; then+ chmod "${3:-644}" "$tmp_fetch"+ mv "$tmp_fetch" "$2"+ return 0+ fi+ rm -f "$tmp_fetch"+ return 1+}++# update.sh (deploy/update.sh) updates with a backup and a way back; it is this repository's file, placed as it is.+place_update() {+ fetch deploy/update.sh "$INSTALL_DIR/update.sh" 755 || true+}++# The sandbox's host preparation and Compose settings are this repository's own (deploy/box, connector/profiles),+# fetched and used as they are. 1 when they are not published where SOURCE points.+fetch_sandbox() {+ mkdir -p "$INSTALL_DIR/box/profiles"+ fetch deploy/box/prepare-host.sh "$INSTALL_DIR/box/prepare-host.sh" 755 &&+ fetch deploy/box/compose.box.yaml "$INSTALL_DIR/compose.box.yaml" &&+ fetch "connector/profiles/$SECCOMP" "$INSTALL_DIR/box/profiles/$SECCOMP" &&+ fetch "connector/profiles/$APPARMOR_PROFILE.apparmor" "$INSTALL_DIR/box/profiles/$APPARMOR_PROFILE.apparmor"+}++# An image that runs the hardened profile says so in its settings (OMB_IMAGE=server).+image_has_sandbox() {+ case "$(docker image inspect -f '{{json .Config.Env}}' "$IMAGE" 2>/dev/null || true)" in+ *'"OMB_IMAGE=server"'*) return 0 ;;+ esac+ return 1+}++# Sets SANDBOX to on when the server will start with the sandbox's settings, and says why when it will not.+prepare_sandbox() {+ if [ "$SANDBOX" != yes ]; then+ unset_env COMPOSE_FILE+ return+ fi+ if ! image_has_sandbox; then+ unset_env COMPOSE_FILE+ SANDBOX=absent+ note "MausBot ${IMAGE##*[:@]} has no bots' sandbox yet. Run this command again after updating to a version that has it."+ return+ fi+ if ! fetch_sandbox; then+ fail "The files that prepare this server for the bots' sandbox could not be downloaded from $SOURCE. Check this server's outbound HTTPS and run this again; or add --no-sandbox to install without the sandbox, on a server you alone sign in to."+ fi+ say "Preparing this server for the bots' sandbox..."+ MAUSBOT_PROFILES_DIR="$INSTALL_DIR/box/profiles" sh "$INSTALL_DIR/box/prepare-host.sh" >/dev/null ||+ fail "This server could not be prepared for the bots' sandbox (the reason is above). Fix that and run this again; or add --no-sandbox to install without the sandbox, on a server you alone sign in to."+ set_env COMPOSE_FILE compose.yaml:compose.box.yaml+ SANDBOX=on+}++# The server's own self-check of the sandbox, as a bot meets it: among its checks, that config.json cannot be read.+check_sandbox_runs() {+ [ "$SANDBOX" = on ] || return 0+ say "Checking that the bots' sandbox holds..."+ report=$(compose exec -T omb node dist-server/bot-box/box-check.js --public=none 2>/dev/null | tr -d ' \n' || true)+ case "$report" in+ *'"box":"bwrap"'*'"failed":[]'* | *'"failed":[]'*'"box":"bwrap"'*)+ case "$report" in+ *'"config-hidden"'*) say "The bots' sandbox is on: a bot cannot read the server's settings, keys or other bots' files." ;;+ *) fail "MausBot is running, but its sandbox self-check did not test that a bot cannot read the server's settings. Send us this line." ;;+ esac+ ;;+ *) fail "MausBot is running, but its bots' sandbox failed its self-check, so bots are not safely separated from the server. See it with: cd $INSTALL_DIR && sudo docker compose exec omb node dist-server/bot-box/box-check.js --public=none and send us what it prints." ;;+ esac+}+# 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@@ -688,10 +799,13 @@ install_server() {write_settingssay "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."+ place_update+ prepare_sandboxprepare_datasay "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"+ check_sandbox_runssay "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"}@@ -736,7 +850,13 @@ finish() {say "Or open https://$DOMAIN/pair and sign in with an emailed code as: $admins"fisay ""- say "Settings: $INSTALL_DIR/.env Your data: $INSTALL_DIR/data Run this command again to update or repair."+ if [ -x "$INSTALL_DIR/update.sh" ]; then+ say "To update later, with a backup first and a way back: sudo $INSTALL_DIR/update.sh"+ else+ say "To update later, run this command again."+ fi+ say ""+ say "Settings: $INSTALL_DIR/.env Your data: $INSTALL_DIR/data Run this command again to repair."}run_install() {@@ -776,6 +896,9 @@ run_uninstall() {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 [ -f "$SYSROOT/etc/mausbot/$SECCOMP" ]; then+ say "The sandbox's two profiles stay on this server: /etc/mausbot/$SECCOMP and /etc/apparmor.d/$APPARMOR_PROFILE."+ fiif [ -n "$(docker ps -aq --filter name=mausbot-connector 2>/dev/null || true)" ]; thensay "This server is still connected to MausBot. To disconnect it, run the uninstall command MausBot shows for the connector."fidiff --git a/docs/deploy-vps.md b/docs/deploy-vps.mdindex 251d7d72eb..84cddc378f 100644--- a/docs/deploy-vps.md+++ b/docs/deploy-vps.md@@ -23,8 +23,9 @@ The installer ([`deploy/install.sh`](https://github.com/milind-soni/OpenMausBot/| 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 |+| Outbound | HTTPS reaches the image registries (`ghcr.io`, `pkg-containers.githubusercontent.com`, Docker Hub), Let's Encrypt and `raw.githubusercontent.com` || User namespaces | switched on, for the bots' sandbox |+| Bots' sandbox | AppArmor is on with its tools, as it is on a stock Ubuntu || Clock | within five minutes of the internet's || Version | a MausBot release to install was found |@@ -44,9 +45,13 @@ If Docker is missing, the installer asks before installing it with Docker's offi| `.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 |+| `update.sh` | the update command, once this repository has it (see below) |+| `compose.box.yaml`, `box/` | the sandbox's settings and the files that prepare the server for it, as this repository has them |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.+**The bots' sandbox.** A MausBot version with the hardened profile runs every bot in a sandbox, away from the server's settings, keys and other bots' files, and Docker's defaults do not let a container build one. For such a version the installer prepares the server (a seccomp profile in `/etc/mausbot` and an AppArmor profile in `/etc/apparmor.d`, the two the MausBot connector installs), starts the server with the four security settings in `compose.box.yaml` (no `--privileged`, no added capability), and then runs the server's own self-check, which among other things confirms that a bot cannot read `config.json`. If the check fails the installer says so and does not report success. For a version without the hardened profile it says the sandbox is not there yet; run the install command again after updating to one that has it. `--no-sandbox` skips all of this, for a server only you sign in to on a host without AppArmor.+**Sign in as the first admin** with a one-time link made on the server:```sh@@ -55,10 +60,11 @@ cd /opt/openmausbot && sudo docker compose exec omb openmausbot pair --label "FiOpen 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.+- **Update:** `sudo /opt/openmausbot/update.sh`, which backs the data up, checks the new version's health and puts the old one back if it fails. The installer places it once this repository has it and prints the command when it finishes; until then, running the install command again moves to the newest release. `update.sh` pins the version by digest in `.env`, and a later run of the installer keeps that pin.+- **Repair:** run the install command again. It checks the server, rewrites its own files 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.+- **What the installer contacts:** the registries and Let's Encrypt from the table, GitHub's release list, this repository's files on `raw.githubusercontent.com`, 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.diff --git a/scripts/server-installer.test.ts b/scripts/server-installer.test.tsindex 8ab1d3ce68..1a48835c13 100644--- a/scripts/server-installer.test.ts+++ b/scripts/server-installer.test.ts@@ -15,6 +15,9 @@ afterEach(() => {const TOKEN = "t0ken-of-the-registry";const CODE = "ABCD-1234-EFGH";+const BOX_PASSED = '{"box":"bwrap","total":31,"passed":31,"failed":[],"results":[{"id":"config-hidden","ok":true},{"id":"messages-db-hidden","ok":true}]}';+const BOX_FAILED = '{"box":"bwrap","total":31,"passed":30,"failed":["config-hidden"],"results":[{"id":"config-hidden","ok":false}]}';+const SOURCE = "https://raw.githubusercontent.com/milind-soni/OpenMausBot/main";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. */@@ -22,6 +25,7 @@ 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",+ FAKE_IMAGE_ENV: '["PATH=/usr/bin","HOME=/data","OMB_IMAGE=server"]', FAKE_BOX_CHECK: BOX_PASSED, FAKE_SOURCE: "published",};interface Server {@@ -29,12 +33,15 @@ interface Server {osRelease?: string | null;memoryKb?: number;userns?: { max?: string; clone?: string };+ /** /sys/module/apparmor/parameters/enabled; null: the kernel has no AppArmor. */+ apparmor?: string | null;/** 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> = {+ apparmor_parser: 'echo "apparmor_parser $*" >> "$FAKE_LOG"',id: 'echo "$FAKE_UID"',uname: 'echo "$FAKE_ARCH"',nproc: 'echo "$FAKE_CPUS"',@@ -61,6 +68,12 @@ case "$*" in*releases/latest*) printf '{\\n "tag_name": "%s",\\n "name": "x"\\n}\\n' "$FAKE_RELEASE" ;;*--resolve*) printf '%s' "\${FAKE_HTTPS:-}" ;;*"/install.sh -o "*) exit 22 ;;+ *"${SOURCE}/"*" -o "*) [ "$FAKE_SOURCE" = published ] || exit 22+ for last; do :; done+ case "$*" in+ *deploy/box/prepare-host.sh*) printf '#!/bin/sh\\necho "prepare-host profiles=$MAUSBOT_PROFILES_DIR" >> "$FAKE_LOG"\\nexit "\${FAKE_PREPARE:-0}"\\n' > "$last" ;;+ *) printf 'the repository file\\n' > "$last" ;;+ esac ;;*"get.docker.com -o "*) exit 22 ;;*) for last; do :; donehost=$(printf '%s' "$last" | sed -e 's#^[a-z]*://##' -e 's#/.*##')@@ -77,6 +90,8 @@ case "$*" in"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 ;;+ "image inspect -f {{json .Config.Env}} "*) echo "$FAKE_IMAGE_ENV" ;;+ "compose exec -T omb node dist-server/bot-box/box-check.js --public=none") echo "$FAKE_BOX_CHECK"; case "$FAKE_BOX_CHECK" in *'"failed":[]'*) ;; *) exit 1 ;; esac ;;"inspect --format {{.State.Health.Status}} c1") echo "$FAKE_HEALTH" ;;esac`,};@@ -112,6 +127,8 @@ function run(args: string[], server: Server = {}, kept?: { dir: string }) {mkdirSync(join(sysroot, "etc"), { recursive: true });mkdirSync(join(sysroot, "proc", "sys", "user"), { recursive: true });mkdirSync(join(sysroot, "proc", "sys", "kernel"), { recursive: true });+ mkdirSync(join(sysroot, "sys", "module", "apparmor", "parameters"), { recursive: true });+ if (server.apparmor !== null) writeFileSync(join(sysroot, "sys", "module", "apparmor", "parameters", "enabled"), `${server.apparmor ?? "Y"}\n`);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');}@@ -167,7 +184,7 @@ describe.skipIf(!posix)("deploy/install.sh", () => {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", "user namespaces: on", "DNS: maus.example.com points at this server (203.0.113.7)",+ "ports 80 and 443: free", "user namespaces: on", "bots' sandbox: AppArmor is on, so this server can be prepared for it", "DNS: maus.example.com points at this server (203.0.113.7)","outbound: the image registries and Let's Encrypt are reachable", "clock: right", "version: v0.1.151, the newest release",]) expect(result.stdout).toContain(` ok ${line}`);expect(result.docker.filter((call) => !READS.test(call))).toEqual([]);@@ -197,6 +214,9 @@ describe.skipIf(!posix)("deploy/install.sh", () => {["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/],+ ["no AppArmor", { apparmor: null }, /^This server is missing AppArmor or its tools, which the bots' sandbox needs\. Run: sudo apt-get install -y apparmor {2}then restart the server and run this again; or add --no-sandbox/],+ ["AppArmor without its tools", { without: ["apparmor_parser"] }, /^This server is missing AppArmor or its tools/],+ ["this repository's files blocked", { env: { FAKE_BLOCKED: "raw.githubusercontent.com" } }, /^This server can't reach raw\.githubusercontent\.com over HTTPS/],["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/],["a registry that is throttling", { env: { FAKE_RELEASE_STATUS: "429" } }, /^The image registry ghcr\.io did not say whether it has MausBot v0\.1\.151 \(it answered 429\)\. Run this again in a few minutes\.$/],@@ -277,13 +297,14 @@ describe.skipIf(!posix)("deploy/install.sh", () => {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 compose pull -q",+ "docker image inspect -f {{json .Config.Env}} ghcr.io/milind-soni/openmausbot:v0.1.151","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`,+ "docker compose up -d --remove-orphans",+ "docker compose exec -T omb node dist-server/bot-box/box-check.js --public=none",]);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]");@@ -340,7 +361,7 @@ describe.skipIf(!posix)("deploy/install.sh", () => {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",+ "OMB_SIGNIN_SMTP_URL=smtps://mail.example.com", "DOMAIN=maus.example.com", "OMB_IMAGE=ghcr.io/milind-soni/openmausbot:v0.1.152", "COMPOSE_FILE=compose.yaml:compose.box.yaml",]);expect(readFileSync(join(first.install, "compose.yaml"), "utf8")).toContain("name: openmausbot");expect(readFileSync(join(first.install, "data", "messages.db"), "utf8")).toBe("chats");@@ -367,7 +388,7 @@ describe.skipIf(!posix)("deploy/install.sh", () => {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 compose 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.`);@@ -379,6 +400,74 @@ describe.skipIf(!posix)("deploy/install.sh", () => {expect(script.split("\n").filter((line) => /\brm -r/.test(line) && !line.includes("To delete it yourself"))).toEqual([]);});+ it("prepares the server for the bots' sandbox with the repository's own files, starts with its settings, and checks that it holds", () => {+ const result = run(["--domain", "maus.example.com"]);+ expect(result.status).toBe(0);+ for (const path of ["deploy/box/prepare-host.sh", "deploy/box/compose.box.yaml", "connector/profiles/seccomp-omb-home.json", "connector/profiles/omb-home-narrow.apparmor"]) {+ expect(result.calls.some((call) => call.startsWith("curl ") && call.includes(`${SOURCE}/${path} -o `)), path).toBe(true);+ }+ expect(result.calls).toContain(`prepare-host profiles=${result.install}/box/profiles`);+ expect(readFileSync(join(result.install, ".env"), "utf8")).toContain("COMPOSE_FILE=compose.yaml:compose.box.yaml\n");+ expect(readFileSync(join(result.install, "compose.box.yaml"), "utf8")).toBe("the repository file\n");+ expect(result.calls.indexOf(`prepare-host profiles=${result.install}/box/profiles`)).toBeLessThan(result.calls.indexOf("docker compose up -d --remove-orphans"));+ expect(result.stdout).toContain("The bots' sandbox is on: a bot cannot read the server's settings, keys or other bots' files.");+ for (const word of ["security_opt", "seccomp=", "apparmor="]) expect(script, word).not.toContain(word);+ });++ it("says so, and does not finish, when the sandbox does not hold or the server cannot be prepared", () => {+ const failed = run(["--domain", "maus.example.com"], { env: { FAKE_BOX_CHECK: BOX_FAILED } });+ expect(failed.status).toBe(1);+ expect(failed.stderr).toContain("MausBot is running, but its bots' sandbox failed its self-check, so bots are not safely separated from the server.");+ expect(failed.all).not.toContain("MausBot is running at");+ const untested = run(["--domain", "maus.example.com"], { env: { FAKE_BOX_CHECK: '{"box":"bwrap","failed":[],"results":[]}' } });+ expect(untested.stderr).toContain("its sandbox self-check did not test that a bot cannot read the server's settings");+ const refused = run(["--domain", "maus.example.com"], { env: { FAKE_PREPARE: "1" } });+ expect(refused.status).toBe(1);+ expect(refused.stderr).toContain("This server could not be prepared for the bots' sandbox (the reason is above).");+ expect(refused.docker).not.toContain("docker compose up -d --remove-orphans");+ const unpublished = run(["--domain", "maus.example.com"], { env: { FAKE_SOURCE: "missing" } });+ expect(unpublished.status).toBe(1);+ expect(unpublished.stderr).toContain(`The files that prepare this server for the bots' sandbox could not be downloaded from ${SOURCE}.`);+ expect(unpublished.docker).not.toContain("docker compose up -d --remove-orphans");+ });++ it("leaves the sandbox out for a version that has none and when asked, and takes its settings back out", () => {+ const first = run(["--domain", "maus.example.com"]);+ expect(readFileSync(join(first.install, ".env"), "utf8")).toContain("COMPOSE_FILE=");+ const asked = run(["--no-sandbox"], { apparmor: null }, { dir: first.dir });+ expect(asked.status).toBe(0);+ expect(asked.stdout).toContain("note This server will not be prepared for the bots' sandbox, as asked.");+ expect(readFileSync(join(first.install, ".env"), "utf8")).not.toContain("COMPOSE_FILE=");+ expect(asked.calls.some((call) => call.startsWith("prepare-host"))).toBe(false);+ expect(asked.docker.some((call) => call.includes("box-check"))).toBe(false);+ const old = run(["--domain", "maus.example.com"], { env: { FAKE_IMAGE_ENV: '["PATH=/usr/bin","HOME=/data"]' } });+ expect(old.status).toBe(0);+ expect(old.stdout).toContain("note MausBot v0.1.151 has no bots' sandbox yet. Run this command again after updating to a version that has it.");+ expect(readFileSync(join(old.install, ".env"), "utf8")).not.toContain("COMPOSE_FILE=");+ expect(old.calls.some((call) => call.includes("deploy/box/"))).toBe(false);+ });++ it("places update.sh as the repository has it, names it as the way to update, and keeps the version it pinned", () => {+ const first = run(["--domain", "maus.example.com"], { env: { FAKE_STABLE: "200" } });+ expect(first.calls.some((call) => call.includes(`${SOURCE}/deploy/update.sh -o `))).toBe(true);+ expect(readFileSync(join(first.install, "update.sh"), "utf8")).toBe("the repository file\n");+ expect(statSync(join(first.install, "update.sh")).mode & 0o777).toBe(0o755);+ expect(first.stdout).toContain(`To update later, with a backup first and a way back: sudo ${first.install}/update.sh`);+ const env = join(first.install, ".env");+ const pin = `ghcr.io/milind-soni/openmausbot@sha256:${"a".repeat(64)}`;+ writeFileSync(env, readFileSync(env, "utf8").replace("OMB_IMAGE=ghcr.io/milind-soni/openmausbot:stable", `OMB_IMAGE=${pin}`));+ const again = run([], { env: { FAKE_STABLE: "200" } }, { dir: first.dir });+ expect(again.status).toBe(0);+ expect(again.stdout).toContain(" ok version: the one update.sh pinned here; it stays until update.sh changes it");+ expect(readFileSync(env, "utf8")).toContain(`OMB_IMAGE=${pin}\n`);+ expect(readFileSync(env, "utf8")).not.toContain(":stable");+ expect(again.calls.some((call) => call.includes("ghcr.io/token"))).toBe(false);+ const unpublished = run(["--domain", "maus.example.com", "--no-sandbox"], { env: { FAKE_SOURCE: "missing" } });+ expect(unpublished.status).toBe(0);+ expect(existsSync(join(unpublished.install, "update.sh"))).toBe(false);+ expect(unpublished.stdout).toContain("To update later, run this command again.");+ });+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"]);