-
Notifications
You must be signed in to change notification settings - Fork 25
/
build.sh
executable file
·96 lines (84 loc) · 2.12 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
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env bash
# Default values
LANGUAGE="en"
# Valid language codes
valid_languages=("en" "pl" "es" "fr" "ua" "ru" "cs" "he" "de")
# Function to print usage information
usage() {
echo "Usage: $0 [language] [-p|--printable] [-n|--no-bg]"
echo "Example: $0 fr --printable --no-bg"
echo
echo "Positional arguments:"
echo " language Language code (${valid_languages[*]})"
echo " Defaults to 'en' if not specified"
echo
echo "Options:"
echo " -p, --printable Enable printable mode"
echo " -n, --no-bg Disable background"
exit 1
}
# Function to check if language is valid
is_valid_language() {
local lang="$1"
for valid_lang in "${valid_languages[@]}"; do
if [[ "$lang" = "$valid_lang" ]]; then
return 0
fi
done
return 1
}
# Check if first argument is a language code
if [[ $1 =~ ^[a-z]{2}$ ]]; then
if is_valid_language "$1"; then
LANGUAGE="$1"
shift
else
echo "Error: Invalid language code '$1'. Valid codes are: ${valid_languages[*]}" >&2
exit 1
fi
fi
# Parse remaining command line arguments
while [[ $# -gt 0 ]]; do
case $1 in
-p|--printable)
export HOMM3_PRINTABLE=1
shift
;;
-n|--no-bg)
export HOMM3_NO_ART_BACKGROUND=1
shift
;;
-h|--help)
usage
;;
-*)
echo "Error: Unknown option $1" >&2
usage
;;
*)
echo "Error: Unexpected argument '$1'" >&2
usage
;;
esac
done
case "$(uname -s)" in
Darwin*) open=open;;
Linux*) open=xdg-open;;
esac
case "${LANGUAGE}" in
ru|ua|cs|he)
ENGINE=-pdflua
;;
*)
ENGINE=-pdf
;;
esac
if [[ ${LANGUAGE} != en ]]; then
po4a --no-update po4a.cfg \
2> >(grep -v "unmatched end of environment .multicols\| (po4a::tex)$" >&2) \
| grep "/${LANGUAGE}/" # limit output to specified language
fi
# rm triggers latexmk build even if previous artifacts generated by faulty run of po4a prevent it from running
rm -f "main_${LANGUAGE}.aux" && \
latexmk ${ENGINE} -shell-escape "main_${LANGUAGE}.tex"
${open} "main_${LANGUAGE}.pdf" &> /dev/null &