diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..364e3a4 --- /dev/null +++ b/build.sh @@ -0,0 +1,148 @@ +#!/usr/bin/env bash +# ------------------------------------------------------------------ +# Build wrapper that runs the “Ravenous” container image with Podman. +# +# Usage: +# ./build.sh [--help | ] [make‑options …] +# +# Modes +# simple (default) – just run `make -N Ravenous.tex` +# full – run all the steps in the original script +# +# The remaining arguments after the mode are forwarded verbatim to +# the `make` command inside the container. +# +# Example: +# ./build.sh full --verbose clean +# ------------------------------------------------------------------ + +set -euo pipefail + +URL="https://proxy.dandaedre.com/gitea/Ravenous/podman_ravenous" +CONTAINER_IMAGE=${CONTAINER_IMAGE:-localhost/ravenous-podman:latest} + +print_error() { + echo "Error: $1" >&2 + echo "Please check the setup at:" >&2 + echo "$URL" >&2 +} + +# ------------------------------------------------------------------ +# Prerequisites Check +# ------------------------------------------------------------------ + +if ! command -v podman >/dev/null 2>&1; then + print_error "Podman is not installed." + exit 1 +fi + +if ! podman image inspect "$CONTAINER_IMAGE" > /dev/null 2>&1; then + print_error "Container image '$CONTAINER_IMAGE' is not installed." + exit 1 +fi + +echo "--- Prerequisites met ---" + +# ------------------------------------------------------------------ +# Argument parsing – first positional arg can be a mode or --help +# ------------------------------------------------------------------ + +MODE=simple # default mode +MAKE_ARGS=() # everything that ends up in the `make` call + +while [[ $# -gt 0 ]]; do + case $1 in + --help) + cat <<'HELP' +Usage: ./build.sh [--help | ] [make-options …] + +Modes: + simple (default) – run a minimal build + full – run all the steps from the original script + +Everything that follows the mode is forwarded verbatim to `make` inside +the container. +HELP + exit 0 + ;; + --full|full) + MODE=full + shift + ;; + *) + # All remaining arguments are passed straight to `make` + MAKE_ARGS+=("$@") + break + ;; + esac +done + +# ------------------------------------------------------------------ +# Helper: run a command inside the container with podman and exit on error +# ------------------------------------------------------------------ + +run_podman() { + # Forward all podman flags (e.g., --no-cache) that the caller might want + local PODMAN_OPTS=() + while [[ $# -gt 0 ]]; do + case $1 in + --* ) + PODMAN_OPTS+=("$1") + shift + ;; + *) + break + ;; + esac + done + + podman run \ + "${PODMAN_OPTS[@]}" \ + --rm \ + --tty \ + -v "$(pwd)":/workspace \ + "$CONTAINER_IMAGE" \ + "$@" +} + +# ------------------------------------------------------------------ +# Build Logic Selection +# ------------------------------------------------------------------ + +case "$MODE" in + full) + echo ">>> Executing FULL build sequence (with args: ${MAKE_ARGS[@]})..." + + run_podman tablegen -e all + + mkdir -p ~/.local/share/fonts/ + mkdir -p ./Images/Radar/ + + cp ./Ressources/lmroman8-regular.ttf ~/.local/share/fonts/ + + run_podman graphs load + run_podman graphs gen + + # Pass user supplied make arguments *before* the target so that options + # like `-j4` or custom targets still work. + run_podman make "${MAKE_ARGS[@]}" -N Ravenous.tex + run_podman make -t glossaries -N Ravenous.tex + run_podman make "${MAKE_ARGS[@]}" -N Ravenous.tex + + ;; + + simple) + echo ">>> Executing SIMPLE build (with args: ${MAKE_ARGS[@]})..." + + run_podman make "${MAKE_ARGS[@]}" -N Ravenous.tex || exit $? + + echo "--- Build Completed Successfully ---" + ;; + + *) + print_error "Unknown mode: $MODE" + exit 1 + ;; +esac + +exit 0