summaryrefslogtreecommitdiff
path: root/bin/copydvd
blob: 6b939c68c53d47d8d727756f4c01be0c23a8a9b2 (plain)
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
#!/bin/bash

#Usage: copydvd <read> <write>

#Make sure we are running as root (otherwise we can't burn later)
if [ `whoami` != "root" ]
then
echo "This script must be run as root."
exit 1
fi

DEVICE1="$1"
DEVICE2="$2"

TMPDIR=`mktemp -d` || exit 1
ISOPIPE="$TMPDIR/pipe.iso"
READERR="$TMPDIR/mkisoerr"

mkfifo "$ISOPIPE"

echo "Burning directory..."

growisofs -dvd-compat -Z "$DEVICE2"="$ISOPIPE" &
BURNER=$!
MD5=`dd if="$DEVICE1" 2>"$READERR" | tee "$ISOPIPE" | md5sum | egrep -o -i -e "^[0-9a-f]{32}"`

EXTENTS=`egrep -e "^[0-9]+ extents written " "$READERR" | egrep -o -e "^[0-9]+"`

wait "$BURNER"

echo "Wrote $EXTENTS extents with a MD5 hash of $MD5."
echo "Cycling drive tray..."

eject "$DEVICE2"
eject -t "$DEVICE2"

# Arch Linux seems to have problems without a wait
# here; gives dd: opening `/dev/sr1': No medium found otherwise
sleep 15

echo "Verifying..."

DISCMD5=`dd if="$DEVICE2" bs=2048 count="$EXTENTS" | md5sum | egrep -o -i -e "^[0-9a-f]{32}"`

echo "Disc has an MD5 hash of $DISCMD5."

if [ "$MD5" == "$DISCMD5" ]
then
echo "Disc appears to have burned successfully!"
else
echo "Disc appears to have burned with errors."
fi

rm -r "$TMPDIR"