-
Notifications
You must be signed in to change notification settings - Fork 7
/
build.sh
executable file
·61 lines (52 loc) · 1.57 KB
/
build.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
#!/bin/bash -eu
MODE=$1
DOCKER="docker run -v `pwd`:`pwd` -w `pwd` lilypond"
if [ "$MODE" != "handout" ] && [ "$MODE" != "booklet" ]; then
echo "Usage: ./build.sh [handout|booklet]"
exit 1
fi
# check that the docker image tagged `lilypond` exists
if [ -z "`docker images -q lilypond`" ]; then
echo "Docker image 'lilypond' not found. Building..."
docker build lilypond_docker -t lilypond:latest
fi
# Make sure 'build' directory exists
if [ ! -d ./build ]; then
echo "Creating './build' directory."
mkdir build
fi
for FILE in carols/*.ly; do
BASE=$(basename $FILE .ly)
if [ "$BASE" == "header" ]; then
continue
fi
INFILE=carols/$BASE.ly
OUTFILE_LY=build/$BASE
OUTFILE=$OUTFILE_LY.pdf
# Check whether file needs to be rebuilt; it may be cached. If it
# is cached, we continue.
if [ -f $OUTFILE ]; then
LATEST=$(ls -1t $INFILE $OUTFILE | head -n 1)
if [ "$LATEST" == $OUTFILE ]; then
echo $FILE up-to-date
continue
elif [ "$LATEST" != $INFILE ]; then
echo Unknown value of LATEST: $LATEST
continue
fi
fi
$DOCKER lilypond -drelative-includes -o $OUTFILE_LY $INFILE
done
# Always compile the main file in handout mode first to produce the index right
if [ -f modes/curmode.tex ]; then
rm modes/curmode.tex
fi
ln modes/handout.tex modes/curmode.tex
$DOCKER pdflatex book.tex
$DOCKER makeindex book.idx
if [ $MODE == "booklet" ]; then
rm modes/curmode.tex
ln modes/booklet.tex modes/curmode.tex
fi
$DOCKER pdflatex book.tex
mv book.pdf $MODE.pdf