#!/usr/bin/env bash
# Real demos for P072 "How to Fix Python pip error: externally-managed-environment". Runs on render01 (Docker).
# One container stands in for Ana's new Ubuntu 24.04 laptop (lab/Dockerfile: Python 3.12 and pip from apt,
# exactly as `sudo apt install python3-pip` gives them; python3-venv and pipx are installed on camera).
# It reaches the Ubuntu archive and PyPI, like any laptop. Ana's tea shop price list is served on
# localhost:8000 inside the container (python3 -m http.server, started off-screen), so prices.py has something
# to fetch. Every command shown is typed into a real interactive bash in a pty (demo_driver.py); sudo's password
# prompt is answered by the driver, so the window shows the prompt and nothing typed.
set -euo pipefail
cd "$(dirname "$0")"
P=ce-p072
cleanup() { docker rm -f $P-laptop >/dev/null 2>&1 || true; }
cleanup
[ -n "${KEEP:-}" ] || trap cleanup EXIT
docker build -q -t $P-laptop lab >/dev/null
docker run -d --name $P-laptop --hostname laptop $P-laptop sleep infinity >/dev/null
docker exec -d -u ana $P-laptop python3 -m http.server 8000 -d /srv/shop -b 127.0.0.1
docker exec $P-laptop apt-get update -qq >/dev/null     # package lists, as on any laptop that has run apt once
sleep 1
python3 - "$P" < demo_driver.py
