-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathsdcard_burn_tool.sh
executable file
·91 lines (71 loc) · 1.42 KB
/
sdcard_burn_tool.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
89
90
91
#!/bin/bash
set -e -o pipefail
FLASH_TOOL="flash-tool.sh"
IMAGE=
DEVICE=
BOARD=
IMAGE_INSTALL_TYPE=
RED='\033[0;31m'
RESET='\033[m'
error_msg() {
echo -e "$RED"ERROR:"$RESET" $1
}
usage() {
echo -e "Usage:"
echo -e "sdcard: $0 -d </dev/sdX> -i <path-to-image>"
}
flash_sdcard() {
pv -tpreb ${IMAGE} | sudo dd of=${DEVICE} conv=notrunc
echo "Sync..."
sync
}
## Calculate time
## $1 - time in seconds
time_cal() {
local minutes
minutes=$(($1 / 60))
echo "Time elapsed: $minutes minute(s)."
}
while getopts "d:i:b:Dh" flag; do
case $flag in
d)
DEVICE="$OPTARG"
;;
i)
IMAGE="$OPTARG"
;;
D)
DEBUG="--debug"
;;
h)
usage
exit
;;
esac
done
if [ ! -f "$IMAGE" ]; then
error_msg "Image '$IMAGE' doesn't exist!"
usage
exit -1
fi
partition=$(fdisk -l "$IMAGE" | grep "Disklabel type" | awk -F ": " '{print $2}' || true)
if [ "$partition" == "dos" ]; then
IMAGE_INSTALL_TYPE="SD-USB"
fi
start_time=`date +%s`
if [ $DEVICE ]; then
if [ ! -b $DEVICE ]; then
error_msg "'$DEVICE' is not a block device! Please make sure the device you choose is right."
exit -1
fi
if [ "$IMAGE_INSTALL_TYPE" != "SD-USB" ]; then
error_msg "Try to burn to SD/USB storage,but the image installation type is '$IMAGE_INSTALL_TYPE', please use 'SD-USB' image!"
exit -1
fi
echo "Burning image '$IMAGE' to SD/USB storage..."
flash_sdcard
fi
end_time=`date +%s`
time_cal $(($end_time - $start_time))
echo "Done!"
date