-
Notifications
You must be signed in to change notification settings - Fork 0
/
brscan_to_pc
executable file
·154 lines (134 loc) · 3.2 KB
/
brscan_to_pc
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
#!/bin/bash
#
# brscan_to_pc [project: ZigzagScan&Print (zsp)
#
# 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 3 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/.
#
# Copyright (C) 2019: Gianluca Zoni (zoninoz) <[email protected]>
#
# Gianluca Zoni
# http://inventati.org/zoninoz
#
#set -x
brscan_mode="$1"
shift
###############################
# $1 = scanner device
# $2 = friendly name
#
scanner_device="$1"
scanner_device_name="$2"
share="/usr/local/share/zsp"
source "$share"/common.sh
source "$share"/utils.sh
function usage {
cat <<EOF
Usage:
$(basename $0) brscan_mode [scanner device] [friendly name]
Respect the order of the arguments.
EOF
}
get_configuration
if [ -n "$filename" ]
then
output_tmp="$directory"/"$filename"
else
output_tmp="$directory"/$(date | sed -r 's|[ :,]+|_|g')
fi
if [ -z "$scanner_device_name" ]
then
scanner_device_name=$(get_name scanner_device)
fi
## RUN SCANNER
sleep 1
echo "Scan from ${scanner_device_name} ($scanner_device)"
for loop in 1 2 3
do
if run_scanner "$scanner_device"
then
test_scanimage=true
break
else
test_scanimage=false
sleep 0.5
fi
done
if [ "$test_scanimage" == false ]
then
echo "$err_scanner_msg"
exit 1
fi
## ORIENTATION
if [ "$scanner_orientation" == landscape ]
then
case "$scanner_format" in
tiff|pnm)
convert_orientation_"$scanner_format"
;;
*)
convert_orientation_images
;;
esac
fi
## PDF
if [ "$convert_format" == pdf ]
then
convert2pdf
fi
## CLEAN UP
if [ "$convert_clean_up" == TRUE ]
then
if [ "$convert_format" == pdf ]
then
for frm in pnm tiff png jpeg
do
rm -f "$output_tmp"*.$frm
done
fi
rm -f "$pnmfile".ps
fi
## PRINT PDF
[ "$lp_print_pdf" == TRUE ] &&
[ -f "$output_tmp".pdf ] &&
print_pdf "$output_tmp".pdf
## MODE
case "$brscan_mode" in
email)
muttrc=$(mktemp)
cat >"$muttrc" <<EOF
set charset="UTF-8"
set send_charset="UTF-8"
set date_format = "%d-%m-%y, %H:%M"
set copy = no
set from = "$email_username"
set smtp_url="${email_proto}://${email_username}:${email_password}@${email_server}:${email_port}"
EOF
mutt -F "$muttrc" \
-s "$(gettext "Scanned document")" \
-a "${output_tmp}"*."$convert_format" \
-- "$email_recipient" \
<<< "$(gettext "Attached scanned document from") $(get_name scanner_device)" &&
echo "$(gettext "Mail sent to") $email_recipient"
;;
ocr)
for f in "${output_tmp}"*."$convert_format"
do
echo -e "Tesseract OCR: $f to ${f%.*}\n$(gettext "wait ...")"
tesseract "$f" "${f%.*}"
echo -e "Tesseract OCR: $f to ${f%.*}\n$(gettext "done")"
done
;;
esac
echo
exit 0