-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathjustscan.sh
80 lines (67 loc) · 1.92 KB
/
justscan.sh
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
#!/bin/bash
# dependency: scanimage
function show_help() {
echo
echo -e "USAGE: bash justscan.sh -d <OUTPUT DIRECTORY> -c <ID> \n"
echo -e "-d : The directory you want to write to, please no trailing /, e.g. /ECSL-CDs"
echo -e "-c : The ID of the item, e.g. callnumber, accessionID, diskID, etc. No spaces"
echo -e "Example:\njustscan.sh -d /ECSL-CDs -c qa76.73.j38.r54.2002x will output: /ECSL-CDs/QA76-73-J38-R54-2002x.tiff"
echo
exit 1
}
OPTIND=1
dir=""
dir=${dir%/}
ID=""
diskID=""
# Parse arguments
while getopts "h?d:c:" opt; do
case "$opt" in
h|\?)
show_help
;;
d) dir=$OPTARG
;;
c) ID=$OPTARG
;;
esac
done
shift $((OPTIND-1))
[ "$1" = "--" ] && shift
garbage="$@"
# Check all required parameters are present
if [ -z "$dir" ] || [ -z "$ID" ] || [ "$garbage" ]; then
echo "parameters required"
exit 1
fi
### Clean ID ###
diskID=${ID^^//./-} #make all caps and replace . with -
### Get correct scanner location ###
bus=$(lsusb | grep Epson | cut -d " " -f 2)
device=$(lsusb | grep Epson | cut -d " " -f 4 | cut -d ":" -f 1)
scanimage -L
echo "Epson scanner at Bus: $bus Device: $device"
echo "If scanner not found (no bus/device), then scanner is not available."
echo
scanner="epson2:libusb:$bus:$device"
tiff="${dir}/${diskID}.tiff"
#cropped="$dir/$diskID.tiff"
if [ -e $tiff ]; then
echo $tiff "already exists:"
ls -l $tiff
read -p "Would you like to replace existing scan? [y/n] " response
if [[ "$response" =~ ^([Nn])+$ ]]; then
exit
fi
fi
mkdir -p ${dir}
scanimage --mode=Color --format=tiff --resolution 300 -x 150 -y 150 >> $tiff
if [ $tiff ]; then
echo "scan complete"
ls -l $tiff
else
echo "ERROR: ${tiff} not found."
fi
### old code for cropping image to edges
#convert $tiff -crop `convert $tiff -virtual-pixel edge -blur 0x15 -fuzz 15% -trim -format '%[fx:w]x%[fx:h]+%[fx:page.x]+%[fx:page.y]' info:` +repage $cropped
#echo "image cropped"