aboutsummaryrefslogtreecommitdiff
path: root/netzbon/generate-qr.sh
blob: e5c01c6c4912588b6c3b8dd3cc24342a46e212f7 (plain)
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
#!/bin/bash
# This script is in the public domain.
#
# Call with the JSON file (like test.json) with
# an array of merchants to generate letters for!
#
# You must export
#
# export BASE_URL=https://e.netzbon-basel.ch/
#
# before running this script!
#

set -eu
LENGTH=$(jq length < $1)
echo "Generating $LENGTH QR codes for ${BASE_URL}"
DOMAIN=$( echo "${BASE_URL}" | sed -e "s/https:\/\///" | sed -e "s/\/$//")
mkdir -p qre
mkdir -p tmp

for n in $(seq 1 $LENGTH)
do
    echo "Processing merchant $n"
    INDEX=$(expr $n - 1 || true)
    ID=$(jq -r .[$INDEX].id < $1)

    jq ".[$INDEX]" < $1 | jq '.domain="'"${DOMAIN}"'"' > "tmp/${ID}.json"
    cd tmp
    ../render.py "${ID}.json" < ../qr.tex.j2 > "${ID}.tex"
    pdflatex "${ID}.tex" < /dev/null &> /dev/null || true
    pdflatex "${ID}.tex" < /dev/null &> /dev/null || true
    pdflatex "${ID}.tex" < /dev/null
    mv "${ID}.pdf" ../qre/
    cd ..

    echo "Done with ${ID}"
done

pdftk qre/*.pdf cat output qr.pdf
echo "Combined letters are in 'qr.pdf'"