-
Notifications
You must be signed in to change notification settings - Fork 72
/
compile_labs.sh
executable file
·67 lines (59 loc) · 1.97 KB
/
compile_labs.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
#!/bin/bash
# Compile the main tex files and ensure that there are no errors.
MAX_TIME=60
FILES=(PythonEssentials DataScienceEssentials Volume1 Volume2 Volume3 Volume4 GettingStarted)
SUCCESS="true"
LOG="_compilelog.errlog"
SEP="===================="
OUTDIR="docs"
RED="\033[0;91m" # Red text color
GREEN="\033[0;92m" # Green text color
CYAN="\033[0;96m" # Cyan text color
NC="\033[0m" # No text color
set -e
# Ignore command line arguments.
if [ "$#" -ne 0 ]; then
echo "usage: ./compile_labs.sh"
exit 1
fi
# Check that latexmk is installed.
# command -v latexmk &> /dev/null || { echo "'latexmk' not found!"; exit 1; }
# Create a directory to deposit the labs in.
if [ ! -e "${OUTDIR}" ]; then
mkdir "${OUTDIR}"
fi
# Compile each tex file in one minute or less.
function ctimeout() { perl -e "alarm ${MAX_TIME}; exec @ARGV" "$@"; }
echo -e "${CYAN}Compiling labs with latexmk${NC}"
for FILE in ${FILES[@]}; do
LOGFILE="${FILE}${LOG}"
echo -n " ${FILE}.tex..."
if ctimeout latexmk -pdf -outdir="${OUTDIR}" "${FILE}.tex" &> "${LOGFILE}"; then
echo -e "${GREEN}success!${NC}"
else
# Report and record a failure, then move on to the next file.
echo -e "${RED}FAILURE${NC}"
SUCCESS="false"
fi
done
# If any of the compilations failed, print the end of each compile log.
if [ "$SUCCESS" == "false" ]; then
echo -en "\n${RED}LAB COMPILATION FAILED${NC}"
for FILE in ${FILES[@]}; do
echo -e "\n\n${SEP} ${FILE} Compiler Log ${SEP}\n"
LOGFILE="${FILE}${LOG}"
tail "${LOGFILE}"
rm "${LOGFILE}"
done
echo
exit 1
else # If successful, delete compile logs and check that PDF files exist.
for FILE in ${FILES[@]}; do
rm "${FILE}${LOG}"
if [ ! -e "${OUTDIR}/${FILE}.pdf" ]; then
echo -e "\nFAILURE: ${OUTDIR}/${FILE}.pdf does not exist\n"
exit 1
fi
done
fi
echo -e "\n${GREEN}LABS SUCCESSFULLY COMPILED${NC}\n"