-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpost-update
executable file
·79 lines (76 loc) · 2.12 KB
/
post-update
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
#!/bin/sh
buildroot=$(git config hooks.autotex.buildroot)
if [ -z "$buildroot" ]; then
echo "*** No buildroot specified. Quitting." >&2
exit 1
fi
builddir=$(git config hooks.autotex.projectname)
if [ -z "$builddir" ]; then
echo "*** No project name specified. Quitting." >&2
exit 1
fi
custom_texinputs=$(git config hooks.autotex.texinputs)
# change texinputs if set
if [ -n "$custom_texinputs" ]; then
export TEXINPUTS="$custom_texinputs"
fi
master_name=$(git config hooks.autotex.buildbranch)
if [ -z "$master_name" ]; then
master_name=$(git config hooks.protectedbranch)
if [ -z "$master_name" ]; then
echo "*** No build branch specified. Nothing to do." >&2
exit 0
fi
fi
jobname=$(git config hooks.autotex.jobname)
#TODO: pull these from some list, to allow for multiple jobs
if [ -z "$jobname" ]; then
echo "*** Job name is not set. I don't know what to compile." >&2
exit 0
fi
case " $@ " in
*" refs/heads/$master_name "*)
echo "*** Update pushed to $master_name, building TeX file."
pdflatex_command=$(git config hooks.autotex.pdflatex)
latexmk_command=$(git config hooks.autotex.latexmk)
if [ -z "$pdflatex_command" ]; then
pdflatex_command="pdflatex %O %S"
fi
if [ -z "$latexmk_command" ]; then
latexmk_command="latexmk"
fi
workdir="$buildroot$builddir"
#create working dir if it doesn't exist yet
if [ ! -d "$workdir" ]; then
mkdir "$workdir"
if [ $? -ne 0 ]; then
echo "*** Failed to create build directory." >&2
exit 1
fi
fi
publishto=$(git config hooks.autotex.publishto)
git --work-tree="$workdir" --git-dir="$GIT_DIR" checkout -f
cd "$workdir"
rm "$jobname.pdf"
$latexmk_command -pdflatex="$pdflatex_command" -pdf "$jobname.tex" >> latexmk_build.log
if [ $? -ne 0 ]; then
echo "*** Failed to build notes" >&2
exit 1
fi
# publish if publishto is set
if [ -n "$publishto" ]; then
cp "$jobname.pdf" "$publishto"
if [ $? -ne 0 ]; then
echo "*** Failed to copy $jobname.pdf to $publishto" >&2
exit 1
else
echo "$jobname.pdf was published to $publishto"
exit 0
fi
else
echo "*** Publish location not set. Job done."
exit 0
fi
;;
esac
echo "No build refs pushed. Nothing to do."