This repository has been archived by the owner on Mar 29, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_brunch.sh
executable file
·339 lines (270 loc) · 25.4 KB
/
build_brunch.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
#!/bin/bash
if [ ! -d /home/runner/work ]; then NTHREADS=$(nproc); else NTHREADS=$(($(nproc)*4)); fi
kernels=$(ls -d ./kernels/* | sed 's#./kernels/##g')
for kernel in $kernels; do
if [ ! -f "./kernels/$kernel/out/arch/x86/boot/bzImage" ]; then echo "The kernel $kernel has to be built first"; exit 1; fi
done
if ( ! test -z {,} ); then echo "Must be ran with \"sudo bash\""; exit 1; fi
if [ $(whoami) != "root" ]; then echo "Please run with sudo"; exit 1; fi
if mountpoint -q ./chroot/dev/shm; then umount ./chroot/dev/shm; fi
if mountpoint -q ./chroot/dev; then umount ./chroot/dev; fi
if mountpoint -q ./chroot/sys; then umount ./chroot/sys; fi
if mountpoint -q ./chroot/proc; then umount ./chroot/proc; fi
if mountpoint -q ./chroot/out; then umount ./chroot/out; fi
if [ -d ./chroot ]; then rm -r ./chroot; fi
if [ -d ./out ]; then rm -r ./out; fi
mkdir -p ./chroot/out ./out || { echo "Failed to create output directory"; exit 1; }
chmod 0777 ./out || { echo "Failed to fix output directory permissions"; exit 1; }
if [ ! -z $1 ] && [ "$1" != "skip" ] ; then
if [ ! -f "$1" ]; then echo "ChromeOS recovery image $1 not found"; exit 1; fi
if [ ! $(dd if="$1" bs=1 count=4 status=none | od -A n -t x1 | sed 's/ //g') == '33c0fa8e' ] || [ $(cgpt show -i 12 -b "$1") -eq 0 ] || [ $(cgpt show -i 13 -b "$1") -gt 0 ] || [ ! $(cgpt show -i 3 -l "$1") == 'ROOT-A' ]; then echo "$1 is not a valid ChromeOS recovery image"; fi
recovery_image=$(losetup --show -fP "$1")
[ -b "$recovery_image"p3 ] || { echo "Failed to setup loop device"; exit 1; }
mount -o ro "$recovery_image"p3 ./out || { echo "Failed to mount ChromeOS rootfs"; exit 1; }
cp -a ./out/* ./chroot/ || { echo "Failed to copy ChromeOS rootfs content"; exit 1; }
umount ./out || { echo "Failed to unmount ChromeOS rootfs"; exit 1; }
losetup -d "$recovery_image" || { echo "Failed to detach loop device"; exit 1; }
else
git clone -b master https://github.com/sebanc/chromeos-ota-extract.git rootfs || { echo "Failed to clone chromeos-ota-extract"; exit 1; }
cd rootfs
curl -L https://dl.google.com/chromeos/rammus/15662.64.0/stable-channel/chromeos_15662.64.0_rammus_stable-channel_full_mp-v4.bin-gy2tsnjrgaztataj3lz3kesauxnqrw5y.signed -o ./update.signed || { echo "Failed to Download the OTA update"; exit 1; }
python3 extract_android_ota_payload.py ./update.signed || { echo "Failed to extract the OTA update"; exit 1; }
cd ..
[ -f ./rootfs/root.img ] || { echo "ChromeOS rootfs has not been extracted"; exit 1; }
mount -o ro ./rootfs/root.img ./out || { echo "Failed to mount ChromeOS rootfs image"; exit 1; }
cp -a ./out/* ./chroot/ || { echo "Failed to copy ChromeOS rootfs content"; exit 1; }
umount ./out || { echo "Failed to unmount ChromeOS rootfs image"; exit 1; }
rm -r ./rootfs
fi
mkdir -p ./chroot/home/chronos/image/tmp || { echo "Failed to create image directory"; exit 1; }
cp -r ./efi-partition ./chroot/home/chronos/image/ || { echo "Failed to copy the efi partition directory"; exit 1; }
chown -R 1000:1000 ./chroot/home/chronos/image || { echo "Failed to fix image directory ownership"; exit 1; }
chmod 0777 ./chroot/home/chronos || { echo "Failed to fix chronos directory permissions"; exit 1; }
rm -f ./chroot/etc/resolv.conf
echo 'nameserver 8.8.4.4' > ./chroot/etc/resolv.conf || { echo "Failed to replace chroot resolv.conf file"; exit 1; }
echo 'chronos ALL=(ALL) NOPASSWD: ALL' > ./chroot/etc/sudoers.d/95_cros_base || { echo "Failed to add custom chroot sudoers file"; exit 1; }
mkdir ./chroot/home/chronos/brunch || { echo "Failed to create brunch directory"; exit 1; }
cp ./scripts/chromeos-install.sh ./chroot/home/chronos/brunch/ || { echo "Failed to copy the chromeos-install.sh script"; exit 1; }
chmod 0755 ./chroot/home/chronos/brunch/chromeos-install.sh || { echo "Failed to change chromeos-install.sh permissions"; exit 1; }
chown -R 1000:1000 ./chroot/home/chronos/brunch || { echo "Failed to fix brunch directory ownership"; exit 1; }
mkdir -p ./chroot/home/chronos/initramfs/sbin || { echo "Failed to create initramfs directory"; exit 1; }
cp ./scripts/brunch-init ./chroot/home/chronos/initramfs/init || { echo "Failed to copy brunch init script"; exit 1; }
cp ./scripts/brunch-setup ./chroot/home/chronos/initramfs/sbin/ || { echo "Failed to copy brunch setup script"; exit 1; }
cp -r ./bootsplashes ./chroot/home/chronos/initramfs/ || { echo "Failed to copy bootsplashes"; exit 1; }
chmod 0755 ./chroot/home/chronos/initramfs/init || { echo "Failed to change init script permissions"; exit 1; }
chown -R 1000:1000 ./chroot/home/chronos/initramfs || { echo "Failed to fix initramfs directory ownership"; exit 1; }
mkdir ./chroot/home/chronos/rootc || { echo "Failed to create rootc directory"; exit 1; }
ln -s kernel-chromebook-6.1 ./chroot/home/chronos/rootc/kernel || { echo "Failed to make the default kernel symlink"; exit 1; }
ln -s kernel ./chroot/home/chronos/rootc/kernel-4.19 || { echo "Failed to make the legacy kernel symlink"; exit 1; }
ln -s kernel ./chroot/home/chronos/rootc/kernel-5.4 || { echo "Failed to make the legacy kernel symlink"; exit 1; }
ln -s kernel-chromebook-6.1 ./chroot/home/chronos/rootc/kernel-macbook || { echo "Failed to make the macbook kernel symlink"; exit 1; }
ln -s kernel-chromebook-6.1 ./chroot/home/chronos/rootc/kernel-macbook-t2 || { echo "Failed to make the macbook kernel symlink"; exit 1; }
cp -r ./packages ./chroot/home/chronos/rootc/ || { echo "Failed to copy brunch packages"; exit 1; }
cp -r ./brunch-patches ./chroot/home/chronos/rootc/patches || { echo "Failed to copy brunch patches"; exit 1; }
chmod -R 0755 ./chroot/home/chronos/rootc/patches || { echo "Failed to change patches directory permissions"; exit 1; }
chown -R 1000:1000 ./chroot/home/chronos/rootc || { echo "Failed to fix rootc directory ownership"; exit 1; }
for kernel in $kernels; do
mkdir -p ./chroot/home/chronos/kernel || { echo "Failed to create directory for kernel $kernel"; exit 1; }
cp -r ./kernels/"$kernel" ./chroot/tmp/kernel || { echo "Failed to copy source for kernel $kernel"; exit 1; }
cd ./chroot/tmp/kernel || { echo "Failed to enter source directory for kernel $kernel"; exit 1; }
kernel_version="$(file ./out/arch/x86/boot/bzImage | cut -d' ' -f9)"
[ ! "$kernel_version" == "" ] || { echo "Failed to read version for kernel $kernel"; exit 1; }
cp ./out/arch/x86/boot/bzImage ../../home/chronos/rootc/kernel-"$kernel" || { echo "Failed to copy the kernel $kernel"; exit 1; }
make -j"$NTHREADS" O=out INSTALL_MOD_STRIP=1 INSTALL_MOD_PATH=../../../home/chronos/kernel modules_install || { echo "Failed to install modules for kernel $kernel"; exit 1; }
rm ../../home/chronos/kernel/lib/modules/"$kernel_version"/build || { echo "Failed to remove the build directory for kernel $kernel"; exit 1; }
rm ../../home/chronos/kernel/lib/modules/"$kernel_version"/source || { echo "Failed to remove the source directory for kernel $kernel"; exit 1; }
cp -r ./headers ../../home/chronos/kernel/lib/modules/"$kernel_version"/build || { echo "Failed to replace the build directory for kernel $kernel"; exit 1; }
mkdir -p ../../home/chronos/kernel/usr/src || { echo "Failed to create the linux-headers directory for kernel $kernel"; exit 1; }
ln -s /lib/modules/"$kernel_version"/build ../../home/chronos/kernel/usr/src/linux-headers-"$kernel_version" || { echo "Failed to symlink the linux-headers directory for kernel $kernel"; exit 1; }
cd ../../..
if [ "$1" != "skip" ] && [ "$2" != "skip" ]; then
if [ "$kernel" == "6.1" ]; then
cp -r ./external-drivers/rtbth ./chroot/tmp/ || { echo "Failed to build external rtbth module for kernel $kernel"; exit 1; }
cd ./chroot/tmp/rtbth || { echo "Failed to build external rtbth module for kernel $kernel"; exit 1; }
make -j"$NTHREADS" || { echo "Failed to build external rtbth module for kernel $kernel"; exit 1; }
cp ./rtbth.ko ../../../chroot/home/chronos/kernel/lib/modules/"$kernel_version"/rtbth.ko || { echo "Failed to build external rtbth module for kernel $kernel"; exit 1; }
cd ../../.. || { echo "Failed to build external rtbth module for kernel $kernel"; exit 1; }
rm -r ./chroot/tmp/rtbth || { echo "Failed to build external rtbth module for kernel $kernel"; exit 1; }
fi
if [ "$kernel" == "6.1" ]; then
cp -r ./external-drivers/rtl8188eu ./chroot/tmp/ || { echo "Failed to build external rtl8188eu module for kernel $kernel"; exit 1; }
cd ./chroot/tmp/rtl8188eu || { echo "Failed to build external rtl8188eu module for kernel $kernel"; exit 1; }
make -j"$NTHREADS" modules || { echo "Failed to build external rtl8188eu module for kernel $kernel"; exit 1; }
cp ./8188eu.ko ../../../chroot/home/chronos/kernel/lib/modules/"$kernel_version"/rtl8188eu.ko || { echo "Failed to build external rtl8188eu module for kernel $kernel"; exit 1; }
cd ../../.. || { echo "Failed to build external rtl8188eu module for kernel $kernel"; exit 1; }
rm -r ./chroot/tmp/rtl8188eu || { echo "Failed to build external rtl8188eu module for kernel $kernel"; exit 1; }
fi
if [ "$kernel" == "6.1" ]; then
cp -r ./external-drivers/rtl8192eu ./chroot/tmp/ || { echo "Failed to build external rtl8192eu module for kernel $kernel"; exit 1; }
cd ./chroot/tmp/rtl8192eu || { echo "Failed to build external rtl8192eu module for kernel $kernel"; exit 1; }
make -j"$NTHREADS" modules || { echo "Failed to build external rtl8192eu module for kernel $kernel"; exit 1; }
cp ./8192eu.ko ../../../chroot/home/chronos/kernel/lib/modules/"$kernel_version"/rtl8192eu.ko || { echo "Failed to build external rtl8192eu module for kernel $kernel"; exit 1; }
cd ../../.. || { echo "Failed to build external rtl8192eu module for kernel $kernel"; exit 1; }
rm -r ./chroot/tmp/rtl8192eu || { echo "Failed to build external rtl8192eu module for kernel $kernel"; exit 1; }
fi
if [ "$kernel" == "6.1" ]; then
cp -r ./external-drivers/rtl8723bs ./chroot/tmp/ || { echo "Failed to build external rtl8723bs module for kernel $kernel"; exit 1; }
cd ./chroot/tmp/rtl8723bs || { echo "Failed to build external rtl8723bs module for kernel $kernel"; exit 1; }
make -j"$NTHREADS" modules || { echo "Failed to build external rtl8723bs module for kernel $kernel"; exit 1; }
cp ./8723bs.ko ../../../chroot/home/chronos/kernel/lib/modules/"$kernel_version"/rtl8723bs.ko || { echo "Failed to build external rtl8723bs module for kernel $kernel"; exit 1; }
cd ../../.. || { echo "Failed to build external rtl8723bs module for kernel $kernel"; exit 1; }
rm -r ./chroot/tmp/rtl8723bs || { echo "Failed to build external rtl8723bs module for kernel $kernel"; exit 1; }
fi
if [ "$kernel" == "6.1" ]; then
cp -r ./external-drivers/rtl8723bu ./chroot/tmp/ || { echo "Failed to build external rtl8723bu module for kernel $kernel"; exit 1; }
cd ./chroot/tmp/rtl8723bu || { echo "Failed to build external rtl8723bu module for kernel $kernel"; exit 1; }
make -j"$NTHREADS" modules || { echo "Failed to build external rtl8723bu module for kernel $kernel"; exit 1; }
cp ./8723bu.ko ../../../chroot/home/chronos/kernel/lib/modules/"$kernel_version"/rtl8723bu.ko || { echo "Failed to build external rtl8723bu module for kernel $kernel"; exit 1; }
cd ../../.. || { echo "Failed to build external rtl8723bu module for kernel $kernel"; exit 1; }
rm -r ./chroot/tmp/rtl8723bu || { echo "Failed to build external rtl8723bu module for kernel $kernel"; exit 1; }
fi
if [ "$kernel" == "6.1" ]; then
cp -r ./external-drivers/rtl8723du ./chroot/tmp/ || { echo "Failed to build external rtl8723du module for kernel $kernel"; exit 1; }
cd ./chroot/tmp/rtl8723du || { echo "Failed to build external rtl8723du module for kernel $kernel"; exit 1; }
make -j"$NTHREADS" || { echo "Failed to build external rtl8723du module for kernel $kernel"; exit 1; }
cp ./8723du.ko ../../../chroot/home/chronos/kernel/lib/modules/"$kernel_version"/rtl8723du.ko || { echo "Failed to build external rtl8723du module for kernel $kernel"; exit 1; }
cd ../../.. || { echo "Failed to build external rtl8723du module for kernel $kernel"; exit 1; }
rm -r ./chroot/tmp/rtl8723du || { echo "Failed to build external rtl8723du module for kernel $kernel"; exit 1; }
fi
if [ "$kernel" == "6.1" ]; then
cp -r ./external-drivers/rtl8812au ./chroot/tmp/ || { echo "Failed to build external rtl8812au module for kernel $kernel"; exit 1; }
cd ./chroot/tmp/rtl8812au || { echo "Failed to build external rtl8812au module for kernel $kernel"; exit 1; }
make -j"$NTHREADS" modules || { echo "Failed to build external rtl8812au module for kernel $kernel"; exit 1; }
cp ./8812au.ko ../../../chroot/home/chronos/kernel/lib/modules/"$kernel_version"/rtl8812au.ko || { echo "Failed to build external rtl8812au module for kernel $kernel"; exit 1; }
cd ../../.. || { echo "Failed to build external rtl8812au module for kernel $kernel"; exit 1; }
rm -r ./chroot/tmp/rtl8812au || { echo "Failed to build external rtl8812au module for kernel $kernel"; exit 1; }
fi
if [ "$kernel" == "6.1" ]; then
cp -r ./external-drivers/rtl8814au ./chroot/tmp/ || { echo "Failed to build external rtl8814au module for kernel $kernel"; exit 1; }
cd ./chroot/tmp/rtl8814au || { echo "Failed to build external rtl8814au module for kernel $kernel"; exit 1; }
make -j"$NTHREADS" modules || { echo "Failed to build external rtl8814au module for kernel $kernel"; exit 1; }
cp ./8814au.ko ../../../chroot/home/chronos/kernel/lib/modules/"$kernel_version"/rtl8814au.ko || { echo "Failed to build external rtl8814au module for kernel $kernel"; exit 1; }
cd ../../.. || { echo "Failed to build external rtl8814au module for kernel $kernel"; exit 1; }
rm -r ./chroot/tmp/rtl8814au || { echo "Failed to build external rtl8814au module for kernel $kernel"; exit 1; }
fi
if [ "$kernel" == "6.1" ]; then
cp -r ./external-drivers/rtl8821ce ./chroot/tmp/ || { echo "Failed to build external rtl8821ce module for kernel $kernel"; exit 1; }
cd ./chroot/tmp/rtl8821ce || { echo "Failed to build external rtl8821ce module for kernel $kernel"; exit 1; }
make -j"$NTHREADS" modules || { echo "Failed to build external rtl8821ce module for kernel $kernel"; exit 1; }
cp ./8821ce.ko ../../../chroot/home/chronos/kernel/lib/modules/"$kernel_version"/rtl8821ce.ko || { echo "Failed to build external rtl8821ce module for kernel $kernel"; exit 1; }
cd ../../.. || { echo "Failed to build external rtl8821ce module for kernel $kernel"; exit 1; }
rm -r ./chroot/tmp/rtl8821ce || { echo "Failed to build external rtl8821ce module for kernel $kernel"; exit 1; }
fi
if [ "$kernel" == "6.1" ]; then
cp -r ./external-drivers/rtl8821cu ./chroot/tmp/ || { echo "Failed to build external rtl8821cu module for kernel $kernel"; exit 1; }
cd ./chroot/tmp/rtl8821cu || { echo "Failed to build external rtl8821cu module for kernel $kernel"; exit 1; }
make -j"$NTHREADS" modules || { echo "Failed to build external rtl8821cu module for kernel $kernel"; exit 1; }
cp ./8821cu.ko ../../../chroot/home/chronos/kernel/lib/modules/"$kernel_version"/rtl8821cu.ko || { echo "Failed to build external rtl8821cu module for kernel $kernel"; exit 1; }
cd ../../.. || { echo "Failed to build external rtl8821cu module for kernel $kernel"; exit 1; }
rm -r ./chroot/tmp/rtl8821cu || { echo "Failed to build external rtl8821cu module for kernel $kernel"; exit 1; }
fi
if [ "$kernel" == "6.1" ]; then
cp -r ./external-drivers/rtl88x2bu ./chroot/tmp/ || { echo "Failed to build external rtl88x2bu module for kernel $kernel"; exit 1; }
cd ./chroot/tmp/rtl88x2bu || { echo "Failed to build external rtl88x2bu module for kernel $kernel"; exit 1; }
make -j"$NTHREADS" modules || { echo "Failed to build external rtl88x2bu module for kernel $kernel"; exit 1; }
cp ./88x2bu.ko ../../../chroot/home/chronos/kernel/lib/modules/"$kernel_version"/rtl88x2bu.ko || { echo "Failed to build external rtl88x2bu module for kernel $kernel"; exit 1; }
cd ../../.. || { echo "Failed to build external rtl88x2bu module for kernel $kernel"; exit 1; }
rm -r ./chroot/tmp/rtl88x2bu || { echo "Failed to build external rtl88x2bu module for kernel $kernel"; exit 1; }
fi
if [ "$kernel" == "6.1" ]; then
cp -r ./external-drivers/rtl885xxx ./chroot/tmp/ || { echo "Failed to build external rtl8852ae module for kernel $kernel"; exit 1; }
cd ./chroot/tmp/rtl885xxx || { echo "Failed to build external rtl8852ae module for kernel $kernel"; exit 1; }
make -j"$NTHREADS" || { echo "Failed to build external rtl8852ae module for kernel $kernel"; exit 1; }
mkdir -p ../../../chroot/home/chronos/kernel/lib/modules/"$kernel_version"/rtl885xxx || { echo "Failed to build external rtl8852ae module for kernel $kernel"; exit 1; }
cp ./rtw89core.ko ../../../chroot/home/chronos/kernel/lib/modules/"$kernel_version"/rtl885xxx/rtw89core.ko || { echo "Failed to build external rtl8852ae module for kernel $kernel"; exit 1; }
cp ./rtw89pci.ko ../../../chroot/home/chronos/kernel/lib/modules/"$kernel_version"/rtl885xxx/rtw89pci.ko || { echo "Failed to build external rtl8852ae module for kernel $kernel"; exit 1; }
cp ./rtw_8852a.ko ../../../chroot/home/chronos/kernel/lib/modules/"$kernel_version"/rtl885xxx/rtw_8852a.ko || { echo "Failed to build external rtl8852ae module for kernel $kernel"; exit 1; }
cp ./rtw_8852ae.ko ../../../chroot/home/chronos/kernel/lib/modules/"$kernel_version"/rtl885xxx/rtw_8852ae.ko || { echo "Failed to build external rtl8852ae module for kernel $kernel"; exit 1; }
cp ./rtw_8852b.ko ../../../chroot/home/chronos/kernel/lib/modules/"$kernel_version"/rtl885xxx/rtw_8852b.ko || { echo "Failed to build external rtl8852ae module for kernel $kernel"; exit 1; }
cp ./rtw_8852be.ko ../../../chroot/home/chronos/kernel/lib/modules/"$kernel_version"/rtl885xxx/rtw_8852be.ko || { echo "Failed to build external rtl8852ae module for kernel $kernel"; exit 1; }
cp ./rtw_8852c.ko ../../../chroot/home/chronos/kernel/lib/modules/"$kernel_version"/rtl885xxx/rtw_8852c.ko || { echo "Failed to build external rtl8852ae module for kernel $kernel"; exit 1; }
cp ./rtw_8852ce.ko ../../../chroot/home/chronos/kernel/lib/modules/"$kernel_version"/rtl885xxx/rtw_8852ce.ko || { echo "Failed to build external rtl8852ae module for kernel $kernel"; exit 1; }
cd ../../.. || { echo "Failed to build external rtl8852ae module for kernel $kernel"; exit 1; }
rm -r ./chroot/tmp/rtl885xxx || { echo "Failed to build external rtl8852ae module for kernel $kernel"; exit 1; }
fi
if [ "$kernel" == "6.1" ]; then
cp -r ./external-drivers/broadcom-wl ./chroot/tmp/ || { echo "Failed to build external broadcom-wl module for kernel $kernel"; exit 1; }
cd ./chroot/tmp/broadcom-wl || { echo "Failed to build external broadcom-wl module for kernel $kernel"; exit 1; }
make -j"$NTHREADS" || { echo "Failed to build external broadcom-wl module for kernel $kernel"; exit 1; }
cp ./wl.ko ../../../chroot/home/chronos/kernel/lib/modules/"$kernel_version"/broadcom_wl.ko || { echo "Failed to build external broadcom-wl module for kernel $kernel"; exit 1; }
cd ../../.. || { echo "Failed to build external broadcom-wl module for kernel $kernel"; exit 1; }
rm -r ./chroot/tmp/broadcom-wl || { echo "Failed to build external broadcom-wl module for kernel $kernel"; exit 1; }
fi
if [ "$kernel" == "6.1" ]; then
cp -r ./external-drivers/acpi_call ./chroot/tmp/ || { echo "Failed to build external acpi_call module for kernel $kernel"; exit 1; }
cd ./chroot/tmp/acpi_call || { echo "Failed to build external acpi_call module for kernel $kernel"; exit 1; }
make -j"$NTHREADS" || { echo "Failed to build external acpi_call module for kernel $kernel"; exit 1; }
cp ./acpi_call.ko ../../../chroot/home/chronos/kernel/lib/modules/"$kernel_version"/acpi_call.ko || { echo "Failed to build external acpi_call module for kernel $kernel"; exit 1; }
cd ../../.. || { echo "Failed to build external acpi_call module for kernel $kernel"; exit 1; }
rm -r ./chroot/tmp/acpi_call || { echo "Failed to build external acpi_call module for kernel $kernel"; exit 1; }
fi
if [ "$kernel" == "6.1" ]; then
cp -r ./external-drivers/ipts ./chroot/tmp/ || { echo "Failed to build external ipts module for kernel $kernel"; exit 1; }
cd ./chroot/tmp/ipts || { echo "Failed to build external ipts module for kernel $kernel"; exit 1; }
make -j"$NTHREADS" || { echo "Failed to build external ipts module for kernel $kernel"; exit 1; }
cp ./src/ipts.ko ../../../chroot/home/chronos/kernel/lib/modules/"$kernel_version"/ipts.ko || { echo "Failed to build external ipts module for kernel $kernel"; exit 1; }
cd ../../.. || { echo "Failed to build external ipts module for kernel $kernel"; exit 1; }
rm -r ./chroot/tmp/ipts || { echo "Failed to build external ipts module for kernel $kernel"; exit 1; }
fi
if [ "$kernel" == "6.1" ]; then
cp -r ./external-drivers/ithc ./chroot/tmp/ || { echo "Failed to build external ithc module for kernel $kernel"; exit 1; }
cd ./chroot/tmp/ithc || { echo "Failed to build external ithc module for kernel $kernel"; exit 1; }
make -j"$NTHREADS" || { echo "Failed to build external ithc module for kernel $kernel"; exit 1; }
cp ./build/ithc.ko ../../../chroot/home/chronos/kernel/lib/modules/"$kernel_version"/ithc.ko || { echo "Failed to build external ithc module for kernel $kernel"; exit 1; }
cd ../../.. || { echo "Failed to build external ithc module for kernel $kernel"; exit 1; }
rm -r ./chroot/tmp/ithc || { echo "Failed to build external ithc module for kernel $kernel"; exit 1; }
fi
fi
cd ./chroot/home/chronos/kernel || { echo "Failed to enter directory for kernel $kernel"; exit 1; }
tar zcf ../rootc/packages/kernel-"$kernel_version".tar.gz * --owner=0 --group=0 || { echo "Failed to create archive for kernel $kernel"; exit 1; }
cd ../../../.. || { echo "Failed to cleanup for kernel $kernel"; exit 1; }
rm -r ./chroot/home/chronos/kernel || { echo "Failed to cleanup for kernel $kernel"; exit 1; }
rm -r ./chroot/tmp/kernel || { echo "Failed to cleanup for kernel $kernel"; exit 1; }
done
cd ./chroot/home/chronos || { echo "Failed to switch to chronos directory"; exit 1; }
cp -r ../../../alsa-ucm-conf ./ || { echo "Failed to copy ucm configuration"; exit 1; }
cd ./alsa-ucm-conf || { echo "Failed to switch to ucm configuration directory"; exit 1; }
tar zcf ../rootc/packages/alsa-ucm-conf.tar.gz * --owner=0 --group=0 || { echo "Failed to create ucm configuration archive"; exit 1; }
cd .. || { echo "Failed to cleanup ucm configuration directory"; exit 1; }
rm -r ./alsa-ucm-conf || { echo "Failed to cleanup ucm configuration directory"; exit 1; }
git clone --depth=1 -b main https://git.kernel.org/pub/scm/linux/kernel/git/firmware/linux-firmware.git || { echo "Failed to clone the linux firmware git"; exit 1; }
cd ./linux-firmware || { echo "Failed to enter the linux firmware directory"; exit 1; }
make -j"$NTHREADS" DESTDIR=./tmp FIRMWAREDIR=/lib/firmware install || { echo "Failed to install firmwares in temporary directory"; exit 1; }
mv ./tmp/lib/firmware ./out || { echo "Failed to move the firmwares temporary directory"; exit 1; }
rm -rf ./out/bnx2x
rm -rf ./out/dpaa2
rm -rf ./out/liquidio
rm -rf ./out/mellanox
rm -rf ./out/mrvl/prestera
rm -rf ./out/netronome
rm -rf ./out/qcom
rm -rf ./out/qed
rm -rf ./out/ti-connectivity
curl -L https://git.kernel.org/pub/scm/linux/kernel/git/sforshee/wireless-regdb.git/plain/regulatory.db -o ./out/regulatory.db || { echo "Failed to download the regulatory db"; exit 1; }
curl -L https://git.kernel.org/pub/scm/linux/kernel/git/sforshee/wireless-regdb.git/plain/regulatory.db.p7s -o ./out/regulatory.db.p7s || { echo "Failed to download the regulatory db"; exit 1; }
cp -r ../../../../extra-firmwares/* ./out/ || { echo "Failed to copy brunch extra firmware files"; exit 1; }
mkdir -p ../rootc/lib/firmware || { echo "Failed to make firmware directory"; exit 1; }
curl -L https://archlinux.org/packages/core/any/amd-ucode/download/ -o /tmp/amd-ucode.tar.zst || { echo "Failed to download amd ucode"; exit 1; }
tar -C ../rootc/lib/firmware/ -xf /tmp/amd-ucode.tar.zst boot/amd-ucode.img --strip 1 || { echo "Failed to extract amd ucode"; exit 1; }
rm /tmp/amd-ucode.tar.zst || { echo "Failed to cleanup amd ucode"; exit 1; }
curl -L https://archlinux.org/packages/extra/any/intel-ucode/download/ -o /tmp/intel-ucode.tar.zst || { echo "Failed to download intel ucode"; exit 1; }
tar -C ../rootc/lib/firmware/ -xf /tmp/intel-ucode.tar.zst boot/intel-ucode.img --strip 1 || { echo "Failed to extract intel ucode"; exit 1; }
rm /tmp/intel-ucode.tar.zst || { echo "Failed to cleanup intel ucode"; exit 1; }
cd ./out || { echo "Failed to enter the final firmware directory"; exit 1; }
tar zcf ../../rootc/packages/firmwares.tar.gz * --owner=0 --group=0 || { echo "Failed to create the firmwares archive"; exit 1; }
cd ../.. || { echo "Failed to cleanup firmwares directory"; exit 1; }
rm -r ./linux-firmware || { echo "Failed to cleanup firmwares directory"; exit 1; }
cd ../../.. || { echo "Failed to cleanup firmwares directory"; exit 1; }
mount --bind ./out ./chroot/out || { echo "Failed to bind mount output directory in chroot"; exit 1; }
mount -t proc none ./chroot/proc || { echo "Failed to mount proc directory in chroot"; exit 1; }
mount -t sysfs none ./chroot/sys || { echo "Failed to mount sys directory in chroot"; exit 1; }
mount -t devtmpfs none ./chroot/dev || { echo "Failed to mount dev directory in chroot"; exit 1; }
mount -t tmpfs -o mode=1777,nosuid,nodev,strictatime tmpfs ./chroot/dev/shm || { echo "Failed to mount shm directory in chroot"; exit 1; }
cp ./scripts/build-init ./chroot/init || { echo "Failed to copy the chroot init script"; exit 1; }
NTHREADS="$NTHREADS" chroot --userspec=1000:1000 ./chroot /init || { echo "The chroot script failed"; exit 1; }
umount ./chroot/dev/shm || { echo "Failed to umount shm directory from chroot"; exit 1; }
umount ./chroot/dev || { echo "Failed to umount dev directory from chroot"; exit 1; }
umount ./chroot/sys || { echo "Failed to umount sys directory from chroot"; exit 1; }
umount ./chroot/proc || { echo "Failed to umount proc directory from chroot"; exit 1; }
umount ./chroot/out || { echo "Failed to umount output directory from chroot"; exit 1; }
rm -r ./chroot || { echo "Failed the final cleanup"; exit 1; }