This repository has been archived by the owner on Nov 7, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 77
/
burn-image.sh
executable file
·57 lines (53 loc) · 1.51 KB
/
burn-image.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
#!/bin/bash
echo "************************************"
files=("./"*.img)
PS3='Select image file, or 0 to exit: '
select file in "${files[@]}"; do
if [[ $REPLY == "0" ]]; then
echo 'Bye!' >&2
exit
# test for zero length of string
elif [[ -z $file ]]; then
echo 'Invalid choice, try again' >&2
else
break
fi
done
if [[ "$OSTYPE" == "darwin"* ]]; then
echo "********* running on OSX *********"
echo "********* available drives *********"
diskutil list external physical
echo "************************************"
drives=($(diskutil list external physical | sed -n '/\/dev\//p' | awk '{print $1}'))
PS3='Select destination drive, or 0 to exit: '
select drive in "${drives[@]}"; do
if [[ $REPLY == "0" ]]; then
echo 'Bye!' >&2
exit
# test for zero length of string
elif [[ -z $drive ]]; then
echo 'Invalid choice, try again' >&2
else
break
fi
done
echo "************************************"
rdrive=($(echo $drive | sed 's/\/dev\/disk/\/dev\/rdisk/'))
echo -e " burning file: $file\n to drive: $rdrive ($drive)"
echo "$rdrive ($drive) WILL BE DELETED !!!"
read -r -p "Are you sure? [y/N] " response
if [[ "$response" =~ ^([yY][eE][sS]|[yY])$ ]]; then
# burn image
echo you will be asked for sudo password...
diskutil unmountDisk $drive
# dd status=progress is unfortunately not supported
sudo dd bs=32m if=$file of=$rdrive
diskutil list $drive
diskutil unmountDisk $drive
else
echo 'Bye!' >&2
exit
fi
else
echo "********* running on non OSX -> not yet implemented *********"
fi