summaryrefslogtreecommitdiffstats
path: root/krebs/5pkgs/simple/qrscan.nix
diff options
context:
space:
mode:
authormakefu <github@syntax-fehler.de>2019-04-26 20:35:52 +0200
committermakefu <github@syntax-fehler.de>2019-04-26 20:35:52 +0200
commit2685464a60f32c75cf9198383ca10c3d6cf55572 (patch)
tree698bd32e2cc51be596771cc0e76ffd8521a64ff5 /krebs/5pkgs/simple/qrscan.nix
parent95f6a06c5acfb6054236ea2f5aee42975dd909ec (diff)
parentcd825d99342050bae35d5373e927ca999bae82cf (diff)
Merge branch 'master' of prism:stockholm
Diffstat (limited to 'krebs/5pkgs/simple/qrscan.nix')
-rw-r--r--krebs/5pkgs/simple/qrscan.nix27
1 files changed, 27 insertions, 0 deletions
diff --git a/krebs/5pkgs/simple/qrscan.nix b/krebs/5pkgs/simple/qrscan.nix
new file mode 100644
index 000000000..7d99dcee7
--- /dev/null
+++ b/krebs/5pkgs/simple/qrscan.nix
@@ -0,0 +1,27 @@
+{ coreutils, gnused, writeDashBin, zbar }:
+
+writeDashBin "qrscan" ''
+ set -efu
+
+ tmpdir=$(${coreutils}/bin/mktemp --tmpdir -d qrscan.XXXXXXXX)
+ codefile=$tmpdir/code
+
+ cleanup() {
+ ${coreutils}/bin/rm "$codefile"
+ ${coreutils}/bin/rmdir "$tmpdir"
+ }
+
+ ${coreutils}/bin/mkfifo "$codefile"
+
+ ${zbar}/bin/zbarcam > "$codefile" &
+ zbarcampid=$!
+
+ exec < "$codefile"
+ while read -r code; do
+ code=$(printf %s "$code" | ${gnused}/bin/sed -n 's/^QR-Code://p')
+ if test -n "$code"; then
+ ${coreutils}/bin/kill "$zbarcampid"
+ echo "$code"
+ fi
+ done
+''