-
Notifications
You must be signed in to change notification settings - Fork 0
/
make.sh
executable file
·182 lines (167 loc) · 6.47 KB
/
make.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
#!/bin/bash
### Copyright (c) 2024 Neruthes. Published with the MIT license.
touch .myenv
source .env
source .myenv
mkdir -p _dist .tmp
function try_make() {
if [[ -e "$1" ]]; then
./make.sh "$1"
fi
}
function hash_compare() {
dir="$1"
cached_hash="$(cat "$dir/Charter.md.hash")"
if ! grep -qs "$cached_hash" "$dir/UNINC.toml"; then
echo "[ERROR] $dir/UNINC.toml hash is incorrect! See $dir/Charter.md.hash"
cat "$dir/Charter.md.hash"
[[ "$IGNOREHASHMISMATCH" != y ]] && exit 2
fi
}
function getdblistcol() {
cut -d';' -f"$1" "authorities/$OFFICE/witnesslist.txt"
}
function try_altdocsrsync() {
[[ "$WWW_INCLUDE_ALTDOC" == y ]] && rsync -av _dist/altdocs/$OFFICE/ _dist/www/$OFFICE/
}
echo "[INFO] Working on make target: $1"
case "$1" in
*/UNINC.toml)
dir="$(dirname "$1")"
try_make "$dir/Charter.md" # Get hash file and LaTeX code
try_make "$dir/Appendix.md" # Get hash file and LaTeX code
texsrc="authorities/$OFFICE/witness.tex"
# ln -svf "$(realpath --relative-to="$dir" "$texsrc")" "$dir/witness-$OFFICE.tex" # Put code into workdir
cp -a "$texsrc" "$dir/witness-$OFFICE.tex" # Put code into workdir
bash "authorities/$OFFICE/toml2tex.sh" "$1" # Render TOML into LaTeX
### Compare hash
hash_compare "$dir"
try_make "$dir/witness-$OFFICE.tex" # Create PDF letter
try_make "$dir/witness-$OFFICE.pdf" # Put PDF to _dist
### Purge intermediate byproducts
for suffix in log out; do
find "$dir" -name 'witness*'."$suffix" -delete
done
for namespec in 'texput.log' 'UNINC.*.texpart' '*.pdf'; do
find "$dir" -name "$namespec" -delete
done
;;
*/Charter.md)
pdf_src="$(dirname "$1")/witness-$OFFICE.pdf"
destfn_pref="$(bash utils/helper-transformpdfpath.sh "$pdf_src" | sed 's|.pdf$||')"
sha1sum "$1" | cut -d' ' -f1 > "$1.hash"
pandoc -i "$1" -f markdown+smart -t latex -o "$1.texpart"
# dirname_dest="_dist/www/$OFFICE/$(cut -d/ -f2 <<< "$1")"
dirname_dest="$(dirname "$destfn_pref.Charter.md")"
mkdir -p "$dirname_dest"
cp -a "$1" "$destfn_pref.Charter.md"
html_header="authorities/$OFFICE/deco/Charter_header.html"
touch "$html_header"
pandoc --verbose -i "$1" --include-before-body="$html_header" \
-f markdown+smart -s --number-sections -t html \
--metadata title="$TITLE_CHARTER_BEFORE$(tomlq -r .fullname "${1/Charter.md/UNINC.toml}")$TITLE_CHARTER_AFTER" \
-o "$destfn_pref.Charter.html"
echo "$destfn_pref.Charter.html"
;;
*/Appendix.md)
pandoc -i "$1" -f markdown+smart -t latex -o "$1.texpart"
;;
db/*.tex | db-private/*.tex)
### Note: Should support alternative prefix 'db-private'!
rawdir="$(dirname "$1")"
rsync -av --delete "$rawdir"/ .workdir/
wdtexpath=.workdir/"$(basename "$1")"
"$LATEXBUILDCMD" -output-directory="$rawdir" -interaction=errorstopmode "$wdtexpath"
pdf_back_path="$(sed 's|.tex$|.pdf|' <<< "$1")"
du -h "$pdf_back_path"
;;
dbindex)
texpath="authorities/$OFFICE/dbindex.tex"
bash utils/makedbmeta.sh
"$LATEXBUILDCMD" -output-directory="$(dirname "$texpath")" -interaction=errorstopmode "$(basename "$texpath")"
"$LATEXBUILDCMD" -output-directory="$(dirname "$texpath")" -interaction=errorstopmode "$(basename "$texpath")"
pdffn="$(sed 's/.tex$/.pdf/' <<< "$texpath")"
dest="_dist/www/$OFFICE/dbindex.pdf"
cp -a "$pdffn" "$dest"
rm -v "authorities/$OFFICE/dbindex".{log,aux,out,pdf,toc} "authorities/$OFFICE/dblist.texpart"
realpath "$dest" | xargs du -h
;;
db/*/witness-*.pdf | db-private/*/witness-*.pdf)
destfn="$(bash utils/helper-transformpdfpath.sh "$1")"
mkdir -p "$(dirname "$destfn")"
cp -a "$1" "$destfn"
du -xhd1 "$(realpath "$destfn")"
[[ "$MAKE_PNG" == y ]] && ./make.sh "$destfn"
;;
_dist/*.pdf)
# example: _dist/www/PearInc/1970/myclub.pdf
### Generate a PNG for the first page
base="$(basename "$1" | cut -d. -f1)"
cd "$(dirname "$1")" || exit 1
pdftoppm -png -r "$PDF_DPI" -f 1 -l 1 "$base".pdf "$base"
pngfn="$(find . -name "${base}*.png" | sort | head -n1)"
mv -v "$pngfn" "$base.png"
realpath "$base".png | xargs du -h
;;
gc)
gc="$2"
[[ -z $gc ]] && gc=png
bash utils/gc.sh "$2"
;;
deploy*)
if [[ -e deploy.sh ]]; then
./deploy.sh
else
echo "[ERROR] Script file 'deploy.sh' is not found."
if [[ "$PWD" == "$HOME/EWS/nekostein/unincdb" ]]; then
### Avoid accidentally pushing from a special fork!
wrangler pages deploy _dist/www/Nekostein --project-name="unincdb" --commit-dirty=true --branch=main # The default deploy command
fi
fi
;;
allmd)
find db db-private -name Charter.md | while read -r md; do
./make.sh "$md"
done
;;
all)
[[ "$WWW_ALLOW_PNG" != y ]] && ./make.sh gc png
getdblistcol 1 | while read -r orgdir; do
[[ -e "$orgdir" ]] && try_make "$orgdir"/UNINC.toml
done
;;
alt)
### Example: ./make alt example db/1970/unincdb-tutorial
export docname="$2"
if [[ -n "$3" ]]; then
bash utils/makealtdocs.sh "$3"
else
getdblistcol 1 | while read -r orgdir; do
bash utils/makealtdocs.sh "$orgdir"
done
fi
try_altdocsrsync
;;
altall)
./make.sh gc altdoc
find "authorities/$OFFICE/altdoc" -maxdepth 1 -mindepth 1 -type d | cut -d/ -f4 | while read -r docname; do
getdblistcol 1 | while read -r orgdir; do
[[ -e "$orgdir" ]] && ./make.sh alt "$docname" "$orgdir"
done
done
./make.sh gc workdir
;;
hash)
list="$(find db db-private -name UNINC.toml | sed 's|/UNINC.toml||')"
while read -r dir; do
hash_compare "$dir" || exit 1
done <<< "$list"
;;
'')
echo "[INFO] You should specify a build target (a relative path)."
echo "[INFO] Non-path targets: all allmd alt altall dbindex gc hash"
;;
*)
[[ -e "$1"/UNINC.toml ]] && ./make.sh "$1"/UNINC.toml
;;
esac