#!/usr/bin/env bash
# Real demos for P067 "How Amazon S3 Works". Real Amazon S3, in the channel's own AWS account (cloudexplainers,
# profile `cloudexplainers`, us-east-1), never another account: the driver checks the account ID first.
# Runs on the Mac (render01 holds no keys), from ~/tea-shop outside this repo, typed into one real interactive bash.
# Ana's tea shop keeps its menu and product photos in one bucket, ana-tea-shop, tagged with the video's slug and
# deleted at the end (every object version, then the bucket). Cost: a few requests and a few kilobytes for minutes,
# well under one cent (owner rule: AWS demos under $1 a month).
# Commands and their real output go to demo_output.json; build_script.py reads every line and number from there.
set -euo pipefail
cd "$(dirname "$0")"
export AWS_PROFILE=cloudexplainers AWS_DEFAULT_REGION=us-east-1 AWS_PAGER=""
ACCOUNT=346882411366
[ "$(aws sts get-caller-identity --query Account --output text)" = "$ACCOUNT" ] || { echo "wrong AWS account"; exit 1; }
LAB="$HOME/tea-shop"
rm -rf "$LAB"; mkdir -p "$LAB"
# Two small real JPEG photos (solid colours), made off-screen.
python3 - "$LAB" <<'PY'
import subprocess, sys
for name, rgb in (("kettle", (184, 115, 51)), ("teapot", (60, 120, 90))):
    ppm = f"{sys.argv[1]}/{name}.ppm"
    with open(ppm, "wb") as f:
        f.write(b"P6 64 64 255\n" + bytes(rgb) * 64 * 64)
    subprocess.run(["sips", "-s", "format", "jpeg", ppm, "--out", f"{sys.argv[1]}/{name}.jpg"], check=True,
                   capture_output=True)
    subprocess.run(["rm", ppm], check=True)
PY
printf 'Copper kettle tea  4.00\n' > "$LAB/menu.txt"
python3 demo_driver.py "$LAB"
rm -rf "$LAB"
