-
Notifications
You must be signed in to change notification settings - Fork 1
/
worker
executable file
·43 lines (33 loc) · 1.04 KB
/
worker
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
#!/bin/bash -e
MAX_COMMAND_WAIT_TIME=10
log() {
echo "[$(date +'%Y-%m-%dT%H:%M:%S%z')]: $@" >&2
}
fail() {
log "$@"
exit 1
}
run() {
log "Running $@"
timeout "${MAX_COMMAND_WAIT_TIME}" "$@" >&2 || fail "$1 invocation failed"
echo >&2
}
output_file() {
# Output file length as unsigned 32-bit integer
printf '%08x' "$(wc -c "$1" | cut -d' ' -f1)" | xxd -r -p
# Output raw file bytes
cat "$1"
}
cd /tmp
cat > render.tex
run latex -halt-on-error -interaction=nonstopmode -no-shell-escape render.tex
run dvisvgm --no-fonts --verbosity=1 render.dvi
run rsvg-convert -o render.png render.svg
[ -f render.png ] || fail 'PNG was not generated'
[ "$(wc -c render.png | cut -d' ' -f1)" -ge 24 ] || fail 'PNG file too small'
[ "$(xxd -p -l4 render.png)" = '89504e47' ] || fail 'no PNG magic number found'
[ "$(xxd -p -l4 -s12 render.png)" = '49484452' ] || fail 'no IHDR in PNG'
# Output: binary width followed by height as unsigned 32-bit integer
dd if=render.png skip=4 bs=4 count=2 status=none
output_file 'render.svg'
output_file 'render.png'