#!/usr/bin/env bash
# Real demos for P182 "What Happens When You Install Docker on Ubuntu". Runs on render01.
# Two Ubuntu 24.04 LXD system containers on render01's lxdbr0 bridge: "gameserver", the LAN party's game server
# (security.nesting=true so Docker can run inside, as in P063), and "laptop", Jim's laptop on the party Wi-Fi.
# Docker is installed on screen, from Docker's own apt repository, exactly as docs.docker.com/engine/install/ubuntu
# says. Every command shown is typed into Mary's (or Jim's) real login shell in a pty (demo_driver.py). The shop's
# order page is one HTML file (lab/index.html) served by the official nginx image.
#
# Needs: the LXD snap on render01 (ubuntu:24.04 image), internet for the Ubuntu archive, download.docker.com and
# Docker Hub. Nothing outside the two containers is touched.
set -euo pipefail
cd "$(dirname "$0")"
S=ce-p182-shop L=ce-p182-laptop
cleanup() { lxc delete -f $S $L >/dev/null 2>&1 || true; }
cleanup
[ -n "${KEEP:-}" ] || trap cleanup EXIT
lxc launch -q ubuntu:24.04 $S --network lxdbr0 -c security.nesting=true \
  -c security.syscalls.intercept.mknod=true -c security.syscalls.intercept.setxattr=true \
  -c user.user-data="$(printf '#cloud-config\nhostname: gameserver\n')"
lxc launch -q ubuntu:24.04 $L --network lxdbr0 -c user.user-data="$(printf '#cloud-config\nhostname: laptop\n')"
for c in $S $L; do lxc exec $c -- cloud-init status --wait >/dev/null || true; done
lxc exec $S -- mkdir -p /root/lab
lxc file push -q lab/index.html $S/root/lab/
python3 - "$S" "$L" <demo_driver.py
