#!/usr/bin/env bash
# Real demos for P166 "Git and GitHub: Full Tutorial for Beginners". Made on the Mac (Docker Desktop).
# Two laptops from one stock Ubuntu 24.04 image (lab/Dockerfile: Ubuntu's own git and gh): Ana's and Ben's,
# volunteers who keep Clay Corner's website, a pottery class. GitHub is real: a private lab repository,
# cloudexplainers/pottery-class-site, created on camera. Every Git and gh command is typed into a real interactive
# bash in a pty (demo_driver.py); file edits (what they'd do in an editor) are made off camera.
# Ana's page is served on her laptop's port 8000, published on the Mac as 127.0.0.1:28090, for the browser captures.
# LOCAL=1 tests the story against a bare repository on Ana's laptop instead of GitHub.
set -euo pipefail
cd "$(dirname "$0")"
P=ce-p166
cleanup() { for b in ana-laptop ben-laptop; do docker rm -f $P-$b >/dev/null 2>&1 || true; done; docker volume rm $P-remote >/dev/null 2>&1 || true; }
cleanup
[ -n "${KEEP:-}" ] || trap cleanup EXIT
docker build -q -t ce-p166-laptop lab >/dev/null
V=(); [ -n "${LOCAL:-}" ] && V=(-v $P-remote:/srv)
docker run -d ${V[@]+"${V[@]}"} --name $P-ana-laptop --hostname ana-laptop -p 127.0.0.1:28090:8000 ce-p166-laptop sleep infinity >/dev/null
docker run -d ${V[@]+"${V[@]}"} --name $P-ben-laptop --hostname ben-laptop ce-p166-laptop sleep infinity >/dev/null
python3 demo_driver.py "$P"
