48 lines
1.5 KiB
Bash
Executable File
48 lines
1.5 KiB
Bash
Executable File
#!/bin/bash
|
|
|
|
mysql --user=root --password="$(pass show sevenkeys/mysql)" <createtable.sql
|
|
|
|
printf "scantap: Enter name of storage box: "
|
|
read storageBox
|
|
|
|
startPosition="$(mysql --silent --silent --user=root --password="$(pass show sevenkeys/mysql)" -e "USE sevenkeys; SELECT Position FROM CardScans WHERE StorageBox = '$storageBox' ORDER BY Position DESC LIMIT 1;")"
|
|
position=$((startPosition + 1))
|
|
|
|
printf "scantap: Enter card source: "
|
|
read cardSource
|
|
|
|
printf "scantap: Enter mode (foil/nonfoil): "
|
|
read foilMode
|
|
outputDir="images/$foilMode"
|
|
mkdir -p "$outputDir"
|
|
|
|
ADD_CARDS=0
|
|
echo "scantap: Beginning scan loop"
|
|
while true; do
|
|
scanimage --format=png --batch=tmp%d.png --batch-count=2 --source "ADF Duplex" --mode Color --page-width 63mm --page-height 88mm 2>/dev/null
|
|
|
|
# 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
|
|
|
|
if ! test -e tmp1.png || ! test -e tmp2.png; then
|
|
echo "scantap: Failed to create temporary image files"
|
|
fi
|
|
|
|
key="$(mysql --silent --silent --user=root --password="$(pass show sevenkeys/mysql)" -e "USE sevenkeys; INSERT INTO CardScans (StorageBox, Position, Source) VALUES ('$storageBox', '$position', '$cardSource'); SELECT Id FROM CardScans ORDER BY Id DESC LIMIT 1;")"
|
|
position=$((position + 1))
|
|
|
|
convert -rotate 180 tmp1.png tmp1.png
|
|
convert -rotate 180 tmp2.png tmp2.png
|
|
|
|
mv tmp1.png "$outputDir/${key}_back.png"
|
|
mv tmp2.png "$outputDir/${key}_front.png"
|
|
done
|