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 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292
|
#!/bin/bash
# Company: PowerCraft Technology
# Author: Copyright Jelle de Jong <jelledejong@powercraft.nl>
# Note: Please send me an email if you enhanced the script
# Date: 2009-01-09 / 2009-01-19 / ... / 2009-02-24 / 2009-03-31
# 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, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
# MA 02110-1301, USA.
# set -x
# exec 2>$HOME/pct-scanner-script-process.log
# STRACE=$(which strace)
TEXTDOMAINDIR=/usr/share/locale
TEXTDOMAIN=pct-scanner-script-process
file="$1"
version="0.0.4"
function process_busy_set()
{
if [ -d "$OUTDIR"/scanscript/ ]
then
mkdir --parents "$OUTDIR"/scanscript/
fi
processbusy="$OUTDIR"/scanscript/.processbusy.txt
touch "$processbusy"
trap "rm -f $processbusy" 0 1 2 3 15
}
function process_counter()
{
logfile="$1"
input=$(head -n 1 "$logfile")
input=${input##*: }
if [ -n "$input" ]
then
echo $"processing: page: $input"
count=${input}
let count+=1
find='counter:.*'
replace="counter: $count"
sed -i -e "s,$find,$replace,g" "$logfile"
echo $"processing: next page: $count"
fi
}
function process_grayscale()
{
sourcefile="$1"
logfile="$LOG"
date=$(date)
dirname=${sourcefile%/*}
filename=${sourcefile##*/}; filename=${filename%.*}
extension=${sourcefile##*.}
if [ ! -z "$SCAN_RES" ] && [ ! -z "$SCAN_WIDTH" ] && [ ! -z "$SCAN_HEIGHT" ] && [ ! -z "$SCAN_DEPTH" ] && [ ! -z "$SCAN_FORMAT" ]&& [ ! -z "$SCAN_FORMAT_ID" ]; then
echo $"processing: all needed variables are found, continuing now"
else
echo 1>&2 $"processing: system variables not found, exiting now"
exit 1
fi
echo "-- -- -- -- -- -- -- --" >> "$logfile"
echo "date: $date" >> "$logfile"
echo "scanadf: res:$SCAN_RES width:$SCAN_WIDTH height:$SCAN_HEIGHT depth:$SCAN_DEPTH format:$SCAN_FORMAT id:$SCAN_FORMAT_ID" >> "$logfile"
echo "processing: convert $sourcefile $OUTDIR/scanscript/processing/jpg/image-single-$filename.jpg" >> "$logfile"
$STRACE convert "$sourcefile" $OUTDIR/scanscript/processing/jpg/image-single-$filename.jpg
if [ -z $NOPDF ]; then
echo "processing: convert $OUTDIR/scanscript/processing/jpg/image-single-$filename.jpg $OUTDIR/scanscript/processing/pdf/document-single-page-$filename.pdf" >> "$logfile"
$STRACE convert $OUTDIR/scanscript/processing/jpg/image-single-$filename.jpg $OUTDIR/scanscript/processing/pdf/document-single-page-$filename.pdf
if [ -e $OUTDIR/scanscript/output/document-multi-page-grayscale.pdf ] && [ -e $OUTDIR/scanscript/processing/pdf/document-single-page-$filename.pdf ]
then
mv $OUTDIR/scanscript/output/document-multi-page-grayscale.pdf $OUTDIR/scanscript/output/document-multi-page-old.pdf
pdftk $OUTDIR/scanscript/output/document-multi-page-old.pdf $OUTDIR/scanscript/processing/pdf/document-single-page-$filename.pdf cat output $OUTDIR/scanscript/output/document-multi-page-grayscale.pdf
rm $OUTDIR/scanscript/output/document-multi-page-old.pdf
else
pdftk $OUTDIR/scanscript/processing/pdf/document-single-page-$filename.pdf cat output $OUTDIR/scanscript/output/document-multi-page-grayscale.pdf
fi
fi
if [ -z $NODJVU ]; then
echo "processing: c44 -crcbnone -dpi $SCAN_RES $sourcefile $OUTDIR/scanscript/processing/document-single-page-$filename.djvu" >> "$logfile"
echo $"processing: executing c44 compression command, please standby ..."
c44 -crcbnone -dpi $SCAN_RES "$sourcefile" $OUTDIR/scanscript/processing/document-single-page-$filename.djvu $EXEC_VERBOSE
# cpaldjvu -verbose -bgwhite -colors 8 -dpi 600 image-0007.pgm $OUTDIR/scanscript/processing/document-single-page-image-0007.djvu
# c44 -crcbnone -dpi 600 image-0008.pgm $OUTDIR/scanscript/processing/document-single-page-image-0008.djvu
if [ -e $OUTDIR/scanscript/output/document-multi-page-grayscale.djvu ] && [ -e $OUTDIR/scanscript/processing/document-single-page-$filename.djvu ]
then
djvm -insert $OUTDIR/scanscript/output/document-multi-page-grayscale.djvu $OUTDIR/scanscript/processing/document-single-page-$filename.djvu
else
djvm -create $OUTDIR/scanscript/output/document-multi-page-grayscale.djvu $OUTDIR/scanscript/processing/document-single-page-$filename.djvu
fi
fi
if [ ! -z "$RMINPUT" ]; then
echo "processing: removing input file: $sourcefile" >> "$logfile"
rm $VERBOSE "$sourcefile"
fi
echo "-- -- -- -- -- -- -- --" >> "$logfile"
process_counter "$logfile"
scanbusy="$OUTDIR"/scanscript/.scanbusy.txt
if [ ! -z "$OPEN" ] && [ -z "$NODJVU" ] && [ ! -e "$scanbusy" ]; then
nohup "$OPEN" "$OUTDIR"/scanscript/output/document-multi-page-grayscale.djvu > "$OUTDIR"/scanscript/.open.log 2>/dev/null &
elif [ ! -z "$OPEN" ] && [ -z "$NOPDF" ] && [ ! -e "$scanbusy" ]; then
nohup "$OPEN" "$OUTDIR"/scanscript/output/document-multi-page-grayscale.pdf > "$OUTDIR"/scanscript/.open.log 2>/dev/null &
fi
return
}
function process_color()
{
sourcefile="$1"
logfile="$LOG"
date=$(date)
dirname=${sourcefile%/*}
filename=${sourcefile##*/}; filename=${filename%.*}
extension=${sourcefile##*.}
if [ ! -z "$SCAN_RES" ] && [ ! -z "$SCAN_WIDTH" ] && [ ! -z "$SCAN_HEIGHT" ] && [ ! -z "$SCAN_DEPTH" ] && [ ! -z "$SCAN_FORMAT" ]&& [ ! -z "$SCAN_FORMAT_ID" ]; then
echo $"processing: all needed variables are found, continuing now"
else
echo 1>&2 $"processing: system variables not found, exiting now"
exit 1
fi
echo "-- -- -- -- -- -- -- --" >> "$logfile"
echo "date: $date" >> "$logfile"
echo "scanadf: res:$SCAN_RES width:$SCAN_WIDTH height:$SCAN_HEIGHT depth:$SCAN_DEPTH format:$SCAN_FORMAT id:$SCAN_FORMAT_ID" >> "$logfile"
echo "processing: convert $sourcefile $OUTDIR/scanscript/processing/jpg/image-single-$filename.jpg" >> "$logfile"
$STRACE convert "$sourcefile" "$OUTDIR/scanscript/processing/jpg/image-single-$filename.jpg"
if [ -z $NOPDF ]; then
echo "processing: convert $OUTDIR/scanscript/processing/jpg/image-single-$filename.jpg $OUTDIR/scanscript/processing/pdf/document-single-page-$filename.pdf" >> "$logfile"
$STRACE convert "$OUTDIR/scanscript/processing/jpg/image-single-$filename.jpg" "$OUTDIR/scanscript/processing/pdf/document-single-page-$filename.pdf"
if [ -e $OUTDIR/scanscript/output/document-multi-page-color.pdf ] && [ -e $OUTDIR/scanscript/processing/pdf/document-single-page-$filename.pdf ]
then
mv $OUTDIR/scanscript/output/document-multi-page-color.pdf $OUTDIR/scanscript/output/document-multi-page-old.pdf
pdftk $OUTDIR/scanscript/output/document-multi-page-old.pdf $OUTDIR/scanscript/processing/pdf/document-single-page-$filename.pdf cat output $OUTDIR/scanscript/output/document-multi-page-color.pdf
rm $OUTDIR/scanscript/output/document-multi-page-old.pdf
else
pdftk $OUTDIR/scanscript/processing/pdf/document-single-page-$filename.pdf cat output $OUTDIR/scanscript/output/document-multi-page-color.pdf
fi
fi
if [ -z $NODJVU ]; then
echo "processing: c44 -dpi $SCAN_RES $sourcefile $OUTDIR/scanscript/processing/document-single-page-$filename.djvu" >> "$logfile"
echo $"processing: executing c44 compression command, please standby ..."
c44 -dpi $SCAN_RES "$sourcefile" $OUTDIR/scanscript/processing/document-single-page-$filename.djvu $EXEC_VERBOSE
# cpaldjvu -verbose -bgwhite -colors 8 -dpi 600 image-0007.pgm $OUTDIR/scanscript/processing/document-single-page-image-0007.djvu
# c44 -crcbnone -dpi 600 image-0008.pgm $OUTDIR/scanscript/processing/document-single-page-image-0008.djvu
# cpaldjvu -verbose -dpi $SCAN_RES -bgwhite "$sourcefile" ~/scanjet/processing/document-single-page-$filename.djvu
# c44 -dpi 600 /home/jelle/scanjet/input/image-0001.ppm /home/jelle/scanjet/processing/document-single-page-image-0001.djvu
if [ -e $OUTDIR/scanscript/output/document-multi-page-color.djvu ] && [ -e $OUTDIR/scanscript/processing/document-single-page-$filename.djvu ]
then
djvm -insert $OUTDIR/scanscript/output/document-multi-page-color.djvu $OUTDIR/scanscript/processing/document-single-page-$filename.djvu
else
djvm -create $OUTDIR/scanscript/output/document-multi-page-color.djvu $OUTDIR/scanscript/processing/document-single-page-$filename.djvu
fi
fi
if [ ! -z "$RMINPUT" ]; then
echo "processing: removing input file: $sourcefile" >> "$logfile"
rm $VERBOSE "$sourcefile"
fi
echo "-- -- -- -- -- -- -- --" >> "$logfile"
process_counter "$logfile"
scanbusy="$OUTDIR"/scanscript/.scanbusy.txt
if [ ! -z "$OPEN" ] && [ -z "$NODJVU" ] && [ ! -e "$scanbusy" ]; then
nohup "$OPEN" $OUTDIR/scanscript/output/document-multi-page-color.djvu > "$OUTDIR"/scanscript/.open.log 2>/dev/null &
elif [ ! -z "$OPEN" ] && [ -z "$NOPDF" ] && [ ! -e "$scanbusy" ]; then
nohup "$OPEN" $OUTDIR/scanscript/output/document-multi-page-color.pdf > "$OUTDIR"/scanscript/.open.log 2>/dev/null &
fi
return
}
function process_lineart()
{
sourcefile="$1"
logfile="$LOG"
date=$(date)
dirname=${sourcefile%/*}
filename=${sourcefile##*/}; filename=${filename%.*}
extension=${sourcefile##*.}
if [ ! -z "$SCAN_RES" ] && [ ! -z "$SCAN_WIDTH" ] && [ ! -z "$SCAN_HEIGHT" ] && [ ! -z "$SCAN_DEPTH" ] && [ ! -z "$SCAN_FORMAT" ]&& [ ! -z "$SCAN_FORMAT_ID" ]; then
echo $"processing: all needed variables are found, continuing now"
else
echo 1>&2 $"processing: system variables not found, exiting now"
exit 1
fi
echo "-- -- -- -- -- -- -- --" >> "$logfile"
echo "date: $date" >> "$logfile"
echo "scanadf: res:$SCAN_RES width:$SCAN_WIDTH height:$SCAN_HEIGHT depth:$SCAN_DEPTH format:$SCAN_FORMAT id:$SCAN_FORMAT_ID" >> "$logfile"
echo "processing: convert $sourcefile $OUTDIR/scanscript/processing/jpg/image-single-$filename.jpg" >> "$logfile"
$STRACE convert "$sourcefile" $OUTDIR/scanscript/processing/jpg/image-single-$filename.jpg
if [ -z $NODJVU ]; then
echo "processing: cjb2 -verbose -clean -dpi $SCAN_RES $sourcefile $OUTDIR/scanscript/processing/document-single-page-$filename.djvu" >> "$logfile"
cjb2 -verbose -clean -dpi $SCAN_RES "$sourcefile" $OUTDIR/scanscript/processing/document-single-page-$filename.djvu $EXEC_VERBOSE
if [ -e $OUTDIR/scanscript/output/document-multi-page-lineart.djvu ] && [ -e $OUTDIR/scanscript/processing/document-single-page-$filename.djvu ]
then
djvm -insert $OUTDIR/scanscript/output/document-multi-page-lineart.djvu $OUTDIR/scanscript/processing/document-single-page-$filename.djvu
else
djvm -create $OUTDIR/scanscript/output/document-multi-page-lineart.djvu $OUTDIR/scanscript/processing/document-single-page-$filename.djvu
fi
fi
if [ -z $NOPDF ]; then
echo "processing: convert $OUTDIR/scanscript/processing/jpg/image-single-$filename.jpg $OUTDIR/scanscript/processing/pdf/document-single-page-$filename.pdf" >> "$logfile"
$STRACE convert $OUTDIR/scanscript/processing/jpg/image-single-$filename.jpg $OUTDIR/scanscript/processing/pdf/document-single-page-$filename.pdf
if [ -e $OUTDIR/scanscript/output/document-multi-page-lineart.pdf ] && [ -e $OUTDIR/scanscript/processing/pdf/document-single-page-$filename.pdf ]
then
mv $OUTDIR/scanscript/output/document-multi-page-lineart.pdf $OUTDIR/scanscript/output/document-multi-page-old.pdf
pdftk $OUTDIR/scanscript/output/document-multi-page-old.pdf $OUTDIR/scanscript/processing/pdf/document-single-page-$filename.pdf cat output $OUTDIR/scanscript/output/document-multi-page-lineart.pdf
rm $OUTDIR/scanscript/output/document-multi-page-old.pdf
else
pdftk $OUTDIR/scanscript/processing/pdf/document-single-page-$filename.pdf cat output $OUTDIR/scanscript/output/document-multi-page-lineart.pdf
fi
fi
if [ ! -z "$RMINPUT" ]; then
echo "processing: removing input file: $sourcefile" >> "$logfile"
rm $VERBOSE "$sourcefile"
fi
echo "-- -- -- -- -- -- -- --" >> "$logfile"
process_counter "$logfile"
scanbusy="$OUTDIR"/scanscript/.scanbusy.txt
if [ ! -z "$OPEN" ] && [ -z "$NODJVU" ] && [ ! -e "$scanbusy" ]; then
nohup "$OPEN" $OUTDIR/scanscript/output/document-multi-page-lineart.djvu > "$OUTDIR"/scanscript/.open.log 2>/dev/null &
elif [ ! -z "$OPEN" ] && [ -z "$NOPDF" ] && [ ! -e "$scanbusy" ]; then
nohup "$OPEN" $OUTDIR/scanscript/output/document-multi-page-lineart.pdf > "$OUTDIR"/scanscript/.open.log 2>/dev/null &
fi
return
}
if [ ! -z "$LOG" ] && [ ! -z "$OUTDIR" ]; then
process_busy_set;
if [ ! -z $LINEART ]; then
process_lineart "$file";
elif [ ! -z $COLOR ]; then
process_color "$file";
elif [ ! -z $GRAYSCALE ]; then
process_grayscale "$file";
fi
else
echo 1>&2 $"processing: system variables not found, exiting now"
exit 1
fi
exit
|