Skip to content

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

Podman: pairing under --lan in the e2e, the piped install, a guard for real hosts; uninstall names the update's copy

milind-soni51dc601cd338
diff --git a/deploy/e2e/podman.sh b/deploy/e2e/podman.sh
index 4b8b204210..ab9b3e0ace 100755
--- a/deploy/e2e/podman.sh
+++ b/deploy/e2e/podman.sh
@@ -5,6 +5,8 @@
# back, an update to the next release, an update that cannot start and is rolled back, and an uninstall that keeps the
# data. It also records whether the bots' sandbox (bubblewrap) can run in a rootless container, and with what.
# The files the installer places (update.sh) come from this checkout.
+# ONLY ON A THROWAWAY HOST (a CI runner): it writes into this user's ~/.local/share/openmausbot and removes it at the
+# end, and restarts this user's systemd. It refuses to start where a MausBot Podman install already exists.
# OUT=<evidence folder> bash deploy/e2e/podman.sh
set -euo pipefail
ROOT=$(cd "$(dirname "$0")/../.." && pwd)
@@ -17,6 +19,10 @@ DIR="$HOME/.local/share/openmausbot"
UNIT="$HOME/.config/containers/systemd/openmausbot.container"
INSTALL=(env "OMB_INSTALL_SOURCE=file://$ROOT" sh "$ROOT/deploy/podman/install.sh")
FINDINGS="$OUT/findings.txt"
+if [ -e "$DIR" ] || [ -e "$UNIT" ]; then
+ echo "This user already has a MausBot Podman install ($DIR or $UNIT). This test replaces and removes it: run it on a throwaway host." >&2
+ exit 2
+fi
: >"$FINDINGS"
step() { printf '\n== %s\n' "$*"; }
@@ -85,7 +91,8 @@ exec /usr/bin/loginctl "$@"
STUB
printf '#!/bin/sh\necho "sudo $*" >>"%s/sudo-called"\nexit 97\n' "$stubs" >"$stubs/sudo"
chmod 755 "$stubs/loginctl" "$stubs/sudo"
-PATH="$stubs:$PATH" OMB_INSTALL_IMAGE="$REPO:v$OLD_VERSION" "${INSTALL[@]}" >"$OUT/install-no-linger.txt" 2>&1 || { cat "$OUT/install-no-linger.txt"; fail "the install without linger failed"; }
+# Piped, as the one-line install runs it.
+PATH="$stubs:$PATH" OMB_INSTALL_IMAGE="$REPO:v$OLD_VERSION" OMB_INSTALL_SOURCE="file://$ROOT" sh -s -- <"$ROOT/deploy/podman/install.sh" >"$OUT/install-no-linger.txt" 2>&1 || { cat "$OUT/install-no-linger.txt"; fail "the install without linger failed"; }
contains "$OUT/install-no-linger.txt" " sudo loginctl enable-linger $(id -un)" "the install did not print the linger line"
[ ! -e "$stubs/sudo-called" ] || fail "the installer ran sudo: $(cat "$stubs/sudo-called")"
rm -rf "$stubs"
@@ -215,6 +222,9 @@ step "--lan: other devices on this network reach it, and must pair; --local take
"${INSTALL[@]}" --lan >"$OUT/install-lan.txt" 2>&1 || { cat "$OUT/install-lan.txt"; fail "the --lan run failed"; }
healthy_again
address=$(ip -4 -o route get 1.1.1.1 | sed -n 's/.* src \([0-9.]*\).*/\1/p')
+# The pairing command the installer prints, without a terminal: a code, and a link on this network's address.
+in_server openmausbot pair >"$OUT/pair-lan.txt" 2>&1 || { cat "$OUT/pair-lan.txt"; fail "pair failed"; }
+contains "$OUT/pair-lan.txt" "http://$address:8799/pair#code=" "pair did not give a link on this network's address"
ss -ltnH | grep -qE "(0\.0\.0\.0|\*):8799 " || fail "the server does not listen beyond loopback with --lan"
ss -ltnH | grep -E ":8800 " >"$OUT/lan-8800.txt" || true
from_lan=$(curl -s -o /dev/null -w '%{http_code}' --max-time 5 "http://$address:8799/api/bots" || true)
@@ -225,6 +235,7 @@ from_here=$(curl -s -o /dev/null -w '%{http_code}' --max-time 5 "http://127.0.0.
healthy_again
[ -z "$(new_outside)" ] || fail "--local left something listening beyond loopback: $(new_outside)"
finding "lan: webhook port with --lan: $(awk '{ print $4 }' "$OUT/lan-8800.txt" | tr '\n' ' ')"
+finding "pair: under --lan, openmausbot pair in the container gave a code and a link on http://$address:8799"
finding "lan: with --lan, $address got $from_lan and 127.0.0.1 got $from_here on /api/bots; --local went back to loopback"
step "update to $NEW_VERSION, through update.sh"
diff --git a/deploy/podman/install.sh b/deploy/podman/install.sh
index 1d4e9a0909..ba8ded3f05 100755
--- a/deploy/podman/install.sh
+++ b/deploy/podman/install.sh
@@ -392,6 +392,7 @@ run_uninstall() {
say "MausBot's service is stopped and removed. Your data stays in $DATA_DIR."
say "To remove the data too (some files belong to the container's other ids, so through Podman):"
say " podman unshare rm -rf $INSTALL_DIR"
+ say "The copies of the data update.sh kept: podman volume ls --filter label=com.mausbot.role=update-backup"
say "The downloaded images: podman image ls ghcr.io/milind-soni/openmausbot"
}
diff --git a/deploy/update.sh b/deploy/update.sh
index 62342092e4..e72985c0fe 100755
--- a/deploy/update.sh
+++ b/deploy/update.sh
@@ -812,6 +812,7 @@ fi
# A fresh record for this update: nothing of a journal read above carries over.
J_phase="" J_target="" J_target_id="" J_version="" J_engine="" J_caddy="" J_started=""
CID=$(container)
+if [ -z "$CID" ] && [ -n "$UNIT" ]; then refuse "The server is not running. Start it first: systemctl --user start $SERVER_UNIT"; fi
[ -n "$CID" ] || refuse "This install has no server yet. Start it once first: docker compose up -d"
J_previous_id=$(inspect '{{.Image}}' "$CID")
J_previous=$(published_ref "$J_previous_id")
diff --git a/docs/self-hosting.md b/docs/self-hosting.md
index d1b5413e26..064089ce85 100644
--- a/docs/self-hosting.md
+++ b/docs/self-hosting.md
@@ -217,7 +217,9 @@ button does not run it on this install yet: run `update.sh` yourself.
**Uninstall.** Run the same command with `--uninstall`. The data stays.
Some of its files can belong to the container's other user ids, so remove
-it through Podman: `podman unshare rm -rf ~/.local/share/openmausbot`.
+it through Podman: `podman unshare rm -rf ~/.local/share/openmausbot`. The
+copy of the data the last update kept is a Podman volume:
+`podman volume ls --filter label=com.mausbot.role=update-backup`.
**What rootless does not do.**