forked from ev3dev/ev3dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
write_sdcard_img
executable file
·72 lines (51 loc) · 1.91 KB
/
write_sdcard_img
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
#! /bin/dash
# ------------------------------------------------------------------------------
# write_sdcard_img - uncompresses the img.gz file to a .img file and then
# writes the raw SD Card data
#
# Requires a udev rule that creates a device symlink at /dev/ev3dev
# ------------------------------------------------------------------------------
error_out () {
echo "$1"
exit 1
}
if [ "$(whoami)" != "root" ]; then
error_out "Sorry, you are not root."
fi
if [ ! -e /dev/ev3dev ]; then
error_out "Error - /dev/ev3dev does not exist - have you set up the udev rules to create it?\n"
fi
# ------------------------------------------------------------------------------
device=$(readlink /dev/ev3dev)
umount "/dev/${device}1"
umount "/dev/${device}2"
umount "/dev/${device}"
sleep 1
echo "-------------------------------------------------------------------------------"
echo "WARNING - If you type \"Yes\" to the prompt, this script"
echo " will OVERWRITE the existing ev3dev.img file on the hard drive and"
echo " will OVERWRITE any data on the /dev/ev3dev SD Card"
echo "-------------------------------------------------------------------------------"
echo
echo -n " Type \"Yes\" to continue ... "
read YesNo
if [ ! "${YesNo}" = "Yes" ]; then
error_out "\n .. aborting, you typed \"${YesNo}\""
fi
# ------------------------------------------------------------------------------
# Unzip the raw SD Card image
cd ../ev3dev-rootfs
echo -n " gunzipping the raw SD Card image - should take about 2 minutes..."
gunzip -k ev3dev.img.gz
echo " done."
echo " Writing the raw SD Card image - should take about 5 minutes..."
dd bs=4M if=ev3dev.img of=/dev/ev3dev
if [ $? -gt 0 ]; then
error_out " SD Card image write failed"
else
echo " done."
fi
echo " done."
cd ${OLDPWD}
echo "-------------------------------------------------------------------------------"
exit