-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathusb_burnomatic.sh
executable file
·70 lines (62 loc) · 1.21 KB
/
usb_burnomatic.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
#!/bin/bash
if [ $UID -ne 0 ] ;then
echo "Must be root to execute!"
exit 1
fi
exclude="/dev/sda" # case regex syntax
known_good_md5="d58bc15213a3c7440974e7b5d46f8812"
ISO="/home/hax/known_good_usb.img"
md5_only(){
drive=$1
md5=$2
drive_md5=`md5sum $drive | cut -d' ' -f1`
echo Known good ${md5}
echo $drive $drive_md5
if [ "$drive_md5" = "${md5}" ] ;then
echo Hash matches
return 0
else
echo "ERROR: Drive $drive failed checksum" 1>&2
return 1
fi
}
burn_usb_from_hybrid_iso(){
iso=$1
drive=$2
md5=$3
dd if=$iso of=$drive
ret=$?
if [ $ret -eq 0 ] ;then
sync
drive_md5=`md5sum $drive | cut -d' ' -f1`
echo Known good ${md5}
echo $drive $drive_md5
if [ "$drive_md5" = "${md5}" ] ;then
echo Successfully burned drive $drive
return 0
else
echo "ERROR: Drive $drive failed checksum" 1>&2
fi
else
echo "ERROR: Failed to burn drive $drive" 1>&2
return 1
fi
}
for i in /dev/sd? ;do
case "$i" in
"$exclude")
echo Skipping drive $i
;;
*)
echo Burning to drive $i
if [ "$1" = "-md5" ] ;then
md5_only "$i" "$known_good_md5" &
else
burn_usb_from_hybrid_iso "$ISO" "$i" "$known_good_md5" &
fi
;;
esac
done
wait
echo !!! Done !!!
aplay /usr/share/sounds/pop.wav