This repository has been archived on 2026-08-30. You can view files and clone it, but cannot push or open issues or pull requests.
Ravenous-LaTeX/all_balance.sh

75 lines
2.4 KiB
Bash
Executable File
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# ------------------------------------------------------------------
# gen_html.sh – generate id.html files for a user‑supplied ID range.
#
# Usage:
# ./gen_html.sh # uses default range 0-21 with Podman
# ./gen_html.sh --raw # skip Podman, run cargo directly (default range)
# ./gen_html.sh 5-12 # use IDs 5 … 12 (Podman wrapper)
# ./gen_html.sh --raw 10 # single ID 10 with raw cargo
#
# Optional: override the container image:
# CONTAINER_IMAGE=myrepo/img:1.2 ./gen_html.sh
# ------------------------------------------------------------------
set -euo pipefail # stop on errors, unset vars are errors
# ---------- Parse optional flags ----------
RAW=0
while [[ $# -gt 0 ]]; do
case "$1" in
--raw) RAW=1; shift ;;
*) break ;; # first non‑flag argument is the range
esac
done
# ---------- Resolve ID range (default: 0-21) ----------
RANGE=${1:-0-21}
# Accept either "X-Y" or just a single number "X".
if [[ "$RANGE" =~ ^([0-9]+)-([0-9]+)$ ]]; then
START="${BASH_REMATCH[1]}"
END="${BASH_REMATCH[2]}"
elif [[ "$RANGE" =~ ^([0-9]+)$ ]]; then
START="$RANGE"
END="$START"
else
echo "Error: invalid range format '$RANGE'. Use 'start-end' or a single number." >&2
exit 1
fi
# Ensure start <= end
if (( START > END )); then
echo "Warning: swapping start and end ($START <-> $END)" >&2
SWAP=$START; START=$END; END=$SWAP
fi
# ---------- Container image (default if not set) ----------
CONTAINER_IMAGE=${CONTAINER_IMAGE:-localhost/ravenous-podman:latest}
# ---------- Main loop --------------------------------------
for id in $(seq "$START" "$END"); do
if [[ $RAW -eq 1 ]]; then
# ----- Run cargo directly -----
cmd="cargo run -- monsters balance \
--filter \"id=${id}\" \
--show-extra --show-balanced"
else
# ----- Wrap the cargo command in a Podman container -----
cmd="podman run \
--rm -i --tty \
-v \"$(pwd)\":/workspace \
$CONTAINER_IMAGE \
monsters balance \
--filter \"id=${id}\" \
--show-extra --show-balanced"
fi
# Execute the command string via to‑html and write to <id>.html
to-html "$cmd" > "${id}.html"
echo "✓ id=$id → ${id}.html"
done
echo "All files written (${START}..${END})."