-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall_raspbian.sh
executable file
·131 lines (95 loc) · 2.54 KB
/
install_raspbian.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#!/bin/bash
################################################################
do_check() {
type dd >/dev/null 2>&1 || { echo >&2 "I require dd but it's not installed. Aborting."; exit 1; }
type wget >/dev/null 2>&1 || { echo >&2 "I require wget but it's not installed. Aborting."; exit 1; }
type pv >/dev/null 2>&1 || { echo >&2 "I require pv but it's not installed. Aborting."; exit 1; }
type jar >/dev/null 2>&1 || { echo >&2 "I require jar but it's not installed. Aborting."; exit 1; }
type diskutil >/dev/null 2>&1 || { echo >&2 "I require diskutil but it's not installed. Aborting."; exit 1; }
if (test ! -d "./tmp"); then
mkdir ./tmp
fi
}
################################################################
do_download_image() {
read -n 1 -p "Download latest raspbian? [Y/n] " YESNO
echo
if (test "$YESNO" = "" -o "$YESNO" = "y" -o "$YESNO" = "Y"); then
rm -f tmp/raspbian.zip
wget http://downloads.raspberrypi.org/raspbian_latest -O tmp/raspbian.zip
cd tmp
echo unzipping...
jar xvf raspbian.zip
cd ..
else
if (test ! -f tmp/raspbian.zip); then
echo "tmp/raspbian.zip does not exist";
exit 1;
fi
fi
SOURCE=`ls -t1 tmp/*.img | head -1`
echo "Image found: $SOURCE"
if (test "$SOURCE" = "" -o ! -f "./$SOURCE"); then
echo No image found.
exit 1;
fi
ls -lh $SOURCE
}
################################################################
do_choose_target() {
read -p "Insert empty SD-Card and press enter [ENTER] "
diskutil list
echo
echo
echo
TARGET=`diskutil list | grep FAT_32 | awk 'NF{print $NF; exit}' | sed 's/s1//' | sed 's/s2//'`
TARGET=/dev/$TARGET
read -p "Enter SD-Card device path: [$TARGET] " INPUT
echo
if (test ! "$INPUT" = ""); then
TARGET=$INPUT
fi
if (test "$TARGET" = "/dev/"); then
echo Unknown device.
exit 1
fi
RAWTARGET=`echo $TARGET | sed 's/disk/rdisk/'`
if (test ! -e "$RAWTARGET"); then
echo Invalid device.
exit 1
fi
}
################################################################
do_dump() {
echo "source:"
ls -lh $SOURCE
echo "target: $TARGET $RAWTARGET"
echo
read -p "Ready? [ENTER]"
diskutil unmountDisk $TARGET
echo "dd..."
sudo bash -c "pv -tpreb $SOURCE | dd bs=1m of=$RAWTARGET"
echo "enable ssh..."
touch /Volumes/boot/ssh
echo "eject..."
diskutil eject $TARGET
}
################################################################
do_check
echo
echo
echo
do_download_image
echo
echo
echo
do_choose_target
echo
echo
echo
do_dump
echo
echo
echo
echo "done."
################################################################