stud/IV/extract-and-generate
2021-03-31 15:24:34 +03:00

28 lines
576 B
Bash
Executable File

#!/bin/bash
set -euo pipefail
dir=$(mktemp -d)
fname=mj-msc-all.pdf
echo "Extracting all files from the report to $dir ..."
pdfdetach -saveall -o "$dir" "$fname"
echo "Generating $dir/$fname..."
fail=0
make -C "$dir" -j $(nproc) "$fname" > "$dir/make.log" 2>&1 || fail=1
if [[ $fail == 1 ]]; then
>&2 echo "Generation failed. Here are the last 10 log lines:"
tail -10 "$dir/make.log"
exit 1
fi
open=open
[[ $(uname) == Linux ]] && open=xdg-open
echo "Opening $dir/$fname ..."
"$open" "$dir/$fname"
echo "Editor has been closed. Removing $dir"
rm -fr "$dir"