-
Notifications
You must be signed in to change notification settings - Fork 45
/
build.sh
executable file
·545 lines (467 loc) · 20.1 KB
/
build.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
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
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
#!/usr/bin/env bash
set -e # exit if any command fails
umask 022
build_dir=./build_dir
packages_dir=./packages
resources_dir=./res
scripts_dir=./scripts
libs_to_copy=()
# update version and date
version_tag="$(git describe --exact-match --tags HEAD 2> /dev/null || true)"
version_commit="$(git rev-parse --short "@{0}" 2> /dev/null || true)"
if [ -n "${version_tag}" ]; then
version_info="${version_tag} (${version_commit})"
zipfile="raspberrypi-ua-netinst-${version_tag}.zip"
elif [ -n "${version_commit}" ]; then
version_info="${version_commit}"
zipfile="raspberrypi-ua-netinst-git-${version_commit}.zip"
else
version_info="unknown"
zipfile="raspberrypi-ua-netinst-$(date +%Y%m%d).zip"
fi
INSTALL_MODULES+=("kernel/fs/btrfs/btrfs.ko")
INSTALL_MODULES+=("kernel/drivers/scsi/sg.ko")
# defines array with kernel versions
function get_kernels {
local moduleconf
mapfile -t moduleconf < <(find tmp/lib/modules/ -type f -name "modules.builtin")
kernels=()
for i in "${moduleconf[@]}"; do
kernels+=("$(dirname "${i/tmp\/lib\/modules\//}")")
done
}
# copies files replacing "kernel*" with kernel versions in path
function cp_kernelfiles {
for kernel in "${kernels[@]}"; do
eval cp --preserve=xattr,timestamps -r "${1//kernel\*/${kernel}}" "${2//kernel\*/${kernel}}" || true
done
}
# checks if first parameter is contained in the array passed as the second parameter
# use: contains_element "search_for" "${some_array[@]}" || do_if_not_found
function contains_element {
local elem
for elem in "${@:2}"; do [[ "${elem}" == "${1}" ]] && return 0; done
return 1
}
# expects an array with kernel modules as a parameter, checks each module for dependencies
# and if a dependency isn't already in the $modules array, adds it to it (through a temporary
# local array).
# in addition sets the global $new_count variable to the number of dependencies added, so
# that the newly added dependencies can be checked as well
# use: check_dependencies "${modules[@]:${index}}"
function check_dependencies {
# collect the parameters into an array
mods=("${@}")
# temp array to hold the newly found dependencies
local -a new_found
# temp array to hold the found dependencies for a single module
local -a deps
local mod
local dep
# iterate over the passed modules
for mod in "${mods[@]}"; do
# find the module's dependencies, convert into array
IFS=" " read -r -a deps <<< "$(grep "^${mod}" "${depmod_file}" | cut -d':' -f2)"
# iterate over the found dependencies
for dep in "${deps[@]}"; do
# check if the dependency is in $modules, if not, add to temp array
contains_element "${dep}" "${modules[@]}" || new_found+=("${dep}")
done
done
# add the newly found dependencies to the end of the $modules array
modules+=("${new_found[@]}")
# set the global variable to the number of newly found dependencies
new_count=${#new_found[@]}
}
# creates the file passed as an argument and sets permissions
function touch_tempfile {
[[ -z "${1}" ]] && return 1
touch "${1}" && chmod 600 "${1}"
echo "${1}"
}
# creates a temporary file and returns (echos) its filename
# the function checks for different commands and uses the appropriate one
# it will fallback to creating a file in /tmp
function create_tempfile {
local tmp_ptrn
tmp_ptrn="/tmp/$(basename "${0}").${$}"
if type mktemp &> /dev/null; then
mktemp 2> /dev/null || \
mktemp -t raspberrypi-ua-netinst 2> /dev/null || \
touch_tempfile "${tmp_ptrn}"
else
if type tempfile &> /dev/null; then
# shellcheck disable=SC2186
tempfile
else
touch_tempfile "${tmp_ptrn}"
fi
fi
}
# copy an executable file and add all needed libraries to libs_to_copy array
function cp_executable {
echo "Copying executable $1"
cp --preserve=xattr,timestamps "$1" "$2"
LIB_PATH=("tmp/lib" "tmp/usr/lib")
libs_todo=("$1")
while true; do
needed_libs=($(readelf -d "${libs_todo[0]}" 2>/dev/null | grep \(NEEDED\) | sed -e 's/.*\[//' -e 's/\]//'))
for lib in "${needed_libs[@]}"; do
if printf '%s\n' "${libs_to_copy[@]}" | grep -q "/$lib$"; then
continue
fi
echo -n " Adding dependency $lib => "
lib_found=$(find -L "${LIB_PATH[@]}" -name "$lib" 2>/dev/null | head -n 1)
if [ -n "$lib_found" ]; then
echo "$lib_found"
libs_to_copy+=("$lib_found")
libs_todo+=("$lib_found")
else
echo " not found!"
exit 1
fi
done
libs_todo=("${libs_todo[@]:1}")
if [ ${#libs_todo[@]} -eq 0 ]; then
break
fi
done
}
function create_cpio {
# initialize rootfs
rm -rf rootfs
mkdir -p rootfs
# create all the directories needed to copy the various components into place
mkdir -p rootfs/bin/
mkdir -p rootfs/lib/arm-linux-gnueabihf/
mkdir -p rootfs/lib/lsb/init-functions.d/
mkdir -p rootfs/etc/{alternatives,cron.daily,default,init,init.d,ld.so.conf.d,logrotate.d,network/if-up.d/}
mkdir -p rootfs/etc/dpkg/dpkg.cfg.d/
mkdir -p rootfs/etc/network/{if-down.d,if-post-down.d,if-pre-up.d,if-up.d,interfaces.d}
mkdir -p rootfs/lib/ifupdown/
mkdir -p rootfs/lib/lsb/init-functions.d/
mkdir -p rootfs/lib/modules/
mkdir -p rootfs/sbin/
mkdir -p rootfs/usr/bin/
mkdir -p rootfs/usr/lib/arm-linux-gnueabihf/
mkdir -p rootfs/usr/sbin/
mkdir -p rootfs/usr/share/{dpkg,keyrings,libc-bin}
mkdir -p rootfs/var/lib/dpkg/{alternatives,info,parts,updates}
mkdir -p rootfs/var/lib/ntpdate
mkdir -p rootfs/var/log/
mkdir -p rootfs/var/run/
mapfile -t moduleconf < <(find tmp/lib/modules/ -type f -name "modules.order" -o -name "modules.builtin")
for i in "${moduleconf[@]}"; do
i="${i/tmp\/}"
# Copy modules file
mkdir -p "rootfs/$(dirname "${i}")"
cp --preserve=xattr,timestamps "tmp/${i}" "rootfs/${i}"
done
# calculate module dependencies
depmod_file=$(create_tempfile)
for kernel in "${kernels[@]}"; do
/sbin/depmod -nb tmp "${kernel}" > "${depmod_file}"
done
modules=("${INSTALL_MODULES[@]}")
# new_count contains the number of new elements in the $modules array for each iteration
new_count=${#modules[@]}
# repeat the hunt for dependencies until no new ones are found (the loop takes care
# of finding nested dependencies)
until [ "${new_count}" == 0 ]; do
# check the dependencies for the modules in the last $new_count elements
check_dependencies "${modules[@]:$((${#modules[@]}-new_count))}"
done
# do some cleanup
rm -f "${depmod_file}"
# copy the needed kernel modules to the rootfs (create directories as needed)
for module in "${modules[@]}"; do
# calculate the target dir, just so the following line of code is shorter :)
for kernel in "${kernels[@]}"; do
if [ -e "tmp/lib/modules/${kernel}/${module}" ]; then
dstdir="rootfs/lib/modules/${kernel}/$(dirname "${module}")"
# check if destination dir exist, create it otherwise
[ -d "${dstdir}" ] || mkdir -p "${dstdir}"
cp --preserve=xattr,timestamps -a "tmp/lib/modules/${kernel}/${module}" "${dstdir}"
fi
done
done
# copy network drivers
for kernel in "${kernels[@]}"; do
mkdir -p "rootfs/lib/modules/${kernel}/kernel/drivers/net"
mkdir -p "rootfs/lib/modules/${kernel}/kernel/net"
done
cp_kernelfiles tmp/lib/modules/kernel*/kernel/net/ipv6 rootfs/lib/modules/kernel*/kernel/net/
cp_kernelfiles tmp/lib/modules/kernel*/kernel/net/mac80211 rootfs/lib/modules/kernel*/kernel/net/
cp_kernelfiles tmp/lib/modules/kernel*/kernel/net/rfkill rootfs/lib/modules/kernel*/kernel/net/
cp_kernelfiles tmp/lib/modules/kernel*/kernel/net/wireless rootfs/lib/modules/kernel*/kernel/net/
cp_kernelfiles tmp/lib/modules/kernel*/kernel/drivers/net/ethernet rootfs/lib/modules/kernel*/kernel/net/
cp_kernelfiles tmp/lib/modules/kernel*/kernel/drivers/net/phy rootfs/lib/modules/kernel*/kernel/net/
cp_kernelfiles tmp/lib/modules/kernel*/kernel/drivers/net/usb rootfs/lib/modules/kernel*/kernel/drivers/net/
cp_kernelfiles tmp/lib/modules/kernel*/kernel/drivers/net/wireless rootfs/lib/modules/kernel*/kernel/drivers/net/
# copy i2c drivers
for kernel in "${kernels[@]}"; do
mkdir -p "rootfs/lib/modules/${kernel}/kernel/drivers/i2c/busses"
done
cp_kernelfiles tmp/lib/modules/kernel*/kernel/drivers/i2c/busses/i2c-bcm2708.ko* rootfs/lib/modules/kernel*/kernel/drivers/i2c/busses/
cp_kernelfiles tmp/lib/modules/kernel*/kernel/drivers/i2c/busses/i2c-bcm2835.ko* rootfs/lib/modules/kernel*/kernel/drivers/i2c/busses/
# copy rtc drivers
for kernel in "${kernels[@]}"; do
mkdir -p "rootfs/lib/modules/${kernel}/kernel/drivers"
mkdir -p "rootfs/lib/modules/${kernel}/kernel/drivers/hwmon"
done
cp_kernelfiles tmp/lib/modules/kernel*/kernel/drivers/rtc rootfs/lib/modules/kernel*/kernel/drivers/
cp_kernelfiles tmp/lib/modules/kernel*/kernel/drivers/hwmon/raspberrypi-hwmon.ko* rootfs/lib/modules/kernel*/kernel/drivers/hwmon/
# create dependency lists
for kernel in "${kernels[@]}"; do
/sbin/depmod -b rootfs "${kernel}"
done
# install scripts
cp --preserve=xattr,timestamps -r ../"${scripts_dir}"/* rootfs/
(cd ../"${scripts_dir}"/ && find . -type d -exec echo rootfs/{} \;) | xargs chmod +rx
(cd ../"${scripts_dir}"/ && find . -type f -exec echo rootfs/{} \;) | xargs chmod +rx
sed -i "s/__VERSION__/${version_info}/" rootfs/opt/raspberrypi-ua-netinst/install.sh
sed -i "s/__DATE__/$(date)/" rootfs/opt/raspberrypi-ua-netinst/install.sh
# btrfs-progs components
cp_executable tmp/sbin/mkfs.btrfs rootfs/sbin/
# busybox components
cp_executable tmp/bin/busybox rootfs/bin
cd rootfs && ln -s bin/busybox init; cd ..
echo "\$MODALIAS=.* 0:0 660 @/opt/busybox/bin/modprobe \"\$MODALIAS\"" > rootfs/etc/mdev.conf
# bash-static components
cp --preserve=xattr,timestamps tmp/bin/bash-static rootfs/bin
cd rootfs/bin && ln -s bash-static bash; cd ../..
# cdebootstrap-static components
cp --preserve=xattr,timestamps -r tmp/usr/share/cdebootstrap-static rootfs/usr/share/
cp --preserve=xattr,timestamps tmp/usr/bin/cdebootstrap-static rootfs/usr/bin/
# coreutils components
cp_executable tmp/bin/cat rootfs/bin/
cp_executable tmp/bin/chgrp rootfs/bin/
cp_executable tmp/bin/chmod rootfs/bin/
cp_executable tmp/bin/chown rootfs/bin/
cp_executable tmp/bin/cp rootfs/bin/
cp_executable tmp/bin/date rootfs/bin/
cp_executable tmp/bin/dd rootfs/bin/
cp_executable tmp/bin/df rootfs/bin/
cp_executable tmp/bin/dir rootfs/bin/
cp_executable tmp/bin/echo rootfs/bin/
cp_executable tmp/bin/false rootfs/bin/
cp_executable tmp/bin/ln rootfs/bin/
cp_executable tmp/bin/ls rootfs/bin/
cp_executable tmp/bin/mkdir rootfs/bin/
cp_executable tmp/bin/mknod rootfs/bin/
cp_executable tmp/bin/mktemp rootfs/bin/
cp_executable tmp/bin/mv rootfs/bin/
cp_executable tmp/bin/pwd rootfs/bin/
cp_executable tmp/bin/readlink rootfs/bin/
cp_executable tmp/bin/rm rootfs/bin/
cp_executable tmp/bin/rmdir rootfs/bin/
cp_executable tmp/bin/sleep rootfs/bin/
cp_executable tmp/bin/stty rootfs/bin/
cp_executable tmp/bin/sync rootfs/bin/
cp_executable tmp/bin/touch rootfs/bin/
cp_executable tmp/bin/true rootfs/bin/
cp_executable tmp/bin/uname rootfs/bin/
cp_executable tmp/bin/vdir rootfs/bin/
# diffutils components
cp_executable tmp/usr/bin/cmp rootfs/usr/bin/
# dosfstools components
cp_executable tmp/sbin/mkfs.fat rootfs/sbin/
cd rootfs/sbin
ln -s mkfs.fat mkfs.vfat
cd ../..
# dpkg components
cp --preserve=xattr,timestamps tmp/etc/alternatives/README rootfs/etc/alternatives/
cp --preserve=xattr,timestamps tmp/etc/cron.daily/dpkg rootfs/etc/cron.daily/
cp --preserve=xattr,timestamps tmp/etc/dpkg/dpkg.cfg rootfs/etc/dpkg/
cp --preserve=xattr,timestamps tmp/etc/logrotate.d/dpkg rootfs/etc/logrotate.d/
cp_executable tmp/sbin/start-stop-daemon rootfs/sbin/
cp_executable tmp/usr/bin/dpkg rootfs/usr/bin/
cp_executable tmp/usr/bin/dpkg-deb rootfs/usr/bin/
cp_executable tmp/usr/bin/dpkg-divert rootfs/usr/bin/
cp_executable tmp/usr/bin/dpkg-maintscript-helper rootfs/usr/bin/
cp_executable tmp/usr/bin/dpkg-query rootfs/usr/bin/
cp_executable tmp/usr/bin/dpkg-split rootfs/usr/bin/
cp_executable tmp/usr/bin/dpkg-statoverride rootfs/usr/bin/
cp_executable tmp/usr/bin/dpkg-trigger rootfs/usr/bin/
cp_executable tmp/usr/bin/update-alternatives rootfs/usr/bin/
cp --preserve=xattr,timestamps tmp/usr/share/dpkg/abitable rootfs/usr/share/dpkg/
cp --preserve=xattr,timestamps tmp/usr/share/dpkg/cputable rootfs/usr/share/dpkg/
cp --preserve=xattr,timestamps tmp/usr/share/dpkg/ostable rootfs/usr/share/dpkg/
cp --preserve=xattr,timestamps tmp/usr/share/dpkg/tupletable rootfs/usr/share/dpkg/
cd rootfs/usr/sbin
ln -s ../bin/dpkg-divert dpkg-divert
ln -s ../bin/dpkg-statoverride dpkg-statoverride
ln -s ../bin/update-alternatives update-alternatives
cd ../../..
touch rootfs/var/lib/dpkg/status
# e2fsprogs components
cp --preserve=xattr,timestamps tmp/etc/mke2fs.conf rootfs/etc/
cp_executable tmp/sbin/mke2fs rootfs/sbin/
cd rootfs/sbin
ln -s mke2fs mkfs.ext4
cd ../..
# f2fs-tools components
cp_executable tmp/sbin/mkfs.f2fs rootfs/sbin/
# gpgv components
cp_executable tmp/usr/bin/gpgv rootfs/usr/bin/
# ifupdown components
cp --preserve=xattr,timestamps tmp/etc/default/networking rootfs/etc/default/
cp --preserve=xattr,timestamps tmp/etc/init.d/networking rootfs/etc/init.d/
cp --preserve=xattr,timestamps tmp/lib/ifupdown/settle-dad.sh rootfs/lib/ifupdown/
cp_executable tmp/sbin/ifup rootfs/sbin/
cd rootfs/sbin
ln -s ifup ifdown
ln -s ifup ifquery
cd ../..
# iproute2 components
cp_executable tmp/bin/ip rootfs/bin/
# lsb-base components
cp --preserve=xattr,timestamps tmp/lib/lsb/init-functions rootfs/lib/lsb/
cp --preserve=xattr,timestamps tmp/lib/lsb/init-functions.d/00-verbose rootfs/lib/lsb/init-functions.d/
# netbase components
cp --preserve=xattr,timestamps tmp/etc/protocols rootfs/etc/
cp --preserve=xattr,timestamps tmp/etc/rpc rootfs/etc/
cp --preserve=xattr,timestamps tmp/etc/services rootfs/etc/
# netcat-openbsd
cp_executable tmp/bin/nc.openbsd rootfs/bin/nc
# ntpdate components
cp --preserve=xattr,timestamps tmp/etc/default/ntpdate rootfs/etc/default/
sed -i s/NTPDATE_USE_NTP_CONF=yes/NTPDATE_USE_NTP_CONF=no/ rootfs/etc/default/ntpdate
cp_executable tmp/usr/sbin/ntpdate rootfs/usr/sbin/
cp_executable tmp/usr/sbin/ntpdate-debian rootfs/usr/sbin/
# raspberrypi.org GPG key
cp --preserve=xattr,timestamps ../"${packages_dir}"/raspberrypi.gpg.key rootfs/usr/share/keyrings/
# *-archive-keyring components
cp --preserve=xattr,timestamps tmp/usr/share/keyrings/*.gpg rootfs/usr/share/keyrings/
# rng-tools5 components
cp_executable tmp/usr/sbin/rngd rootfs/usr/sbin/
# tar components
cp_executable tmp/bin/tar rootfs/bin/
# fdisk components
cp_executable tmp/sbin/fdisk rootfs/sbin/
# util-linux components
cp_executable tmp/sbin/blkid rootfs/sbin/
cp_executable tmp/sbin/mkswap rootfs/sbin/
# wpa_supplicant components
cp_executable tmp/sbin/wpa_supplicant rootfs/sbin/wpa_supplicant
cp --preserve=xattr,timestamps -r tmp/etc/wpa_supplicant rootfs/etc/wpa_supplicant
# libc-bin components
cp --preserve=xattr,timestamps tmp/etc/default/nss rootfs/etc/default/
cp --preserve=xattr,timestamps tmp/etc/ld.so.conf.d/* rootfs/etc/ld.so.conf.d/
cp --preserve=xattr,timestamps tmp/etc/bindresvport.blacklist rootfs/etc/
cp --preserve=xattr,timestamps tmp/etc/gai.conf rootfs/etc/
cp --preserve=xattr,timestamps tmp/etc/ld.so.conf rootfs/etc/
cp_executable tmp/sbin/ldconfig rootfs/sbin/
# lib/locale ?
cp --preserve=xattr,timestamps tmp/usr/share/libc-bin/nsswitch.conf rootfs/usr/share/libc-bin/
# libc6 components
cp_executable tmp/lib/*/libnss_dns.so.* rootfs/lib/arm-linux-gnueabihf/
cp_executable tmp/lib/*/libnss_files.so.* rootfs/lib/arm-linux-gnueabihf/
# Binary firmware for version 3 Model B, Zero W wireless
mkdir -p rootfs/lib/firmware/brcm
cp --preserve=xattr,timestamps tmp/lib/firmware/brcm/brcmfmac43430-sdio.bin rootfs/lib/firmware/brcm/
cp --preserve=xattr,timestamps tmp/lib/firmware/brcm/brcmfmac43430-sdio.txt rootfs/lib/firmware/brcm/
cp --preserve=xattr,timestamps tmp/lib/firmware/brcm/brcmfmac43430-sdio.clm_blob rootfs/lib/firmware/brcm/
# Binary firmware for Zero 2 W wireless
cp --preserve=xattr,timestamps tmp/lib/firmware/brcm/brcmfmac43436-sdio.bin rootfs/lib/firmware/brcm/
cp --preserve=xattr,timestamps tmp/lib/firmware/brcm/brcmfmac43436-sdio.clm_blob rootfs/lib/firmware/brcm/
cp --preserve=xattr,timestamps tmp/lib/firmware/brcm/brcmfmac43436-sdio.txt rootfs/lib/firmware/brcm/
cp --preserve=xattr,timestamps tmp/lib/firmware/brcm/brcmfmac43436s-sdio.bin rootfs/lib/firmware/brcm/
cp --preserve=xattr,timestamps tmp/lib/firmware/brcm/brcmfmac43436s-sdio.txt rootfs/lib/firmware/brcm/
# Binary firmware for version 3 Model A+/B+, 4 Model B wireless
ln -s cyfmac43455-sdio-standard.bin tmp/lib/firmware/cypress/cyfmac43455-sdio.bin
cp --preserve=xattr,timestamps tmp/lib/firmware/brcm/brcmfmac43455-sdio.bin rootfs/lib/firmware/brcm/
cp --preserve=xattr,timestamps tmp/lib/firmware/brcm/brcmfmac43455-sdio.clm_blob rootfs/lib/firmware/brcm/
cp --preserve=xattr,timestamps tmp/lib/firmware/brcm/brcmfmac43455-sdio.txt rootfs/lib/firmware/brcm/
# Binary firmware for version 4 Compute Module, 400 wireless
cp --preserve=xattr,timestamps tmp/lib/firmware/brcm/brcmfmac43456-sdio.bin rootfs/lib/firmware/brcm/
cp --preserve=xattr,timestamps tmp/lib/firmware/brcm/brcmfmac43456-sdio.clm_blob rootfs/lib/firmware/brcm/
cp --preserve=xattr,timestamps tmp/lib/firmware/brcm/brcmfmac43456-sdio.txt rootfs/lib/firmware/brcm/
# vcgencmd
## libraspberrypi-bin
mkdir -p rootfs/usr/bin
cp_executable tmp/usr/bin/vcgencmd rootfs/usr/bin/
# xxd
mkdir -p rootfs/usr/bin
cp_executable tmp/usr/bin/xxd rootfs/usr/bin/
# install additional resources
mkdir -p rootfs/opt/raspberrypi-ua-netinst/res
cp --preserve=xattr,timestamps -r ../"${resources_dir}"/initramfs/* rootfs/opt/raspberrypi-ua-netinst/res/
(cd ../"${resources_dir}"/initramfs/ && find . -type d -exec echo rootfs/opt/raspberrypi-ua-netinst/res/{} \;) | xargs chmod +rx
(cd ../"${resources_dir}"/initramfs/ && find . -type f -exec echo rootfs/opt/raspberrypi-ua-netinst/res/{} \;) | xargs chmod +r
# curl
cp_executable tmp/usr/bin/curl rootfs/usr/bin/
# copy all libraries needed by executable files above
for lib in "${libs_to_copy[@]}"; do
cp --preserve=xattr,timestamps "$lib" $(echo "$lib" | sed -e 's/^tmp\//rootfs\//')
done
INITRAMFS="../raspberrypi-ua-netinst.cpio.gz"
(cd rootfs && find . | cpio -H newc -ov | gzip --best > $INITRAMFS)
rm -rf rootfs
}
# Run update if never run
if [ ! -d packages ]; then
# shellcheck disable=SC1091
. ./update.sh
fi
# Prepare
rm -rf ${build_dir} && mkdir -p ${build_dir} && cd ${build_dir}
rm -rf tmp && mkdir tmp
# extract debs
for i in ../packages/*.deb; do
cd tmp && ar x "../${i}" && tar -xf data.tar.*; rm -f data.tar.* control.tar.* debian-binary; cd ..
done
# get kernel versions
get_kernels
# initialize bootfs
rm -rf bootfs
mkdir -p bootfs/raspberrypi-ua-netinst
# raspberrypi-bootloader components and kernel
cp --preserve=xattr,timestamps -r tmp/boot/* bootfs/
mv bootfs/kernel*.img bootfs/raspberrypi-ua-netinst/
mv bootfs/*.dtb bootfs/raspberrypi-ua-netinst/
mv bootfs/overlays bootfs/raspberrypi-ua-netinst/
if [ ! -f bootfs/config.txt ] ; then
touch bootfs/config.txt
fi
create_cpio
mv raspberrypi-ua-netinst.cpio.gz bootfs/raspberrypi-ua-netinst/initramfs.gz
{
echo "[all]"
echo "os_prefix=raspberrypi-ua-netinst/"
echo "initramfs initramfs.gz"
echo "gpu_mem=16"
echo "[pi3]"
echo "dtoverlay=disable-bt"
echo "arm_64bit=1"
echo "[pi4]"
echo "dtoverlay=disable-bt"
echo "arm_64bit=1"
echo "[pi02]"
echo "arm_64bit=1"
echo "[board-type=a02042]"
echo "arm_64bit=1"
echo "[board-type=a22042]"
echo "arm_64bit=1"
} >> bootfs/raspberrypi-ua-netinst/config.txt
cp bootfs/raspberrypi-ua-netinst/config.txt bootfs/config.txt
echo "consoleblank=0 console=serial0,115200 console=tty1 rootwait" > bootfs/raspberrypi-ua-netinst/cmdline.txt
if [ ! -f bootfs/TIMEOUT ] ; then
touch bootfs/TIMEOUT
fi
# prepare config content
mkdir -p bootfs/raspberrypi-ua-netinst/config
mkdir -p bootfs/raspberrypi-ua-netinst/config/apt
mkdir -p bootfs/raspberrypi-ua-netinst/config/boot
mkdir -p bootfs/raspberrypi-ua-netinst/config/files
mkdir -p bootfs/raspberrypi-ua-netinst/config/files/root
if [ -d ../config ]; then
cp --preserve=xattr,timestamps -r ../config/* ./bootfs/raspberrypi-ua-netinst/config/
find ./bootfs/ -type f -name "*.txt" -execdir sed -i -e 's/\([^\r]\)$/\1\r/' {} +
fi
# create zip file
rm -f "${zipfile}"
cd bootfs && zip -r -9 "../${zipfile}" ./*; cd ..
mv "${zipfile}" ../
# clean up
rm -rf tmp