Created
November 24, 2017 11:22
-
-
Save alepez/1f0654f605fa27b7f7ef416c0edc4cd0 to your computer and use it in GitHub Desktop.
GPG to Printable Datamatrix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
add_caption() { | |
convert "${1}" \ | |
-quality 100 \ | |
-units PixelsPerInch \ | |
-resize 200% \ | |
\( -background white -fill black -size x48 \ | |
label:"${2}" -trim +repage \ | |
-bordercolor white -border 10 \ | |
\) -gravity South -append \ | |
-density 300 \ | |
"caption_${1}" \ | |
&& mv "caption_${1}" "${1}" | |
} | |
generate_image() { | |
dmtxwrite --margin=80 --resolution=300 --output="${1}.jpg" -e8 "${1}" | |
add_caption "${1}.jpg" "${1}" | |
} | |
secret_key_to_image() { | |
local key="${1}" | |
gpg --export-secret-keys "${key}" | split -a1 -b1556 -d - secret.gpg. | |
for i in secret.gpg.[0-9]; do | |
generate_image "${i}" && rm "${i}" | |
done | |
} | |
public_key_to_image() { | |
local key="${1}" | |
gpg --export "${key}" | split -a1 -b1556 -d - public.gpg. | |
for i in public.gpg.[0-9]; do | |
generate_image "${i}" && rm "${i}" | |
done | |
} | |
image_to_key() { | |
local name="${1}" | |
shift | |
( for i in $@; do dmtxread "${i}"; done ) > "${name}.gpg" | |
} | |
generate_pdf() { | |
local output="${1}" | |
shift | |
local resolution="2480x3508"; | |
convert -resize "${resolution}" -extent "${resolution}" \ | |
-background white -gravity Center -border 30 -bordercolor white \ | |
$@ \ | |
"${output}" | |
} | |
import() { | |
gpg --import < "${1}" | |
} | |
import_from_pdf() { | |
local pdf="${1}" | |
convert "${pdf}" "all.png" | |
image_to_key public all-0.png all-1.png | |
image_to_key revocation-certificate all-2.png | |
image_to_key secret all-3.png all-4.png all-5.png | |
import public.gpg | |
import secret.gpg | |
# revocation certificate is not imported, because it revokes the key when | |
# imported | |
} | |
export_to_pdf() { | |
local key="${1}" | |
secret_key_to_image "${key}" | |
public_key_to_image "${key}" | |
# FIXME generate revocation-certificate | |
generate_pdf all.pdf \ | |
public.gpg.[0-9].jpg \ | |
secret.gpg.[0-9].jpg | |
} | |
action="${1}" | |
shift | |
case ${action} in | |
save) key_to_image $@;; | |
load) image_to_key $@;; | |
add_caption) add_caption $@;; | |
generate_image) generate_image $@;; | |
generate_pdf) generate_pdf $@;; | |
import) import $@;; | |
import_from_pdf) import_from_pdf $@;; | |
export_to_pdf) export_to_pdf $@;; | |
esac |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment