-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSDHC.sh
executable file
·57 lines (53 loc) · 1.19 KB
/
SDHC.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
card_mount="" # Location of SDHC (e.g /dev/sdb)
img_dir="" # Location of saved SDHC images
if [ -z $card_mount ]; then
echo "card_mount path not specified. Exiting..."
exit 1
fi
if [ -z $img_dir ]; then
echo "img_dir path not specified. Exiting..."
exit 1;
fi
if [ $EUID -ne 0 ]; then # Run as root if not already
exec sudo -- "$0" "$@"
fi
case "$1" in
[bB]ackup )
echo "Creating SDHC image..."
name=$(date | sed 's/ /-/g')
dd if="$card_mount" of="$img_dir/$name.img"
if [ $? -ne 0 ]; then
echo "Failed to create image"
exit 1
fi
echo "Image saved as $name.img"
;;
[fF]lash )
if [ "$2" != "-f" ]; then # Check for flags
read -p "[WARNING!] This will destroy all data on SDHC. Proceed? (y/n): " opt
if [ $opt != "y" ]; then
exit 1
fi
fi
if [ "$2" == "-f" ]; then
echo "Flashing $3 to SDHC..."
dd if="$img_dir/$3" of="$card_mount"
if [ $? -ne 0 ]; then
echo "Failed to flash card"
exit 1
fi
else
echo "Flashing $2 to SDHC..."
dd if="$img_dir/$2" of="$card_mount"
if [ $? -ne 0 ]; then
echo "Failed to flash card"
exit 1
fi
fi
echo "Flash complete"
;;
* )
echo $"Usage: $0 {backup|flash}"
exit 1
esac