-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathverifycd
executable file
·57 lines (45 loc) · 1.35 KB
/
verifycd
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
#!/bin/sh
######################################
# Usage: verifycd CDROM_DEVICE ISO_IMAGE
# example: verifycd /dev/cdrom image.iso
#
# References: http://www.troubleshooters.com/linux/coasterless.htm
#
# Inputs
DEVICE=$1
IMAGE_FILE=$2
# temp files
MD5SUM_ISO='md5sum-file.txt'
MD5SUM_CD='md5sum-cdrom.txt'
# Checking cd's blocksize and count
echo "Checking CD's block size, and count..."
blocksize=`isoinfo -d -i $DEVICE | grep "^Logical block size is:" | cut -d " " -f 5`
if test "$blocksize" = ""; then
echo catdevice FATAL ERROR: Blank blocksize >&2
exit
fi
blockcount=`isoinfo -d -i $DEVICE | grep "^Volume size is:" | cut -d " " -f 4`
if test "$blockcount" = ""; then
echo catdevice FATAL ERROR: Blank blockcount >&2
exit
fi
echo "block size: $blocksize"
echo "block count: $blockcount"
#Command for reading disk
raw_read_command="dd if=$DEVICE bs=$blocksize count=$blockcount conv=notrunc,noerror"
#Getting checksums
echo "Reading CD and creating check sum..."
$raw_read_command | md5sum > $MD5SUM_CD
echo "Reading ISO and creating check sum..."
md5sum $IMAGE_FILE > $MD5SUM_ISO
# Comparing md5 checksums
echo "Comparing check sums..."
cat $MD5SUM_ISO | while read CODE NAME; do
if [ -n "`cat $MD5SUM_CD | grep $CODE`" ]; then
echo "Success: $NAME"
else
echo "Failure: $NAME"
fi
done
#Cleaning up
#rm -f $MD5SUM_CD MD5SUM_ISO