initial commit

This commit is contained in:
2020-04-01 02:04:31 +02:00
commit 301a2d9987
6 changed files with 254 additions and 0 deletions

68
buttonpressed.sh Normal file
View File

@@ -0,0 +1,68 @@
#!/bin/sh
# daemon's name
DAEMON=scanbd
# securely create temporary file to avoid race condition attacks
TMPFILE=`mktemp /tmp/$DAEMON.XXXXXX`
# lock file
LOCKFILE="/tmp/$DAEMON.lock"
# device name
DEVICE="$2"
# destination of the final image file (modify to match your setup)
DESTINATION="/home/manolis/Desktop/scanned_image.jpg"
# remove temporary file on abort
trap 'rm -f $TMPFILE' 0 1 15
# function: create lock file with scanbuttond's PID
mk_lock() {
pidof $DAEMON > $LOCKFILE
}
# function: remove temporary and lock files
clean_up () {
test -e $LOCKFILE && rm -f $LOCKFILE
rm -f $TMPFILE
}
# function: check if lock file exists and print an error message with zenity (if it's installed)
chk_lock() {
if [ -e $LOCKFILE ]; then
if [ -x /usr/bin/zenity ]; then
zenity --display :0.0 --title="Scanbuttond" --error
--text="Another scanning operation is currently in progress."
fi
exit 1
fi
}
# function: the actual scan command (modify to match your setup)
scan() {
scanimage --device-name "$DEVICE" --mode Color --resolution 300
--depth 8 -x 215 -y 297 > $TMPFILE
}
case $1 in
1)
# button 1 (scan): scan the picture & save it as $DESTINATION
chk_lock; mk_lock; scan; convert $TMPFILE -quality 85 -quiet $DESTINATION; clean_up
;;
2)
# button 2 (copy): scan the picture, convert it to postscript and print it
chk_lock; mk_lock; scan; convert $TMPFILE ps:- | lpr; clean_up
;;
3)
# button 3 (mail): scan the picture, save it as $DESTINATION and send it as an e-mail
# attachment with Evolution
chk_lock; mk_lock; scan; convert $TMPFILE -quality 85 -quiet $DESTINATION
evolution --display=:0.0 "mailto:?attach=$DESTINATION"; clean_up
;;
4)
# button 4 (web): unconfigured
echo "button 4 has been pressed on $2"
;;
esac

43
readme.md Normal file
View File

@@ -0,0 +1,43 @@
## Setup
### Sane
```bash
sudo apt intall sane-utils
# add user to scanner group. Logout after this command
sudo adduser zero scanner
# find scanner ids
lsusb
# copy and modify udev example file to udev folder
sudo cp udev-example/55-libsane.rules /etc/udev/rules.d/
# restart udev service, than unplug and replug scanner
sudo service udev restart
# now this should run without sudo
scanimage -L
```
### Scanner button
```bash
sudo apt install scanbd
# create script directory
sudo mkdir /etc/scanbd/scripts
# copy script
sudo cp scannerbutton.sh /etc/scanbd/scripts/
# backup original plustek config
sudo mv /etc/scanbd/scanner.d/plustek.conf /etc/scanbd/scanner.d/plustek.conf.orig
# copy modified plustek.conf
sudo cp scanner.d/plustek.conf /etc/scanbd/scanner.d/
# restart scanbd
sudo service scanbd restart
```
## Scanning
```bash
scanimage -x 210 -y 297 --format=png --resolution 150 > /media/miniretek/scanner/scan-`date +%F-%H%M`.png
```
## Acknoledgements
scannerbutton.sh based on the script found here: https://www.linux.com/news/how-configure-scanners-buttons-linux/

60
scanner.d/plustek.conf Normal file
View File

@@ -0,0 +1,60 @@
/*
* $Id: snapscan.conf 154 2013-01-06 07:24:56Z wimalopaan $
*
* scanbd - KMUX scanner button daemon
*
* Copyright (C) 2008 - 2013 Wilhelm Meier (wilhelm.wm.meier@googlemail.com)
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
device plustek {
# the device matching string
filter = "plustek" # regex
# the device description
desc = "Canon N650"
action b0 {
filter = "^button.*0.*"
numerical-trigger {
from-value = 0
to-value = 1
}
desc = "Button0"
script = "scannerbutton.sh"
}
action b1 {
filter = "^button.*1.*"
numerical-trigger {
from-value = 0
to-value = 1
}
desc = "Button1"
script = "scannerbutton.sh"
}
action b2 {
filter = "^button.*2.*"
numerical-trigger {
from-value = 0
to-value = 1
}
desc = "Button2"
script = "scannerbutton.sh"
}
}

74
scannerbutton.sh Normal file
View File

@@ -0,0 +1,74 @@
#!/bin/sh
# Buttons:
# b0: E-mail
# b1: Copy
# b2: Scan
echo $SCANBD_ACTION
# daemon's name
#DAEMON=scanbd
# securely create temporary file to avoid race condition attacks
TMPFILE=`mktemp /tmp/$DAEMON.XXXXXX`
# lock file
LOCKFILE="/tmp/$DAEMON.lock"
# device name
#DEVICE="$2"
# destination of the final image file (modify to match your setup)
DESTINATION="media/miniretek/scanner/scan-`date +%F-%H%M`.png"
# remove temporary file on abort
trap 'rm -f $TMPFILE' 0 1 15
# function: create lock file with scanbuttond's PID
mk_lock() {
pidof $DAEMON > $LOCKFILE
}
# function: remove temporary and lock files
clean_up () {
test -e $LOCKFILE && rm -f $LOCKFILE
rm -f $TMPFILE
}
# function: check if lock file exists and print an error message with zenity (if it's installed)
chk_lock() {
if [ -e $LOCKFILE ]; then
if [ -x /usr/bin/zenity ]; then
zenity --display :0.0 --title="Scanbuttond" --error
--text="Another scanning operation is currently in progress."
fi
exit 1
fi
}
# function: the actual scan command (modify to match your setup)
scan() {
#scanimage --device-name "$DEVICE" --mode Color --resolution 300 --depth 8 -x 215 -y 297 > $TMPFILE
scanimage -x 210 -y 297 --format=png --resolution 150 > $TMPFILE
}
case $SCANBD_ACTION in
"b0")
# button 1 (scan): scan the picture & save it as $DESTINATION
#chk_lock; mk_lock; scan; convert $TMPFILE -quality 85 -quiet $DESTINATION; clean_up
echo "email button pressed"
;;
"b1")
# button 2 (copy): scan the picture, convert it to postscript and print it
#chk_lock; mk_lock; scan; convert $TMPFILE ps:- | lpr; clean_up
echo "copy button pressed"
;;
"b2")
# button 3 (mail): scan the picture, save it as $DESTINATION and send it as an e-mail
# attachment with Evolution
# chk_lock; mk_lock; scan; convert $TMPFILE -quality 85 -quiet $DESTINATION
# evolution --display=:0.0 "mailto:?attach=$DESTINATION"; clean_up
echo "scan button pressed"
;;
esac

8
scannerbutton.sh.1 Executable file
View File

@@ -0,0 +1,8 @@
#!/bin/bash
# Buttons:
# b0: E-mail
# b1: Copy
# b2: Scan
echo $SCANBD_ACTION

View File

@@ -0,0 +1 @@
ATTRS{idVendor}=="04a9", ATTRS{idProduct}=="220d", MODE="0660", GROUP="scanner", ENV{libsane_matched}="yes"