forked from fsr/Stoffkiste
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
executable file
·73 lines (63 loc) · 1.93 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
#!/bin/bash
set -euo pipefail
declare -a FILES
if [[ $# < 1 || $1 = "--help" ]]; then
echo "Usage: $0 <command>"
echo "Available commands are:"
echo " build: just builds all .tex files"
echo " deploy <repo> <branch>: builds all .tex files an deploys to the given repository"
echo " clean: deletes all build artefacts"
exit 1
fi
if [[ "$1" = "build" || "$1" = "deploy" ]]; then
# building PDFs
echo "building PDFs"
find . -name "*.tex" -type f -print -execdir latexmk -halt-on-error -pdf {} \;
# building index file
WS=" "
BODY="$(find . -name "*.pdf" -type f -printf "%h\n" | sort -u | while read DIR; do
pushd "$DIR" > /dev/null
echo "$WS<h2>$(echo $DIR | cut -d'/' -f 2-)</h2>"
echo "$WS<ul>"
for PDF in *.pdf; do
echo "$WS <li><a href='$DIR/$PDF'>$PDF</a></li>"
done
echo "$WS</ul>"
popd > /dev/null
done)"
echo "</html>" >> index.htm
cat > index.htm <<EOF
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Stoffkiste</title>
</head>
<body>
<h1>Stoffkiste</h1>
$BODY
</body>
</html>
EOF
fi
if [[ "$1" = "deploy" ]]; then
if [[ $# != 3 ]]; then
echo "Error: you have to specify the target repository. See $0 --help ." >&2
exit 2
fi
DEPLOY_REPOSITORY=$2
DEPLOY_BRANCH=$3
echo "deploying to $DEPLOY_REPOSITORY:$DEPLOY_BRANCH"
find . -name "*.pdf" -type f -print -exec git add {} \;
CURR_COMMIT=$(git rev-parse HEAD)
git add index.htm
git commit -m "built PDFs and index"
git push -f $DEPLOY_REPOSITORY HEAD:$DEPLOY_BRANCH
git reset $CURR_COMMIT
fi
if [[ "$1" = "clean" || "$1" = "deploy" ]]; then
echo "deleting PDF artefacts"
find . -name "*.tex" -type f -print -execdir latexmk -quiet -C -pdf {} \;
echo "deleting index file"
rm index.htm 2> /dev/null ||:
fi