#!/usr/bin/env bash set -euo pipefail URL="https://didawiki.cli.di.unipi.it/doku.php/matematica/ro/start" BASE="https://didawiki.cli.di.unipi.it" TMPDIR=$(mktemp -d) cleanup() { rm -rf "$TMPDIR"; } trap cleanup EXIT if [[ "${1:-}" == "--with-solutions" ]]; then PREFIX="sc" OUTFILE="soluzioni_ro_merge.pdf" echo "Fetching Svolgimenti PDFs..." else PREFIX="c" OUTFILE="testi_ro_merge.pdf" echo "Fetching Testi PDFs..." fi curl -s "$URL" \ | grep -oP "/lib/exe/fetch\.php/matematica/ro/${PREFIX}\d{6}\.pdf" \ | sort -u \ | while read -r path; do filename=$(basename "$path") echo " Downloading $filename" curl -s -o "$TMPDIR/$filename" "${BASE}${path}" done echo "" echo "Merging PDFs into $OUTFILE..." gs -q -dNOPAUSE -dBATCH -sDEVICE=pdfwrite -sOutputFile="$OUTFILE" "$TMPDIR"/*.pdf echo "Done → $OUTFILE ($(wc -c < "$OUTFILE") bytes)"