#!/bin/bash
#
# $Id: scanadf.script 31 2010-11-25 08:59:51Z wimalopaan $
#
#  scanbd - KMUX scanner button daemon
#
#  Copyright (C) 2008  Wilhelm Meier (wilhelm.meier@fh-kl.de)
#
#  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., 675 Mass Ave, Cambridge, MA 02139, USA.
#

scan_dir=/var/spool/scan
datetime=`date +%F_%H%M%S`
filename=scan-$datetime
#send_to=machanska@seznam.cz
send_to=rasto@ynet.sk

logger -t "scanbd: $0" "Begin of $SCANBD_ACTION"

case $SCANBD_ACTION in
 scan)
  scanner=$(echo $SCANBD_DEVICE | cut -d ':' -f 1)
  scanimage  | convert -density 300 - $scan_dir/$filename.ps
  ps2pdf  -sPAPERSIZE=a4 $scan_dir/$filename.ps $scan_dir/$filename.pdf
  rm $scan_dir/$filename.ps
  ;;
 copy)
  scanimage  | convert -density 300 - $scan_dir/$filename.ps
  lp $scan_dir/$filename.ps
  rm $scan_dir/$filename.ps
  ;;
email)
  scanimage  | convert -density 300 - $scan_dir/$filename.ps
  ps2pdf  -sPAPERSIZE=a4 $scan_dir/$filename.ps $scan_dir/$filename.pdf
  (cat <<EOCAT
Dokument bol oskenovany pomocou Canon LiDE 110 a poslany z krabice na polici
EOCAT
uuencode $scan_dir/$filename.pdf $scan_dir/$filename.pdf ) | mail -a "From: Canon scanner <rastislav.david@seznam.cz>" -s "Dokument $filename" $send_to
  rm $scan_dir/$filename.ps
  ;;
*)
  logger -t "scanbd: $0" "Unhandled action request."
  ;;
esac




##scan a batch
#scanimage –format pnm –batch –batch-prompt –resolution 150 –mode Gray

##convert the raw file to postscript
#convert -density 150 *.pnm out.ps

##convert the postscript to pdf
#ps2pdf -sPAPERSIZE=a4 out.ps out.pdf 

logger -t "scanbd: $0" "End of $SCANBD_ACTION"
