summaryrefslogtreecommitdiffstats
path: root/krebs/5pkgs/simple
diff options
context:
space:
mode:
authortv <tv@krebsco.de>2019-04-17 21:49:43 +0200
committertv <tv@krebsco.de>2019-04-17 21:49:43 +0200
commite051fecf9c19d446d6588bd21070fd1a799b97a3 (patch)
tree0bb2c728046a728616f848ab52a581cca8b24a85 /krebs/5pkgs/simple
parent84ad0b0a93eccdef0e4ca05fd4091f014cb1ac25 (diff)
qrscan: init
Diffstat (limited to 'krebs/5pkgs/simple')
-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
+''