#!/usr/bin/env bash
# Real demos for P167 "PostgreSQL: Full Tutorial for Beginners". Made on the Mac (Docker Desktop).
# One container from stock Ubuntu 24.04 with systemd as PID 1 (lab/Dockerfile): the office PC at Pine Hollow, a
# small campground, with no PostgreSQL yet. Ana installs Ubuntu's PostgreSQL on camera and builds the campground's
# booking database; Ben, at the same front desk, uses a second terminal. Every command shown is typed into a real
# interactive bash (and psql) in a pty (demo_driver.py); every error, row, time and size is real.
set -euo pipefail
cd "$(dirname "$0")"
P=ce-p167
cleanup() { docker rm -f -v $P-office >/dev/null 2>&1 || true; }
cleanup
[ -n "${KEEP:-}" ] || trap cleanup EXIT
docker build -q -t $P-office lab >/dev/null
docker run -d --name $P-office --hostname office --privileged --cgroupns=private --tmpfs /run --tmpfs /run/lock \
  $P-office >/dev/null
for i in $(seq 60); do docker exec $P-office systemctl is-system-running 2>/dev/null | grep -qE 'running|degraded' && break; sleep 1; done
[ -n "${NODRIVER:-}" ] || python3 demo_driver.py $P
