From cf04e7a8a4676a3f17cd7c03116152f91c7605b8 Mon Sep 17 00:00:00 2001 From: "Brock A. Martin" Date: Sat, 23 Jul 2016 13:05:59 -0500 Subject: [PATCH 1/6] Removed temporary file generation --- qr2asc.sh | 9 --------- 1 file changed, 9 deletions(-) diff --git a/qr2asc.sh b/qr2asc.sh index 8ead0e5..1aeb7ca 100755 --- a/qr2asc.sh +++ b/qr2asc.sh @@ -33,15 +33,6 @@ if [ $# -lt 1 ]; then exit 1 fi -# Create a temp file to use as a pattern for splitting the input key file. -# This helps protect against file collisions in the current directory. -export TMPDIR="" -tmp_file=$(mktemp keyparts.XXXXXX) -if [ $? -ne 0 ]; then - echo "failed to create temporary file" - exit 1 -fi - # For each image on the command line, decode it into text chunks=() index=1 From 2bfcc74b5af5343fac0c81c454e56d0c96efe60a Mon Sep 17 00:00:00 2001 From: "Brock A. Martin" Date: Sat, 23 Jul 2016 15:01:34 -0500 Subject: [PATCH 2/6] Adding test script --- test.sh | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100755 test.sh diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..d85c9a1 --- /dev/null +++ b/test.sh @@ -0,0 +1,24 @@ +#!/bin/bash + +if [ $# -eq 0 ]; then + echo "usage: $(basename ${0}) " + exit 1 +fi + +set -x + +asc_key="$1" + +./asc2qr.sh "${asc_key}" + +./qr2asc.sh QR*.png + +diff "${asc_key}" "./mykey.asc" +if [ $? -eq 0 ]; then + echo "Diff Test: PASS" +else + echo "Diff Test: FAIL" +fi + +rm ./QR*.png +rm ./mykey.asc From 64638766a034785dc3e659996a91205f54620f8f Mon Sep 17 00:00:00 2001 From: "Brock A. Martin" Date: Sat, 23 Jul 2016 15:04:58 -0500 Subject: [PATCH 3/6] Removing 'echo' of private asc key --- asc2qr.sh | 1 - 1 file changed, 1 deletion(-) diff --git a/asc2qr.sh b/asc2qr.sh index e98842f..2f0fe02 100755 --- a/asc2qr.sh +++ b/asc2qr.sh @@ -49,7 +49,6 @@ fi chunks=() while true; do s=$( head -c ${max_qr_bytes} ) - echo "$s" if [ ${#s} -gt 0 ]; then chunks+=("${s}") else From d80f849f4ac9aad03f08f3cc044848575d3fbebc Mon Sep 17 00:00:00 2001 From: "Brock A. Martin" Date: Sat, 23 Jul 2016 15:06:23 -0500 Subject: [PATCH 4/6] Adding suggested decode line as comment (I don't think the other one works always anyway) --- qr2asc.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/qr2asc.sh b/qr2asc.sh index 1aeb7ca..fe5ae0a 100755 --- a/qr2asc.sh +++ b/qr2asc.sh @@ -44,6 +44,10 @@ for img in "$@"; do asc_key="${tmp_file}.${index}" echo "decoding ${img}" chunk=$( zbarimg --raw ${img} 2>/dev/null | perl -p -e 'chomp if eof' ) + # Please use this next line instead of teh one above if zbarimg does + # not decode the qr code properly in tests + # (zbarimg needs to be told it is being given a qr code to decode) + #chunk=$( zbarimg --raw --set disable --set qrcode.enable ${img} 2>/dev/null ) if [ $? -ne 0 ]; then echo "failed to decode QR image" exit 2 From 5094f35d05664fcf2819e9665110298bbac867cf Mon Sep 17 00:00:00 2001 From: "Brock A. Martin" Date: Tue, 26 Jul 2016 07:21:04 -0500 Subject: [PATCH 5/6] switched out 'head' for 'dd' in order to do chunking --- asc2qr.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/asc2qr.sh b/asc2qr.sh index 2f0fe02..708d869 100755 --- a/asc2qr.sh +++ b/asc2qr.sh @@ -48,13 +48,13 @@ fi ## Split the key file into usable chunks that the QR encoder can consume chunks=() while true; do - s=$( head -c ${max_qr_bytes} ) + s=$( dd bs=${max_qr_bytes} count=1 2>/dev/null ) if [ ${#s} -gt 0 ]; then chunks+=("${s}") else break fi -done <<< "$( cat ${asc_key} )" +done < ${asc_key} ## For each chunk, encode it into a qr image index=1 From 9aa3a998d4a0e9a6ae67242039fd7d131b4afc64 Mon Sep 17 00:00:00 2001 From: "Brock A. Martin" Date: Tue, 26 Jul 2016 21:49:29 -0500 Subject: [PATCH 6/6] switched to read instead of 'dd' --- asc2qr.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/asc2qr.sh b/asc2qr.sh index 708d869..a10e3ef 100755 --- a/asc2qr.sh +++ b/asc2qr.sh @@ -48,7 +48,7 @@ fi ## Split the key file into usable chunks that the QR encoder can consume chunks=() while true; do - s=$( dd bs=${max_qr_bytes} count=1 2>/dev/null ) + IFS= read -r -d'\0' -n ${max_qr_bytes} s if [ ${#s} -gt 0 ]; then chunks+=("${s}") else