-
Notifications
You must be signed in to change notification settings - Fork 2
/
createImage.sh
executable file
·88 lines (74 loc) · 1.63 KB
/
createImage.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
#!/bin/bash
: '
Maintainer: Lander Usategui San Juan, e-mail: [email protected]
'
DEVICE=""
IMAGE_PATH="/Users/lander/ImagesFlash" #Change for your path
cont=1
indexArrayDevices=0
deviceArray=( )
currentUser=$(whoami)
#####################
#### FUNCTIONS ###
#####################
function checkUser()
{
# Clear screen
clear
if [ "$currentUser" == "root" ]; then
listDevices
else
# Bad user
echo "\"sudo\" is needed..."
exit 1
fi
}
function listDevices()
{
for i in $(df -h | cut -d " " -f 1 | grep "^/dev/"); do
echo "$cont- $i"
deviceArray[indexArrayDevices]=$i
indexArrayDevices=$((indexArrayDevices+1))
cont=$((cont+1))
done
printf "Choose the device: "
read -r device
if [ "$device" -gt ${#deviceArray[@]} ] || [ "$device" -lt 0 ]; then
#Bad device number
echo "Invalid number, launch the script again and choose a number of the list."
exit 1
else
device=$((device-1))
DEVICE="${deviceArray[$device]}"
createImage
fi
}
function createImage()
{
checkSD
if [ "$(diskutil unmountDisk $DEVICE 2>/dev/null)" ]; then
echo "Unmounted correctly."
printf "Name of the new image? "
read -r name
dd if=$DEVICE bs=8m | gzip -c > $IMAGE_PATH/$name.img.gz
echo "Done, your image is storaged at $IMAGE_PATH"
else
echo "Unable to unmount the SD Card"
exit 1
fi
}
function checkSD()
{
READ_ONLY=$(diskutil info "$DEVICE" | grep "Read-Only Media"| awk '{print $3}')
if [ "$READ_ONLY" == "Yes" ]; then
clear
echo "Unable to flash your SD card, the SD is protected..."
exit 1
fi
}
function main()
{
checkUser
}
#Start script
main