Created
August 29, 2017 06:33
-
-
Save lpsmith/231f219fa21e756ea686283043ac3d10 to your computer and use it in GitHub Desktop.
Bash scripts for working with qr codes
This file contains 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 | |
DECODEQR_TMPDIR=$(mktemp --tmpdir=$TMPDIR -d) | |
if [ $? -eq 0 -a ! -z "$DECODEQR_TMPDIR" ]; then | |
#mkfifo $DECODEQR_TMPDIR/tmp.png | |
gnome-screenshot -f $DECODEQR_TMPDIR/tmp.png | |
zbarimg --quiet $DECODEQR_TMPDIR/tmp.png | |
rm -rf $DECODEQR_TMPDIR | |
fi |
This file contains 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 | |
ENCODEQR_TEMPDIR=$(mktemp --tmpdir=$TMPDIR -d) | |
if [ $? -eq 0 -a ! -z $ENCODEQR_TEMPDIR ]; then | |
if [ $# -eq 0 ]; then | |
qrencode -o $ENCODEQR_TEMPDIR/tmpqrcode.png < /dev/stdin | |
else | |
qrencode -o $ENCODEQR_TEMPDIR/tmpqrcode.png "$*" < /dev/stdin | |
fi | |
eog -n $ENCODEQR_TEMPDIR/tmpqrcode.png | |
rm -rf $ENCODEQR_TEMPDIR | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
decodeqr
decodes any qr codes currently displayed on the screen, writing the result(s) to stdout. If nothing is found, then nothing is written to stdout. This depends ongnome-screenshot
and thezbar-tools
packages on Ubuntu.encodeqr
generates a qr code and displays it, temporarily. The content of the qr code can be specified either via command line arguments or via stdin; see the documentation forqrencode
for more info. This depends on theqrencode
andeog
packages on Ubuntu.For security reasons, ideally
TMPDIR
would be on a memory-only filesystem such as tmpfs. Note that at least on linux, if theTMPDIR
environment variable is empty thenmktemp
will default to creating a temporary directory inside/tmp
.One could avoid writing the screen captures or temporary images to a file by using a fifo, not sure why uncommenting the
mkfifo
line (and startinggnome-screenshot
in the background using&
) doesn't work. Assuming you could find a way to get gnome-screenshot and zbarimg to agree on the file type, one could avoid named fifo's altogether viapipe(2)
and/dev/fd
, but I'm not sure how to accomplish that with my limited bash scripting skills.