#!/usr/bin/env bash
# Real demos for P021 "Linux Package Managers: apt vs Snap vs Flatpak" (Linux for Beginners, episode 4).
# The series' Ubuntu 24.04 machine (hostname "ubuntu", admin ana), this time as an LXD system container on
# render01: snapd needs systemd, and only a system container with nesting gives snaps their real, strict
# AppArmor sandbox (in Docker, snapd falls back to "partial" confinement, which would not block anything).
# Ana installs GIMP three ways, then GNOME Calculator three ways, in one real interactive bash (a pty).
# Every number on screen comes from demo_output.json; build_script.py reads it with asserts.
#
# Needs: the LXD snap on render01 (sudo snap install lxd && sudo lxd init --auto), internet for the
# Ubuntu archive, the Snap Store and Flathub. Nothing outside the container is touched; it is deleted at the end.
set -euo pipefail
cd "$(dirname "$0")"
BOX=ce-p021
cleanup() { sudo lxc delete -f $BOX >/dev/null 2>&1 || true; }
cleanup
[ -n "${KEEP:-}" ] || trap cleanup EXIT
sudo lxc launch -q ubuntu:24.04 $BOX -c security.nesting=true
python3 - "$BOX" <demo_driver.py
