-
Notifications
You must be signed in to change notification settings - Fork 6
/
cert-card
executable file
·111 lines (97 loc) · 5.21 KB
/
cert-card
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
#! /usr/bin/env bash
set -euo pipefail
certname=${1:-}
fetchkey=${2:-}
cardcolor=${3:-"w"}
if [[ -z $certname || -z $fetchkey ]]; then
echo "usage: $0 <certname> <fetchkey>"
fi
echo "Reading PEM from stdin..." >&2
cat >/tmp/crt-$certname
# When printing to the Brother QL-820WNB, the width of the image (as opposed to
# the height) is scaled to the 6.2 cm of the label tape's width. In the
# following, e.g., 984 x 696 px, means height x width. So the "second" number is
# the one scaled to 6.2 cm.
#
# For example, with a portrait-mode image of 696 x 232 px, the "top" if the
# image is scaled to the width of the paper roll (6.2 cm). If the "top" is 696
# px, which the the nominal pixel width, then no scaling is neededd.
#
# 696 x 232 px
# ^^^ ^^^
# width height
# (6.2 cm)
#
# - - - - - - - - - - +--------------+ ^
# | RIGHT | |
# | | |
# PAPER UNROLLS THIS WAY | TOP | | width
# --------------------> | | | 696 px
# | (normal | | (6.2 cm)
# | orienta.) | |
# - - - - - - - - - - +--------------+ v
# <-------------->
# height 232 px (2.9 cm)
#
#
# If I want the "right" of the image to scale to the 6.2 cm of the paper roll,
# I need to --rotate 90. Since the "right" of the image is now scaled to the
# width of the paper roll, I need to have an image with a in which case the size
# is 696 x 984 px:
#
# 696 x 984 px (rotated 90 degrees)
# ^^^ ^^^
# width height
# (6.2 cm)
#
# - - - - - - - - - - +------------------------------+ ^
# | TOP | |
# | | |
# PAPER UNROLLS THIS WAY | | | width
# --------------------> | RIGHT | | 696 px
# | | | (6.2 cm)
# | (rotated 90) | |
# - - - - - - - - - - +------------------------------+ v
# <------------------------------>
# height 984 px (8.4 cm)
#
#
# Format 1: 984 x 696 px (8.7 x 6.2 cm), requires --rotate 90 so that "696 px"
# (the height) coincides with the the width of the paper roll.
#
# Format 2: 696 x 492 px (6.2 x 4.4 cm), requires no rotation.
line1=$(
cat <<EOF
Thank you for visiting the cert-manager booth
at KubeCon NA 2024!
We hope you\'re enjoying Salt Lake City!
EOF
)
line2=$(
cat <<EOF
The QR code will allow you to download your
certificate and sign the guestbook!
$(step certificate inspect --short /tmp/crt-$certname | sed -e 's/\[\(.*\)\]/\n\1/' -e 's/Certificate (\(.*\))/Certificate\nAlgorithm: \1/' | sed 's/^ //')
EOF
)
# \( -gravity NorthEast logo.png -resize 160 -background white -alpha remove -alpha off -monochrome \) -geometry +40+20 -composite \
# \( -gravity East kubecon-eu-2022-logo.png -resize 280 -background white -alpha remove -alpha off -monochrome \) -geometry +80+10 \
#convert -size 696x1109 canvas:white \
# \( -gravity NorthWest -font Open-Sans-Regular -pointsize 22 -fill black -annotate +0-0 "$line1" \) -geometry +0+0 \
# \( -gravity NorthWest -font Open-Sans-Regular -pointsize 22 -fill black -annotate +0+115 "$line2" \) -geometry +0+0 \
# \( -gravity NorthEast -font Open-Sans-Regular -pointsize 44 -fill black -annotate +0-0 "$cardcolor" \) -geometry +0+0 \
# \( -gravity SouthWest -font DejaVu-Sans-Mono -pointsize 22 -fill black -annotate +0+0 "$(step certificate inspect --short /tmp/crt-$certname | sed -e 's/\[\(.*\)\]/\n\1/' -e 's/Certificate (\(.*\))/Certificate\nAlgorithm: \1/' | sed 's/^ //')" \) -geometry +0+0 \
# -background None -layers Flatten front-$certname.png
#
# TODO: update this URL
url="http://print-your-cert.cert-manager.io/certificate?certName=$certname&fetchKey=$fetchkey"
# url="http://192.168.1.171:8080/certificate?certName=$certname&fetchKey=$fetchkey"
echo "$url" | qrencode --type PNG --margin 4 -o - | convert -size 696x1109 canvas:white \
\( -gravity SouthWest -font Open-Sans-Regular -pointsize 22 -fill black -annotate +0-0 "$line1" \) -geometry +0+0 \
\( -gravity SouthWest -font Open-Sans-Regular -pointsize 22 -fill black -annotate +0+115 "$line2" \) -geometry +0+0 \
\( -gravity SouthEast -font Open-Sans-Regular -pointsize 44 -fill black -annotate +0-0 "$cardcolor" \) -geometry +0+0 \
\( -gravity SouthEast -annotate +415+415 -monochrome -filter point -interpolate nearest - -resize 492 \) -geometry +0+0 \
-background None -layers Flatten front-$certname.png
#echo "$url" >&2
#echo "$url" | qrencode --type PNG --margin 4 -o - | convert -size 696x1109 canvas:white \
# \( -gravity Center -monochrome -filter point -interpolate nearest - -resize 492 \) -composite back-$certname.png