TheMathemagicians/sevenkeys/card_scanner

33 lines
1.0 KiB
Plaintext
Raw Normal View History

2024-08-17 19:13:51 +00:00
#!/bin/bash
2024-10-10 09:56:35 +00:00
STORAGE_DIR="$HOME/.local/share/sevenkeys/scanimages/"
mkdir -p "$STORAGE_DIR"
2024-08-17 19:13:51 +00:00
ADD_CARDS=0
echo "scantap: Beginning scan loop"
while true; do
2024-10-10 09:56:35 +00:00
rng="$(cat /dev/random | tr -cd 'a-f0-9' | head -c 32)"
filename="$STORAGE_DIR/$rng.png"
scanimage --output-file="$filename" --source "ADF Front" --mode Color --page-width 63mm --page-height 88mm 2>/dev/null
2024-08-17 19:13:51 +00:00
# scanimage exits with code 7 if no documents are available in scanner
if test $? -eq 7; then
if test $ADD_CARDS -eq 0; then
ADD_CARDS=1
echo "scantap: No more cards in feeder" >&2
fi
continue
fi
ADD_CARDS=0
2024-10-10 09:56:35 +00:00
convert -rotate 180 "$filename" "$filename"
2024-08-17 19:13:51 +00:00
2024-10-10 09:56:35 +00:00
# TODO: Add "store" command to sevenkeys executable to avoid duplicating insert logic here, then `./sevenkeys --profile=production store --id="0000..0000"`
# Return inserted CardLocationId
#cardLocationId="1"
#mysql --silent --silent --user=root --password="$(pass show sevenkeys/mysql \
#-e "USE sevenkeys; INSERT INTO CardScan (CardLocationId, Filename) VALUES ('$cardLocationId', '$filename.png');"
2024-08-17 19:13:51 +00:00
done