-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.sh
executable file
·85 lines (70 loc) · 2.81 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#!/bin/sh
while true; do
if [ "$#" = "0" ]; then
break;
elif [ "$1" = "--" ]; then
# the next arguments will be passed directly to the executable
shift;
break;
elif [ "$1" = "--help" ]; then
echo "Wrapper around the curricust Rust program for conversion from YML directly to PDF."
echo "Usage: $0 [--help] [--dark] [--watch] <BASE_YML_PATH> <OUTPUT_TEX_PATH> <TEMPLATE_PATH>"
echo "Pass arguments the curricust Rust program after --, e.g. $0 ... -- --check-links"
echo
echo "Arguments:"
echo " <BASE_YML_PATH> The base YAML file to use as input"
echo " <OUTPUT_TEX_PATH> The output LaTeX file to then convert to PDF"
echo " (the folder it is in will be cluttered with build files!)"
echo " <TEMPLATE_PATH> The .cls template to use"
echo
echo "Options:"
echo " --help Print help"
echo " --dark Invert colors in the PDF"
echo " --watch Automatically rebuild the .tex and the PDF when any relevant file changes"
echo
echo "Help for curricust (<INPUT> and <OUTPUT> are passed through):"
cargo run -- --help
exit 0
elif [ "$1" = "--dark" ]; then
DARK="true"
elif [ "$1" = "--watch" ]; then
WATCH="true"
elif [ "$BASE_YML_PATH" = "" ]; then
BASE_YML_PATH="$1"
elif [ "$OUTPUT_TEX_PATH" = "" ]; then
OUTPUT_TEX_PATH="$1"
elif [ "$TEMPLATE_PATH" = "" ]; then
TEMPLATE_PATH="$1"
else
echo "Unexpected argument: $1"
echo "Use this to get help about the build script: $0 --help"
echo "Use this to get help about curricust: $0 -- --help"
exit 1
fi
shift;
done;
function buildPdf() {
cargo run -- "$BASE_YML_PATH" "$OUTPUT_TEX_PATH" "$@" || return
if [ "$DARK" = "true" ]; then
sed -i -e "s/{resumecvrusttemplate}/{resumecvrusttemplate}\\\\pagecolor[rgb]{0,0,0}\\\\color[rgb]{1,1,1}/" "$OUTPUT_TEX_PATH"
fi
NEW_CLS_PATH="$(dirname "$OUTPUT_TEX_PATH")/resumecvrusttemplate.cls"
cp "$TEMPLATE_PATH" "$NEW_CLS_PATH"
sed -i -e "s/ProvidesClass{[^}]*}/ProvidesClass{resumecvrusttemplate}/" "$NEW_CLS_PATH"
pushd "$(dirname "$OUTPUT_TEX_PATH")" >/dev/null
pdflatex \
--interaction=nonstopmode "$(basename "$OUTPUT_TEX_PATH")" \
| awk 'BEGIN{IGNORECASE = 1}/warning|!/,/^$/;' \
|| echo "Could not compile latex"
popd >/dev/null
}
buildPdf "$@"
if [ "$WATCH" = "true" ]; then
inotifywait --recursive --monitor \
--event modify,move,create,delete \
"$(dirname "$BASE_YML_PATH")" "./src/" "./curricust_proc_macro" "$TEMPLATE_PATH" \
--exclude "($(dirname "$OUTPUT_TEX_PATH"))|(\.git)" \
| while read whatchanged; do
buildPdf "$@"
done
fi