Files
labs/utilities/pdf_make/generate_reports.sh

40 lines
1.4 KiB
Bash
Raw Permalink Normal View History

2025-06-07 14:04:07 -07:00
#!/bin/bash
echo "Starting report generation..."
# Navigate to the /labs directory within the container
# This is crucial because we're mounting the host's /labs into the container's /labs
cd /labs || { echo "Error: /labs directory not found in container. Exiting."; exit 1; }
# Find all directories prefixed with "lab-"
find . -maxdepth 1 -type d -name "lab-*" | while read lab_dir; do
echo "Processing directory: $lab_dir"
2025-06-16 18:49:18 -07:00
markdown_file="$lab_dir/README.md"
pdf_file="$lab_dir/README.pdf"
2025-06-07 14:04:07 -07:00
# Check if LAB-REPORT.md exists
if [ -f "$markdown_file" ]; then
echo "Found $markdown_file"
# Check if LAB-REPORT.pdf does not exist
if [ ! -f "$pdf_file" ]; then
2025-06-16 18:49:18 -07:00
echo "README.pdf not found. Generating PDF from markdown..."
2025-06-07 14:04:07 -07:00
# Generate PDF using pandoc
# Make sure 'pandoc' command is available in the image, which it is for pandoc/latex
image_dir="$lab_dir"
2025-06-13 21:24:32 -07:00
pandoc "$markdown_file" -s -o "$pdf_file" --pdf-engine=xelatex --resource-path "$image_dir" -V geometry:margin=0.5in
2025-06-07 14:04:07 -07:00
if [ $? -eq 0 ]; then
echo "Successfully generated $pdf_file"
else
echo "Error generating $pdf_file"
fi
else
2025-06-16 18:49:18 -07:00
echo "README.pdf already exists. Skipping generation."
2025-06-07 14:04:07 -07:00
fi
else
2025-06-16 18:49:18 -07:00
echo "README.md not found in $lab_dir. Skipping."
2025-06-07 14:04:07 -07:00
fi
done
echo "Report generation complete."