forked from ev3dev/ev3dev
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_rootfs
executable file
·270 lines (194 loc) · 9.08 KB
/
build_rootfs
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
#! /bin/dash
# ------------------------------------------------------------------------------
# build-rootfs.sh - download and configure a minimal rootfs for ev3dev
#
# Must be run as root (use sudo of course!)
# ------------------------------------------------------------------------------
error_out () {
echo "$1"
exit 1
}
if [ "$(whoami)" != "root" ]; then
error_out "Sorry, you are not root."
fi
export DEBIAN_FRONTEND=noninteractive
export DEBCONF_NONINTERACTIVE_SEEN=true
export LC_ALL=C LANGUAGE=C LANG=C
TARGET_ROOTFS_DIR="ev3-rootfs"
# ------------------------------------------------------------------------------
# Make sure were running at the same level as a directory called ev3dev so
# that our directory structure is maintained!
if [ ! -d ../ev3dev ]; then
error_out "Not running at same directory level as ev3dev"
fi
if [ ! -d ../ev3dev-rootfs ]; then
error_out "You need to create or clone ../ev3dev-rootfs first"
fi
# ------------------------------------------------------------------------------
# Download the bare ev3-rootfs directory if we don't already have it
cd ../ev3dev-rootfs
if [ ! -d ${TARGET_ROOTFS_DIR} ]; then
echo "-------------------------------------------------------------------------------"
echo " Downloading a complete grip rootfs from emDebian - this might take a while"
echo " so you might want to tail the multistrap.log file from another shell to keep"
echo " track of progress ... "
echo ""
echo -n " Type \"Yes\" to continue, anything else to skip ... "
read YesNo
if [ "${YesNo}" = "Yes" ]; then
# multistrap -f multistrap.conf > multistrap.log 2>&1
multistrap -f ../ev3dev/multistrap.conf
echo "Done"
echo "-------------------------------------------------------------------------------"
fi
else
echo " Checking for existing ev3-rootfs - already exists!"
fi
cd ${OLDPWD}
# ------------------------------------------------------------------------------
# Configuring the rootfs
cd ../ev3dev-rootfs
echo "-------------------------------------------------------------------------------"
echo " This step will configure the rootfs - it will take a while and overwrite"
echo " any customizations you have done!"
echo ""
echo -n " Type \"Yes\" to continue, anything else to skip ... "
read YesNo
if [ "${YesNo}" = "Yes" ]; then
if [ ! -e ${TARGET_ROOTFS_DIR}/usr/bin/qemu-arm-static ]; then
echo -n " Copying qemu-arm-static to ev3-rootfs/usr/bin ... "
cp /usr/bin/qemu-arm-static ${TARGET_ROOTFS_DIR}/usr/bin
echo " Done"
fi
echo -n " Running the dash.preinst file in ev3-rootfs ... "
chroot ${TARGET_ROOTFS_DIR} var/lib/dpkg/info/dash.preinst install > /dev/null
echo "Done"
echo " Configuring packages in ev3-rootfs - this will take a while!"
chroot ${TARGET_ROOTFS_DIR} dpkg --configure -a
# mount proc -t proc /proc
# dpkg --configure -a
fi
cd ${OLDPWD}
# ------------------------------------------------------------------------------
# Set root password and add users
cd ../ev3dev-rootfs
echo "-------------------------------------------------------------------------------"
echo " This step will set the root password and add the default ev3dev user to the"
echo " sudoer group"
echo ""
echo -n " Type \"Yes\" to continue, anything else to skip ... "
read YesNo
if [ "${YesNo}" = "Yes" ]; then
echo -n " Setting the root password ... "
chroot ev3-rootfs passwd
echo -n " Adding the ev3dev user ... "
chroot ${TARGET_ROOTFS_DIR} useradd -m -G sudo,plugdev ev3dev
chroot ${TARGET_ROOTFS_DIR} usermod -s /bin/bash ev3dev
# Additional groups we'll add later...
# ,netdev,audio,video,ssh
echo -n " Setting the ev3dev password ... "
chroot ev3-rootfs passwd ev3dev
fi
cd ${OLDPWD}
# ------------------------------------------------------------------------------
# Clean out the apt-cache -no sense keeping it around if we've already
# installed the files!
cd ../ev3dev-rootfs
echo "-------------------------------------------------------------------------------"
echo " Purging unneeded files from the apt-cache..."
chroot ev3-rootfs apt-get purge
chroot ev3-rootfs apt-get clean
chroot ev3-rootfs rm -r /var/lib/apt/lists
chroot ev3-rootfs mkdir -p /var/lib/apt/lists/partial
echo " done"
cd ${OLDPWD}
# ------------------------------------------------------------------------------
# Customizing the rootfs
cd ../ev3dev-rootfs
#Directories used to mount microSD partitions
for media_dir in "mmc_p1" "data"
do
if [ ! -d ${TARGET_ROOTFS_DIR}/media/${media_dir} ]; then
echo -n " Creating mount directories ... "
mkdir ${TARGET_ROOTFS_DIR}/media/${media_dir}
echo " done"
fi
done
#Set the target board hostname
filename="${TARGET_ROOTFS_DIR}/etc/hostname"
if [ ! -d "${filename}" ]; then
echo -n " Creating "${filename}" ... "
echo "ev3dev" > "${filename}"
echo "done"
fi
#Set the default name server - use Google's DNS for now...
filename="${TARGET_ROOTFS_DIR}/etc/resolv.conf"
if [ ! -d "${filename}" ]; then
echo -n " Creating "${filename}" ... "
echo "nameserver 8.8.8.8" > "${filename}"
echo "nameserver 8.8.8.4" >> "${filename}"
echo "done"
fi
#Set the default network interfaces including wireless
filename="${TARGET_ROOTFS_DIR}/etc/network/interfaces"
if [ ! -d "${filename}" ]; then
echo -n " Creating "${filename}" ... "
echo "auto lo" > $filename
echo "iface lo inet loopback" >> $filename
echo "" >> $filename
echo "allow-hotplug eth0" >> $filename
echo "iface eth0 inet dhcp" >> $filename
echo "hwaddress ether 00:04:25:12:34:56" >> $filename
echo "" >> $filename
echo "auto wlan0" >> $filename
echo "iface wlan0 inet dhcp" >> $filename
echo "done"
fi
#Set a terminal to the debug port
filename="${TARGET_ROOTFS_DIR}/etc/inittab"
echo -n " Updating "${filename}" ... "
sed -n -i -e "/^T0:2345:respawn:\/sbin\/getty -L ttyS1 115200 vt100/ d" \
-e "p" \
"${filename}"
echo "T0:2345:respawn:/sbin/getty -L ttyS1 115200 vt100" >> "${filename}"
echo "done"
#Set how to mount the microSD partitions
filename="${TARGET_ROOTFS_DIR}/etc/fstab"
echo -n " Updating "${filename}" ... "
echo "/dev/mmcblk0p1 /media/mmc_p1 vfat noatime 0 0" > ${filename}
echo "/dev/mmcblk0p2 / ext3 noatime 0 0" >> ${filename}
echo "proc /proc proc defaults 0 0" >> ${filename}
echo "done"
#Set up wpa_supplicant.conf - add your own keys here!!!
filename="${TARGET_ROOTFS_DIR}/etc/wpa_supplicant.conf"
echo -n " Updating "${filename}" ... "
echo "ctrl_interface=/var/run/wpa_supplicant" > ${filename}
echo "#ap_scan=2" >> ${filename}
echo "" >> ${filename}
echo "network={" >> ${filename}
echo " ssid=\"Your SSID Here\"" >> ${filename}
echo " scan_ssid=1" >> ${filename}
echo " proto=WPA RSN" >> ${filename}
echo " key_mgmt=WPA-PSK" >> ${filename}
echo " pairwise=CCMP TKIP" >> ${filename}
echo " group=CCMP TKIP" >> ${filename}
echo " psk=\"Your text key here\"" >> ${filename}
echo "}" >> ${filename}
echo "done"
cd ${OLDPWD}
# ------------------------------------------------------------------------------
# Create the custom issue
cd ../ev3dev-rootfs
filename="${TARGET_ROOTFS_DIR}/etc/issue"
echo -n " Creating "${filename}" ... "
echo " _____ _" > "${filename}"
echo " _____ _|___ / __| | _____ __" >> "${filename}"
echo " / _ \\\\\\ \\\\\\ / / |_ \\\\\\ / _\` |/ _ \\\\\\ \\\\\\ / /" >> "${filename}"
echo " | __/\\\\\\ V / ___) | (_| | __/\\\\\\ V / " >> "${filename}"
echo " \\\\\\___| \\\\\\_/ |____/ \\\\\\__,_|\\\\\\___| \\\\\\_/ " >> "${filename}"
echo "" >> "${filename}"
echo "Debian GNU/Linux 7 on LEGO MINDSTORMS EV3! \\\\n \\\\l" >> "${filename}"
echo "done"
exit
echo "-------------------------------------------------------------------------------"
exit