forked from jaysonsantos/iso2usb4mac
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathiso2usb.sh
More file actions
100 lines (86 loc) · 1.78 KB
/
iso2usb.sh
File metadata and controls
100 lines (86 loc) · 1.78 KB
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
#!/bin/bash
HELP="$(cat << EOF
Usage:
iso2usb.sh -i file.iso -d /dev/diskN
EOF)"
function help {
echo $HELP
exit 1
}
TMPDIR="$(mktemp -d /tmp/iso2usb.XXXXXXXXXX)"
function cleanup {
echo "Removing temp dir."
rm -rf "$TMPDIR"
}
trap cleanup EXIT
while getopts "i:d:" OPT
do
case $OPT in
i)
INFILE=$OPTARG
if [ ! -f "$INFILE" ]
then
echo "Invalid ISO file"
exit 1
fi
;;
d)
DISK=$OPTARG
if [ ! -b "$DISK" ]
then
echo "Invalid disk specified."
exit 1
fi
;;
\?)
help
;;
esac
done
if [ -z "$INFILE" -o -z "$DISK" ]
then
help
fi
echo "Listing the disk you specified."
diskutil list $DISK
while true
do
read -p"Is this the right disk? (y/n) " CONFIRM
if [ "$CONFIRM" = "y" ]
then
echo "Doing as you wish."
break
else
if [ "$CONFIRM" = "n" ]
then
echo "Breaking the process."
exit 1
else
echo "Wrong choice."
continue
fi
fi
done
echo "Converting ISO"
hdiutil convert -format UDRW -o "$TMPDIR/out" "$INFILE"
if [ "$?" -ne 0 ]
then
echo "Something went worng with hdiutil check logs above."
exit 1
fi
echo "File converted, erasing your disk and writing the new file. It will ask for your password."
diskutil unmountDisk "$DISK"
if [ "$?" -ne 0 ]
then
echo "diskutil was not able to unmount the disk, aborting operation."
exit 1
fi
sudo dd if="$TMPDIR/out.dmg" of="$DISK" bs=1m
if [ "$?" -eq 0 ]
then
echo "Convertion successful."
exit 0
else
echo "Something went wrong while writing on the disk."
exit 1
fi