File: actions.script

package info (click to toggle)
scanbd 1.4.0-2
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 2,604 kB
  • ctags: 915
  • sloc: sh: 11,577; ansic: 7,612; makefile: 251
file content (136 lines) | stat: -rw-r--r-- 5,073 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash
#
# Scanbd actions script v1.0 for EPSON Perfection V200 Photo (4 buttons)
#
# Copyright (C) 2012 - The Home Server Handbook - thehomeserverhandbook.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, see <http://www.gnu.org/licenses/>.
#
#                    *************************
#
# Usage:
#
# Press [Start] button to scan a document and save it as a JPEG image.
# In Pdf mode, pressing the [Start] button scans the next page.
#
# Press [Copy] button to scan and print a single page document.
#
# Press [Email] button to scan a document and save it as a JPEG attachment
# to an .eml file. To edit the email, import / drag'n drop it in the drafts
# folder of your preferred eml compatible email client.
# In Pdf mode, pressing the [Email] button saves the scan(s) as a single
# PDF attachment to an .eml file.
#
# Press [Pdf] button to enter Pdf mode and scan the first page of a
# document. Then, each press on the [Start] button scans the next page.
# Finally, press again the [Pdf] button to save the scan(s) as a PDF file
# and exit the Pdf mode.

TMPDIR="/mnt/data/tmp/"
SCANDIR="/mnt/data/Public/Scans/" # modify according to your own setup
FILENAME="scan-`date +%F_%H%M%S`"
PAGEBASE="page-"
TIMEOUT="2" # in minutes, specify auto escape delay for the Pdf mode
PRINTER="Lexmark_E260d" # modify according to your own setup
EMAIL="someone@example.org" # email address of receiver
USER="user" # useful when saving scans in NFS shared directory
GROUP="group" # useful when saving scans in NFS shared directory

export MAGICK_TMPDIR="${TMPDIR}" # Override default cache of convert command. Needed for systems with very small /tmp (e.g. ramdisk).

case "$SCANBD_ACTION" in

    scan)
	STARTANEW=`find ${TMPDIR} -mindepth 1 -maxdepth 1 -name "${PAGEBASE}*.tif" -mmin -${TIMEOUT} 2> /dev/null | wc -l`

	if [ "0${STARTANEW}" -eq 0 ]; then
		scanimage -d "$SCANBD_DEVICE" \
		--icc-profile=/usr/share/color/icc/sRGB.icm --format=tiff \
		--mode=Color --depth=8 --resolution=300 \
		> "${TMPDIR}${FILENAME}.tif"

		convert -rotate 180 "${TMPDIR}${FILENAME}.tif" "${SCANDIR}${FILENAME}.jpg"
		chown "${USER}:${GROUP}" "${SCANDIR}${FILENAME}.jpg"

		rm "${TMPDIR}${FILENAME}.tif"
	else
		NEXTPAGE=`expr 1 + \`ls -1 "${TMPDIR}${PAGEBASE}"*.tif | wc -l\``

		scanimage -d "$SCANBD_DEVICE" \
		--icc-profile=/usr/share/color/icc/sRGB.icm --format=tiff \
		--mode=Color --depth=8 --resolution=150 \
		> "${TMPDIR}${PAGEBASE}`printf %.5d ${NEXTPAGE}`.tif"
	fi
    ;;

    copy)
	scanimage -d "$SCANBD_DEVICE" --format=tiff --mode=Gray --depth=8 \
	--resolution=300 \
	| convert - -density 300 ps:- \
	| lp -d "${PRINTER}"
    ;;

    email)
	STARTANEW=`find "${TMPDIR}" -mindepth 1 -maxdepth 1 -name "${PAGEBASE}*.tif" -mmin -${TIMEOUT} 2> /dev/null | wc -l`

	if [ "0${STARTANEW}" -eq 0 ]; then
		scanimage -d "$SCANBD_DEVICE" \
		--icc-profile=/usr/share/color/icc/sRGB.icm --format=tiff \
		--mode=Color --depth=8 --resolution=150 \
		> "${TMPDIR}${FILENAME}.tif"

		convert -rotate 180 "${TMPDIR}${FILENAME}.tif" "${TMPDIR}${FILENAME}.jpg"
		touch "${TMPDIR}${FILENAME}.txt"
		mpack -s "Scanned document ${FILENAME}" -d "${TMPDIR}${FILENAME}.txt" \
		-o "${TMPDIR}${FILENAME}.eml" "${TMPDIR}${FILENAME}.jpg"

		cat "${TMPDIR}${FILENAME}.eml" | sendmail -v "${EMAIL}"

		rm "${TMPDIR}${FILENAME}.tif" "${TMPDIR}${FILENAME}.eml" "${TMPDIR}${FILENAME}.jpg" "${TMPDIR}${FILENAME}.txt"
	else
		convert -rotate 180 -units PixelsPerInch -density 150 -compress jpeg \
		"${TMPDIR}${PAGEBASE}"*.tif "${TMPDIR}${FILENAME}.pdf"

		touch "${TMPDIR}${FILENAME}.txt"
		mpack -s "Scanned document ${FILENAME}" -d "${TMPDIR}${FILENAME}.txt" \
		-o "${TMPDIR}${FILENAME}.eml" "${TMPDIR}${FILENAME}.pdf"

		cat "${TMPDIR}${FILENAME}.eml" | sendmail -v "${EMAIL}"

		rm "${TMPDIR}${PAGEBASE}"*.tif "${TMPDIR}${FILENAME}.eml" "${TMPDIR}${FILENAME}.pdf" "${TMPDIR}${FILENAME}.txt"
	fi
    ;;

    file)
	STARTANEW=`find "${TMPDIR}" -mindepth 1 -maxdepth 1 -name "${PAGEBASE}*.tif" -mmin -${TIMEOUT} 2> /dev/null | wc -l`

	if [ "0${STARTANEW}" -eq 0 ]; then
		rm "${TMPDIR}${PAGEBASE}"*.tif &> /dev/null

		scanimage -d "$SCANBD_DEVICE" \
		--icc-profile=/usr/share/color/icc/sRGB.icm --format=tiff \
		--mode=Color --depth=8 --resolution=150 \
		> "${TMPDIR}${PAGEBASE}00001.tif"
	else
		convert -rotate 180 -units PixelsPerInch -density 150 -compress jpeg \
		"${TMPDIR}${PAGEBASE}"*.tif "${SCANDIR}${FILENAME}.pdf"
		chown "${USER}:${GROUP}" "${SCANDIR}${FILENAME}.pdf"

		rm "${TMPDIR}${PAGEBASE}"*.tif
	fi
    ;;

esac

exit 0