#!/usr/bin/env bash
# Real demos for P135 "How to Fix Linux apt 'Could Not Get Lock' Errors (Ubuntu)". Made on the Mac (Docker Desktop).
# One container, "catalog": a library's catalog server, stock Ubuntu 24.04 with systemd as PID 1 (lab/Dockerfile).
# Two admins each get a real interactive bash in a pty (demo_driver.py): Ana and Ben. Every lock in the video is held
# by a real process: unattended-upgrades installing real security updates, and Ben's real apt runs.
set -euo pipefail
cd "$(dirname "$0")"
cleanup() { docker rm -f ce-p135-catalog >/dev/null 2>&1 || true; }
cleanup
[ -n "${KEEP:-}" ] || trap cleanup EXIT
docker build -q -t ce-p135-catalog lab >/dev/null
docker run -d --name ce-p135-catalog --hostname catalog \
  --privileged --cgroupns=private -v /sys/fs/cgroup:/sys/fs/cgroup:rw --tmpfs /run --tmpfs /run/lock \
  ce-p135-catalog >/dev/null
python3 - ce-p135 < demo_driver.py
