-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-all.sh
executable file
·136 lines (115 loc) · 3.88 KB
/
build-all.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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
#
# Build all content using your locally installed LaTex installation.
#
SCRIPT_DIR="$(cd $(dirname "${BASH_SOURCE[0]}") && pwd -P)"
function getAllMainDocNames() {
(
cd "${SCRIPT_DIR}"
for directory in */ ; do
directory="${directory/\//}" # strips the slash
if [[ -f "${directory}/${directory}.tex" ]] ; then
echo -n "${directory} "
fi
done
)
}
function getCustomerCodeInFileName() {
local -r customerCode="$1"
if [[ -f "${SCRIPT_DIR}/customer-assets/${customerCode}/customer-code-in-file-names.txt" ]] ; then
cat "${SCRIPT_DIR}/customer-assets/${customerCode}/customer-code-in-file-names.txt"
else
echo "${customerCode}"
fi
return 0
}
function getCustomerCodeOfCustomerSpecificDocument() {
local -r documentName="$1"
local -r IFS='-'
read -ra documentNameParts <<< "${documentName}"
for documentNamePart in "${documentNameParts[@]}" ; do
if [[ -d "${SCRIPT_DIR}/customer-assets/${documentNamePart}" ]] ; then
echo -n "${documentNamePart}"
return 0
fi
done
return 1
}
function stripCustomerCodeFromMainFileName() {
local -r customerCode="$1"
local -r mainFile="$2"
echo -n "${mainFile}" | sed "s/${customerCode}-//g" | sed "s/-${customerCode}//g"
}
function buildThemAll() {
local customerCodes=""
local customerCodeInFileName
if ! pushd ${SCRIPT_DIR}/customer-assets >/dev/null 2>&1 ; then
echo "ERROR: Could not find directory ${SCRIPT_DIR}/customer-assets"
return 1
fi
for dir in $(ls -1 -F | grep / | sed "s@/@@") ; do
customerCodes+="${dir} "
done
popd >/dev/null 2>&1
for pdf in $(getAllMainDocNames) ; do
for customerCode in ${customerCodes} ; do
customerCodeInFileName="$(getCustomerCodeInFileName "${customerCode}")"
echo "Deleting ./out/${customerCodeInFileName}*${pdf}*.pdf"
rm "./out/${customerCodeInFileName}*${pdf}*.pdf" >/dev/null 2>&1
done
done
for pdf in $(getAllMainDocNames) ; do
customerCode="$(getCustomerCodeOfCustomerSpecificDocument "${pdf}")"
if [[ "${customerCode}" == "" ]] ; then
for customerCode in ${customerCodes} ; do
customerCodeInFileName="$(getCustomerCodeInFileName "${customerCode}")"
echo "Going to build ./out/${customerCodeInFileName} - ${pdf} - *.pdf"
done
else
customerCodeInFileName="$(getCustomerCodeInFileName "${customerCode}")"
echo "Going to build ./out/${customerCodeInFileName} - $(stripCustomerCodeFromMainFileName "${customerCode}" "${pdf}") - *.pdf"
fi
done
for pdf in $(getAllMainDocNames) ; do
customerCode="$(getCustomerCodeOfCustomerSpecificDocument "${pdf}")"
if [[ "${customerCode}" == "" ]] ; then
for customerCode in ${customerCodes} ; do
echo "===================================================================="
echo "Building ${pdf}"
bash ./build.sh ${localOption} ${draftOption} ${finalOption} --customer ${customerCode} "${pdf}" || exit $?
done
else
echo "===================================================================="
echo "Building $(stripCustomerCodeFromMainFileName "${customerCode}" "${pdf}")"
bash ./build.sh ${localOption} ${draftOption} ${finalOption} --customer ${customerCode} "${pdf}" || exit $?
fi
done
}
localOption=""
draftOption=""
finalOption=""
while (($#)) ; do
if [[ "$1" == "--local" ]] ; then
localOption="--local"
echo "Running the build using local TexLive installation"
shift
elif [[ "$1" == "--editors-version" ]] ; then
draftOption="--editors-version"
echo "Building the editors-version of the document"
shift
elif [[ "$1" == "--release-version" ]] ; then
finalOption="--release-version"
echo "Building the release-version of the document"
shift
else
echo "ERROR: Unknown option $1"
exit 1
fi
done
cleanup() {
echo "Cleaning stuff up..."
exit
}
trap cleanup INT TERM
buildThemAll
exit $?