Skip to content

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

Own server: the installer upgrades Debian 12's old Docker and adds AppArmor's tools itself; probe --json for doctor --host

milind-soni73c846cf67a8
diff --git a/connector/install.sh b/connector/install.sh
index 2f7fd3743f..2c40fc3487 100644
--- a/connector/install.sh
+++ b/connector/install.sh
@@ -89,31 +89,40 @@ install_docker() {
if command -v systemctl >/dev/null 2>&1; then systemctl enable --now docker >/dev/null 2>&1 || true; fi
}
-offer_docker() {
+offer_docker() { # what is wrong, in one sentence
if [ "${MAUSBOT_INSTALL_DOCKER:-}" = 1 ]; then
install_docker
return
fi
if tty_available; then
- printf "Docker isn't installed. Install it now with Docker's official script (get.docker.com)? [Y/n] " >/dev/tty
+ printf "%s Install the current Docker now with Docker's official script (get.docker.com)? [Y/n] " "$1" >/dev/tty
answer=""
read -r answer </dev/tty || answer=n
case "$answer" in
"" | y | Y | yes | Yes) install_docker; return ;;
esac
fi
- fail "Docker isn't installed. Install it with: curl -fsSL https://get.docker.com | sudo sh and then run this command again."
+ fail "$1 Install the current Docker with: curl -fsSL https://get.docker.com | sudo sh and then run this command again (or run it with --install-docker)."
}
-check_docker() {
- command -v docker >/dev/null 2>&1 || offer_docker
+docker_server() {
server=$(docker version --format '{{.Server.Version}}' 2>/dev/null || true)
if [ -z "$server" ]; then
fail "Docker is installed but not running. Start it with: sudo systemctl enable --now docker and then run this command again."
fi
major=${server%%.*}
case "$major" in '' | *[!0-9]*) major=0 ;; esac
- [ "$major" -ge "$MIN_DOCKER" ] || fail "Docker $server is too old; MausBot needs Docker $MIN_DOCKER or newer. Update it with: curl -fsSL https://get.docker.com | sudo sh"
+}
+
+check_docker() {
+ command -v docker >/dev/null 2>&1 || offer_docker "Docker isn't installed."
+ docker_server
+ # Debian 12's own Docker is 20.10: Docker's script replaces it with the current one, keeping its containers and volumes.
+ if [ "$major" -lt "$MIN_DOCKER" ]; then
+ offer_docker "Docker $server is too old; MausBot needs Docker $MIN_DOCKER or newer."
+ docker_server
+ [ "$major" -ge "$MIN_DOCKER" ] || fail "Docker is still $server after the update (Docker's output is above). Fix that, then run this command again."
+ fi
security=$(docker info --format '{{json .SecurityOptions}}' 2>/dev/null || true)
case "$security" in
*rootless*) fail "Docker runs in rootless mode here. MausBot needs the standard Docker service: run curl -fsSL https://get.docker.com | sudo sh" ;;
@@ -123,6 +132,12 @@ check_docker() {
check_apparmor() {
enabled=$(cat /sys/module/apparmor/parameters/enabled 2>/dev/null || true)
+ # Debian 12's cloud images run AppArmor in the kernel without its tools; installing them needs no restart.
+ if [ "$enabled" = Y ] && ! command -v apparmor_parser >/dev/null 2>&1 && command -v apt-get >/dev/null 2>&1; then
+ say "Installing AppArmor's tools..."
+ { apt-get update -qq && DEBIAN_FRONTEND=noninteractive apt-get install -y -qq apparmor; } >/dev/null 2>&1 ||
+ fail "AppArmor's tools could not be installed. Run: sudo apt-get install -y apparmor and then run this command again."
+ fi
case "$security" in
*name=apparmor*name=seccomp* | *name=seccomp*name=apparmor*) docker_confines=yes ;;
*) docker_confines=no ;;
diff --git a/connector/src/main.ts b/connector/src/main.ts
index 4970322607..e926e220ed 100644
--- a/connector/src/main.ts
+++ b/connector/src/main.ts
@@ -199,15 +199,21 @@ function statusCommand(): void {
}));
}
-/** One line per check for install.sh: `ok <id>`, `warn <id> <fix>` or `fail <id> <fix>`; exits 1 when any fails. */
+/**
+ * One line per check for install.sh: `ok <id>`, `warn <id> <fix>` or `fail <id> <fix>`. With --json, one object
+ * `{ok, checks}` for `openmausbot doctor --host`, which asks the connector on a server that runs one. Exits 1 when any
+ * check fails.
+ */
async function probeCommand(): Promise<void> {
const docker = new SocketDocker(PATHS.docker);
const image = process.env.MAUSBOT_CONNECTOR_IMAGE;
let box: BoxProbeResult | null = null;
try { box = image ? await probeBox(docker, image, seccomp()) : null; } catch (error) { box = { ok: false, fix: errorText(error) }; }
const checks = hostChecks(await docker.info(), reader, { clockSkewS: null, box });
- for (const check of checks) console.log(check.ok && !check.warning ? `ok ${check.id}` : `${check.ok ? "warn" : "fail"} ${check.id} ${check.fix ?? ""}`);
- if (checks.some((check) => !check.ok)) process.exitCode = 1;
+ const ok = checks.every((check) => check.ok);
+ if (process.argv.includes("--json")) console.log(JSON.stringify({ ok, checks }));
+ else for (const check of checks) console.log(check.ok && !check.warning ? `ok ${check.id}` : `${check.ok ? "warn" : "fail"} ${check.id} ${check.fix ?? ""}`);
+ if (!ok) process.exitCode = 1;
}
const commands: Record<string, () => Promise<void> | void> = {