stud/IV/extract-and-generate

28 lines
572 B
Plaintext
Raw Normal View History

2021-03-31 15:12:42 +03:00
#!/bin/bash
set -euo pipefail
dir=$(mktemp -d)
2021-03-31 15:24:23 +03:00
fname=mj-msc-all.pdf
2021-03-31 15:12:42 +03:00
2021-03-31 15:30:14 +03:00
echo "Extracting all files from $fname to $dir ..."
2021-03-31 15:24:23 +03:00
pdfdetach -saveall -o "$dir" "$fname"
2021-03-31 15:12:42 +03:00
2021-03-31 15:24:23 +03:00
echo "Generating $dir/$fname..."
2021-03-31 15:12:42 +03:00
fail=0
2021-03-31 15:24:23 +03:00
make -C "$dir" -j $(nproc) "$fname" > "$dir/make.log" 2>&1 || fail=1
2021-03-31 15:12:42 +03:00
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
2021-03-31 15:24:23 +03:00
[[ $(uname) == Linux ]] && open=xdg-open
echo "Opening $dir/$fname ..."
"$open" "$dir/$fname"
echo "Editor has been closed. Removing $dir"
rm -fr "$dir"