forked from xqms/graphicscache
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrelease.sh
executable file
·102 lines (81 loc) · 2.7 KB
/
release.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/bin/bash
set -ex
# source: https://stackoverflow.com/questions/29436275/how-to-prompt-for-yes-or-no-in-bash
function yes_or_no {
while true; do
read -p "$* [y/n]: " yn
case $yn in
[Yy]*) return 0 ;;
[Nn]*) echo "Aborted" ; return 1 ;;
esac
done
}
err_report() {
echo
echo
echo "release.sh:$1: ERROR: Some command failed (see above and in release.log)"
exit 1
}
trap 'err_report $LINENO' ERR
if [[ $# -ne 1 ]]; then
echo "Usage: release.sh input.tex"
exit 1
fi
if [[ -e submission.tex ]] && [[ $1 -ef submission.tex ]]; then
echo "Your file is named 'submission.tex' and I would overwrite it. Aborting..."
exit 1
fi
echo "1) Running latexpand to strip comments and unify your .tex file..."
latexpand --empty-comments $1 > submission.tex
echo
echo "2) Running pdflatex (log in release.log)..."
pdflatex -shell-escape -interaction nonstopmode submission.tex &>> release.log
pdflatex -shell-escape -interaction nonstopmode submission.tex &>> release.log
bibtex submission
pdflatex -shell-escape -interaction nonstopmode submission.tex &>> release.log
pdflatex -shell-escape -interaction nonstopmode submission.tex &>> release.log
echo
echo "3) Running pdflatex with render=false to determine needed files..."
mv submission.tex submission.tex.orig
echo '\makeatletter\def\graphicscache@inhibit{true}\makeatother' > submission.tex
cat submission.tex.orig >> submission.tex
pdflatex -interaction nonstopmode -recorder submission.tex &>> release.log
grep "^INPUT" submission.fls \
| cut -d ' ' --complement -f 1 \
| grep -v '^/' \
| grep -v 'submission\..*' \
| while read f; do echo $(realpath --relative-to=. "$f"); done \
| sort | uniq > submission.fls.clean
FILES=()
while read file; do
FILES+=("$file")
done < submission.fls.clean
FILES+=("submission.tex")
if [[ -e submission.bbl ]]; then
FILES+=("submission.bbl")
fi
echo "Files to be included:"
echo ${FILES[@]}
echo "4) Creating archive release.tar..."
tar cf release.tar "${FILES[@]}"
echo "5) Testing compilation..."
if [[ -e test_release ]]; then
if yes_or_no "The output directory test_release already exists. Can I remove it (rm -Rf test_release)?"; then
rm -Rf test_release
else
exit 1
fi
fi
(
mkdir test_release
cd test_release
tar xf ../release.tar
pdflatex -interaction nonstopmode submission.tex &>> release.log
pdflatex -interaction nonstopmode submission.tex &>> release.log
pdflatex -interaction nonstopmode submission.tex &>> release.log
)
echo
echo "Finished. Please check test_release/submission.pdf for correctness."
# Clean up intermediate files
rm -f submission.pdf submission.out submission.aux submission.log submission.fls
rm -f submission.blg submission.bbl submission.tex.orig