forked from sbwml/r4s_build_script
-
Notifications
You must be signed in to change notification settings - Fork 0
/
build.sh
481 lines (431 loc) · 17.8 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
#!/bin/bash -e
export RED_COLOR='\e[1;31m'
export GREEN_COLOR='\e[1;32m'
export YELLOW_COLOR='\e[1;33m'
export BLUE_COLOR='\e[1;34m'
export PINK_COLOR='\e[1;35m'
export SHAN='\e[1;33;5m'
export RES='\e[0m'
#####################################
# NanoPi R4S OpenWrt Build Script #
#####################################
# IP Location
ip_info=`curl -s https://ip.cooluc.com`;
export isCN=`echo $ip_info | grep -Po 'country_code\":"\K[^"]+'`;
# script url
if [ "$isCN" = "CN" ]; then
export mirror=init.cooluc.com
else
export mirror=init2.cooluc.com
fi
# github actions - automatically retrieve `github raw` links
if [ "$(whoami)" = "runner" ] && [ -n "$GITHUB_REPO" ]; then
export mirror=raw.githubusercontent.com/$GITHUB_REPO/master
fi
# private gitea
export gitea=git.cooluc.com
# github mirror
if [ "$isCN" = "CN" ]; then
export github="github.com"
else
export github="github.com"
fi
# Check root
if [ "$(id -u)" = "0" ]; then
echo -e "${RED_COLOR}Building with root user is not supported.${RES}"
exit 1
fi
# Start time
starttime=`date +'%Y-%m-%d %H:%M:%S'`
CURRENT_DATE=$(date +%s)
# Cpus
cores=`expr $(nproc --all) + 1`
# $CURL_BAR
if curl --help | grep progress-bar >/dev/null 2>&1; then
CURL_BAR="--progress-bar";
fi
if [ -z "$1" ] || [ "$2" != "nanopi-r4s" -a "$2" != "nanopi-r5s" -a "$2" != "x86_64" ]; then
echo -e "\n${RED_COLOR}Building type not specified.${RES}\n"
echo -e "Usage:\n"
echo -e "nanopi-r4s releases: ${GREEN_COLOR}bash build.sh rc2 nanopi-r4s${RES}"
echo -e "nanopi-r4s snapshots: ${GREEN_COLOR}bash build.sh dev nanopi-r4s${RES}"
echo -e "nanopi-r5s releases: ${GREEN_COLOR}bash build.sh rc2 nanopi-r5s${RES}"
echo -e "nanopi-r5s snapshots: ${GREEN_COLOR}bash build.sh dev nanopi-r5s${RES}"
echo -e "x86_64 releases: ${GREEN_COLOR}bash build.sh rc2 x86_64${RES}"
echo -e "x86_64 snapshots: ${GREEN_COLOR}bash build.sh dev x86_64${RES}\n"
exit 1
fi
# Source branch
if [ "$1" = "dev" ]; then
export branch=openwrt-23.05
export version=snapshots-23.05
export toolchain_version=openwrt-23.05
elif [ "$1" = "rc2" ]; then
latest_release="v$(curl -s https://$mirror/tags/v23)"
export branch=$latest_release
export version=rc2
export toolchain_version=openwrt-23.05
fi
# platform
export platform=$2
[ "$platform" = "nanopi-r4s" ] && export platform="rk3399" toolchain_arch="nanopi-r4s"
[ "$platform" = "nanopi-r5s" ] && export platform="rk3568" toolchain_arch="nanopi-r5s"
[ "$platform" = "x86_64" ] && export platform="x86_64" toolchain_arch="x86_64"
# gcc13 & 14
if [ "$USE_GCC13" = y ]; then
export USE_GCC13=y
# use mold
[ "$USE_MOLD" = y ] && USE_MOLD=y
elif [ "$USE_GCC14" = y ]; then
export USE_GCC14=y
# use mold
[ "$USE_MOLD" = y ] && USE_MOLD=y
fi
# use glibc
export USE_GLIBC=$USE_GLIBC
# lrng
export ENABLE_LRNG=$ENABLE_LRNG
# print version
echo -e "\r\n${GREEN_COLOR}Building $branch${RES}\r\n"
if [ "$platform" = "x86_64" ]; then
echo -e "${GREEN_COLOR}Model: x86_64${RES}"
curl -s https://$mirror/tags/kernel-6.6 > kernel.txt
kmod_hash=$(grep HASH kernel.txt | awk -F'HASH-' '{print $2}' | awk '{print $1}' | md5sum | awk '{print $1}')
kmodpkg_name=$(echo $(grep HASH kernel.txt | awk -F'HASH-' '{print $2}' | awk '{print $1}')-1-$(echo $kmod_hash))
echo -e "${GREEN_COLOR}Kernel: $kmodpkg_name ${RES}"
rm -f kernel.txt
elif [ "$platform" = "rk3568" ]; then
echo -e "${GREEN_COLOR}Model: nanopi-r5s/r5c${RES}"
[ "$1" = "rc2" ] && model="nanopi-r5s"
curl -s https://$mirror/tags/kernel-6.6 > kernel.txt
kmod_hash=$(grep HASH kernel.txt | awk -F'HASH-' '{print $2}' | awk '{print $1}' | md5sum | awk '{print $1}')
kmodpkg_name=$(echo $(grep HASH kernel.txt | awk -F'HASH-' '{print $2}' | awk '{print $1}')-1-$(echo $kmod_hash))
echo -e "${GREEN_COLOR}Kernel: $kmodpkg_name ${RES}"
rm -f kernel.txt
else
echo -e "${GREEN_COLOR}Model: nanopi-r4s${RES}"
[ "$1" = "rc2" ] && model="nanopi-r4s"
curl -s https://$mirror/tags/kernel-6.6 > kernel.txt
kmod_hash=$(grep HASH kernel.txt | awk -F'HASH-' '{print $2}' | awk '{print $1}' | md5sum | awk '{print $1}')
kmodpkg_name=$(echo $(grep HASH kernel.txt | awk -F'HASH-' '{print $2}' | awk '{print $1}')-1-$(echo $kmod_hash))
echo -e "${GREEN_COLOR}Kernel: $kmodpkg_name ${RES}"
rm -f kernel.txt
fi
echo -e "${GREEN_COLOR}Date: $CURRENT_DATE${RES}\r\n"
if [ "$USE_GCC13" = "y" ]; then
echo -e "${GREEN_COLOR}GCC VERSION: 13${RES}"
elif [ "$USE_GCC14" = "y" ]; then
echo -e "${GREEN_COLOR}GCC VERSION: 14${RES}"
else
echo -e "${GREEN_COLOR}GCC VERSION: 11${RES}"
fi
[ "$USE_MOLD" = "y" ] && echo -e "${GREEN_COLOR}USE_MOLD: true${RES}" || echo -e "${GREEN_COLOR}USE_MOLD: false${RES}"
[ "$ENABLE_OTA" = "y" ] && echo -e "${GREEN_COLOR}ENABLE_OTA: true${RES}" || echo -e "${GREEN_COLOR}ENABLE_OTA: false${RES}"
[ "$ENABLE_BPF" = "y" ] && echo -e "${GREEN_COLOR}ENABLE_BPF: true${RES}" || echo -e "${GREEN_COLOR}ENABLE_BPF: false${RES}"
[ "$ENABLE_LTO" = "y" ] && echo -e "${GREEN_COLOR}ENABLE_LTO: true${RES}" || echo -e "${GREEN_COLOR}ENABLE_LTO: false${RES}"
[ "$ENABLE_LRNG" = "y" ] && echo -e "${GREEN_COLOR}ENABLE_LRNG: true${RES}" || echo -e "${GREEN_COLOR}ENABLE_LRNG: false${RES}"
[ "$BUILD_FAST" = "y" ] && echo -e "${GREEN_COLOR}BUILD_FAST: true${RES}" || echo -e "${GREEN_COLOR}BUILD_FAST: false${RES}"
[ "$MINIMAL_BUILD" = "y" ] && echo -e "${GREEN_COLOR}MINIMAL_BUILD: true${RES}\r\n" || echo -e "${GREEN_COLOR}MINIMAL_BUILD: false${RES}\r\n"
# clean old files
rm -rf openwrt master && mkdir master
# openwrt - releases
git clone --depth=1 https://$github/openwrt/openwrt -b $branch
# openwrt master
git clone https://$github/openwrt/openwrt master/openwrt --depth=1
git clone https://$github/openwrt/packages master/packages --depth=1
git clone https://$github/openwrt/luci master/luci --depth=1
git clone https://$github/openwrt/routing master/routing --depth=1
# openwrt-23.05
[ "$1" = "rc2" ] && git clone https://$github/openwrt/openwrt -b openwrt-23.05 master/openwrt-23.05 --depth=1
# immortalwrt master
git clone https://$github/immortalwrt/packages master/immortalwrt_packages --depth=1
if [ -d openwrt ]; then
cd openwrt
[ "$1" = "rc2" ] && echo "$CURRENT_DATE" > version.date
curl -Os https://$mirror/openwrt/patch/key.tar.gz && tar zxf key.tar.gz && rm -f key.tar.gz
else
echo -e "${RED_COLOR}Failed to download source code${RES}"
exit 1
fi
# tags
if [ "$1" = "rc2" ]; then
git describe --abbrev=0 --tags > version.txt
else
git branch | awk '{print $2}' > version.txt
fi
# feeds mirror
if [ "$1" = "rc2" ]; then
packages="^$(grep packages feeds.conf.default | awk -F^ '{print $2}')"
luci="^$(grep luci feeds.conf.default | awk -F^ '{print $2}')"
routing="^$(grep routing feeds.conf.default | awk -F^ '{print $2}')"
telephony="^$(grep telephony feeds.conf.default | awk -F^ '{print $2}')"
else
packages=";$branch"
luci=";$branch"
routing=";$branch"
telephony=";$branch"
fi
cat > feeds.conf <<EOF
src-git packages https://$github/openwrt/packages.git$packages
src-git luci https://$github/openwrt/luci.git$luci
src-git routing https://$github/openwrt/routing.git$routing
src-git telephony https://$github/openwrt/telephony.git$telephony
EOF
# Init feeds
./scripts/feeds update -a
./scripts/feeds install -a
# loader dl
if [ -f ../dl.gz ]; then
tar xf ../dl.gz -C .
fi
###############################################
echo -e "\n${GREEN_COLOR}Patching ...${RES}\n"
# scripts
curl -sO https://$mirror/openwrt/scripts/00-prepare_base.sh
curl -sO https://$mirror/openwrt/scripts/01-prepare_base-mainline.sh
curl -sO https://$mirror/openwrt/scripts/02-prepare_package.sh
curl -sO https://$mirror/openwrt/scripts/03-convert_translation.sh
curl -sO https://$mirror/openwrt/scripts/04-fix_kmod.sh
curl -sO https://$mirror/openwrt/scripts/05-fix-source.sh
curl -sO https://$mirror/openwrt/scripts/99_clean_build_cache.sh
chmod 0755 *sh
bash 00-prepare_base.sh
bash 02-prepare_package.sh
bash 03-convert_translation.sh
bash 05-fix-source.sh
if [ "$platform" = "rk3568" ] || [ "$platform" = "rk3399" ] || [ "$platform" = "x86_64" ]; then
bash 01-prepare_base-mainline.sh
bash 04-fix_kmod.sh
fi
if [ "$USE_GCC14" = "y" ]; then
rm -rf toolchain/binutils
cp -a ../master/openwrt/toolchain/binutils toolchain/binutils
fi
rm -f 0*-*.sh
rm -rf ../master
# Load devices Config
if [ "$platform" = "x86_64" ]; then
curl -s https://$mirror/openwrt/23-config-musl-x86 > .config
ALL_KMODS=y
elif [ "$platform" = "rk3568" ]; then
curl -s https://$mirror/openwrt/23-config-musl-r5s > .config
ALL_KMODS=y
else
curl -s https://$mirror/openwrt/23-config-musl-r4s > .config
fi
# config-common
if [ "$MINIMAL_BUILD" = "y" ]; then
curl -s https://$mirror/openwrt/23-config-minimal-common >> .config
echo 'VERSION_TYPE="minimal"' >> package/base-files/files/usr/lib/os-release
else
curl -s https://$mirror/openwrt/23-config-common >> .config
fi
# ota
[ "$ENABLE_OTA" = "y" ] && [ "$version" = "rc2" ] && echo 'CONFIG_PACKAGE_luci-app-ota=y' >> .config
# bpf
export ENABLE_BPF=$ENABLE_BPF
[ "$ENABLE_BPF" = "y" ] && curl -s https://$mirror/openwrt/generic/config-bpf >> .config
# LTO
export ENABLE_LTO=$ENABLE_LTO
[ "$ENABLE_LTO" = "y" ] && curl -s https://$mirror/openwrt/generic/config-lto >> .config
# glibc
[ "$USE_GLIBC" = "y" ] && {
curl -s https://$mirror/openwrt/generic/config-glibc >> .config
sed -i '/NaiveProxy/d' .config
}
# mold
[ "$USE_MOLD" = "y" ] && echo 'CONFIG_USE_MOLD=y' >> .config
# openwrt-23.05 gcc11/13/14
if [ "$USE_GCC13" = "y" ] || [ "$USE_GCC14" = "y" ]; then
[ "$USE_GCC13" = "y" ] && curl -s https://$mirror/openwrt/generic/config-gcc13 >> .config
[ "$USE_GCC14" = "y" ] && curl -s https://$mirror/openwrt/generic/config-gcc14 >> .config
curl -s https://$mirror/openwrt/patch/generic/200-toolchain-gcc-update-to-13.2.patch | patch -p1
curl -s https://$mirror/openwrt/patch/generic/201-toolchain-gcc-add-support-for-GCC-14.patch | patch -p1
if [ "$USE_GCC14" = "y" ]; then
cp -a toolchain/gcc/patches-13.x toolchain/gcc/patches-14.x
curl -s https://$mirror/openwrt/patch/generic/gcc-14/910-mbsd_multi.patch > toolchain/gcc/patches-14.x/910-mbsd_multi.patch
curl -s https://$mirror/openwrt/patch/generic/gcc-14/990-libatomic-Fix-build-for---disable-gnu-indirect-function-PR113986.patch > toolchain/gcc/patches-14.x/990-libatomic-Fix-build-for---disable-gnu-indirect-function-PR113986.patch
fi
elif [ ! "$USE_GLIBC" = "y" ]; then
curl -s https://$mirror/openwrt/generic/config-gcc11 >> .config
fi
# clean directory - github actions
[ "$(whoami)" = "runner" ] && echo 'CONFIG_AUTOREMOVE=y' >> .config
# uhttpd
[ "$ENABLE_UHTTPD" = "y" ] && sed -i '/nginx/d' .config && echo 'CONFIG_PACKAGE_ariang=y' >> .config
# Toolchain Cache
if [ "$BUILD_FAST" = "y" ]; then
[ "$USE_GLIBC" = "y" ] && LIBC=glibc || LIBC=musl
[ "$isCN" = "CN" ] && github_proxy="http://gh.cooluc.com/" || github_proxy=""
echo -e "\n${GREEN_COLOR}Download Toolchain ...${RES}"
PLATFORM_ID=""
[ -f /etc/os-release ] && source /etc/os-release
if [ "$PLATFORM_ID" = "platform:el9" ]; then
TOOLCHAIN_URL="http://127.0.0.1:8080"
else
TOOLCHAIN_URL="$github_proxy"https://github.com/sbwml/toolchain-cache/releases/latest/download
fi
if [ "$USE_GCC13" = "y" ]; then
curl -L "$TOOLCHAIN_URL"/toolchain_"$LIBC"_"$toolchain_arch"_13.tar.gz -o toolchain.tar.gz $CURL_BAR
elif [ "$USE_GCC14" = "y" ]; then
curl -L "$TOOLCHAIN_URL"/toolchain_"$LIBC"_"$toolchain_arch"_14.tar.gz -o toolchain.tar.gz $CURL_BAR
else
curl -L "$TOOLCHAIN_URL"/toolchain_"$LIBC"_"$toolchain_arch".tar.gz -o toolchain.tar.gz $CURL_BAR
fi
echo -e "\n${GREEN_COLOR}Process Toolchain ...${RES}"
tar -zxf toolchain.tar.gz && rm -f toolchain.tar.gz
mkdir bin
find ./staging_dir/ -name '*' -exec touch {} \; >/dev/null 2>&1
find ./tmp/ -name '*' -exec touch {} \; >/dev/null 2>&1
fi
# init openwrt config
rm -rf tmp/*
if [ "$BUILD" = "n" ]; then
exit 0
else
make defconfig
fi
# Compile
if [ "$BUILD_TOOLCHAIN" = "y" ]; then
echo -e "\r\n${GREEN_COLOR}Building Toolchain ...${RES}\r\n"
make -j$cores toolchain/compile || make -j$cores toolchain/compile V=s || exit 1
mkdir -p toolchain-cache
[ "$USE_GLIBC" = "y" ] && LIBC=glibc || LIBC=musl
if [ "$USE_GCC13" = "y" ]; then
tar -zcf toolchain-cache/toolchain_"$LIBC"_"$toolchain_arch"_13.tar.gz ./{build_dir,dl,staging_dir,tmp} && echo -e "${GREEN_COLOR} Build success! ${RES}"
elif [ "$USE_GCC14" = "y" ]; then
tar -zcf toolchain-cache/toolchain_"$LIBC"_"$toolchain_arch"_14.tar.gz ./{build_dir,dl,staging_dir,tmp} && echo -e "${GREEN_COLOR} Build success! ${RES}"
else
tar -zcf toolchain-cache/toolchain_"$LIBC"_"$toolchain_arch".tar.gz ./{build_dir,dl,staging_dir,tmp} && echo -e "${GREEN_COLOR} Build success! ${RES}"
fi
exit 0
else
echo -e "\r\n${GREEN_COLOR}Building OpenWrt ...${RES}\r\n"
sed -i "/BUILD_DATE/d" package/base-files/files/usr/lib/os-release
sed -i "/BUILD_ID/aBUILD_DATE=\"$CURRENT_DATE\"" package/base-files/files/usr/lib/os-release
make -j$cores
fi
# Compile time
endtime=`date +'%Y-%m-%d %H:%M:%S'`
start_seconds=$(date --date="$starttime" +%s);
end_seconds=$(date --date="$endtime" +%s);
SEC=$((end_seconds-start_seconds));
if [ "$platform" = "x86_64" ]; then
if [ -f bin/targets/x86/64*/*-ext4-combined-efi.img.gz ]; then
echo -e "${GREEN_COLOR} Build success! ${RES}"
echo -e " Build time: $(( SEC / 3600 ))h,$(( (SEC % 3600) / 60 ))m,$(( (SEC % 3600) % 60 ))s"
if [ "$ALL_KMODS" = y ]; then
cp -a bin/targets/x86/*/packages $kmodpkg_name
rm -f $kmodpkg_name/Packages*
# driver firmware
cp -a bin/packages/x86_64/base/*firmware*.ipk $kmodpkg_name/
bash kmod-sign $kmodpkg_name
tar zcf x86_64-$kmodpkg_name.tar.gz $kmodpkg_name
rm -rf $kmodpkg_name
fi
# OTA json
if [ "$1" = "rc2" ]; then
mkdir -p ota
if [ "$MINIMAL_BUILD" = "y" ]; then
BUILD_TYPE=minimal
else
BUILD_TYPE=releases
fi
VERSION=$(sed 's/v//g' version.txt)
SHA256=$(sha256sum bin/targets/x86/64/*-generic-squashfs-combined-efi.img.gz | awk '{print $1}')
cat > ota/fw.json <<EOF
{
"x86_64": [
{
"build_date": "$CURRENT_DATE",
"sha256sum": "$SHA256",
"url": "https://x86.cooluc.com/$BUILD_TYPE/openwrt-23.05/v$VERSION/openwrt-$VERSION-x86-64-generic-squashfs-combined-efi.img.gz"
}
]
}
EOF
fi
# Backup download cache
if [ "$isCN" = "CN" ] && [ "$1" = "rc2" ]; then
rm -rf dl/geo* dl/go-mod-cache
tar cf ../dl.gz dl
fi
exit 0
else
echo -e "\n${RED_COLOR} Build error... ${RES}"
echo -e " Build time: $(( SEC / 3600 ))h,$(( (SEC % 3600) / 60 ))m,$(( (SEC % 3600) % 60 ))s"
echo
exit 1
fi
else
if [ -f bin/targets/rockchip/armv8*/*-r5s-ext4-sysupgrade.img.gz ] || [ -f bin/targets/rockchip/armv8*/*-r5c-ext4-sysupgrade.img.gz ] || [ -f bin/targets/rockchip/armv8*/*-r4s-ext4-sysupgrade.img.gz ]; then
if [ "$ALL_KMODS" = y ]; then
cp -a bin/targets/rockchip/armv8*/packages $kmodpkg_name
rm -f $kmodpkg_name/Packages*
# driver firmware
cp -a bin/packages/aarch64_generic/base/*firmware*.ipk $kmodpkg_name/
bash kmod-sign $kmodpkg_name
tar zcf aarch64-$kmodpkg_name.tar.gz $kmodpkg_name
rm -rf $kmodpkg_name
fi
echo -e "${GREEN_COLOR} Build success! ${RES}"
echo -e " Build time: ${GREEN_COLOR}$(( SEC / 3600 ))h,$(( (SEC % 3600) / 60 ))m,$(( (SEC % 3600) % 60 ))s${RES}"
# OTA json
if [ "$1" = "rc2" ]; then
mkdir -p ota
if [ "$MINIMAL_BUILD" = "y" ]; then
BUILD_TYPE=minimal
else
BUILD_TYPE=releases
fi
VERSION=$(sed 's/v//g' version.txt)
if [ "$model" = "nanopi-r4s" ]; then
SHA256=$(sha256sum bin/targets/rockchip/armv8*/*-squashfs-sysupgrade.img.gz | awk '{print $1}')
cat > ota/fw.json <<EOF
{
"friendlyarm,nanopi-r4s": [
{
"build_date": "$CURRENT_DATE",
"sha256sum": "$SHA256",
"url": "https://r4s.cooluc.com/$BUILD_TYPE/openwrt-23.05/v$VERSION/openwrt-$VERSION-rockchip-armv8-friendlyarm_nanopi-r4s-squashfs-sysupgrade.img.gz"
}
]
}
EOF
elif [ "$model" = "nanopi-r5s" ]; then
SHA256_R5C=$(sha256sum bin/targets/rockchip/armv8*/*-r5c-squashfs-sysupgrade.img.gz | awk '{print $1}')
SHA256_R5S=$(sha256sum bin/targets/rockchip/armv8*/*-r5s-squashfs-sysupgrade.img.gz | awk '{print $1}')
cat > ota/fw.json <<EOF
{
"friendlyarm,nanopi-r5c": [
{
"build_date": "$CURRENT_DATE",
"sha256sum": "$SHA256_R5C",
"url": "https://r5s.cooluc.com/$BUILD_TYPE/openwrt-23.05/v$VERSION/openwrt-$VERSION-rockchip-armv8-friendlyarm_nanopi-r5c-squashfs-sysupgrade.img.gz"
}
],
"friendlyarm,nanopi-r5s": [
{
"build_date": "$CURRENT_DATE",
"sha256sum": "$SHA256_R5S",
"url": "https://r5s.cooluc.com/$BUILD_TYPE/openwrt-23.05/v$VERSION/openwrt-$VERSION-rockchip-armv8-friendlyarm_nanopi-r5s-squashfs-sysupgrade.img.gz"
}
]
}
EOF
fi
fi
# Backup download cache
if [ "$isCN" = "CN" ] && [ "$version" = "rc2" ]; then
rm -rf dl/geo* dl/go-mod-cache
tar -cf ../dl.gz dl
fi
exit 0
else
echo -e "\n${RED_COLOR} Build error... ${RES}"
echo -e " Build time: ${RED_COLOR}$(( SEC / 3600 ))h,$(( (SEC % 3600) / 60 ))m,$(( (SEC % 3600) % 60 ))s${RES}"
echo
exit 1
fi
fi
# 很少有人会告诉你为什么要这样做,而是会要求你必须要这样做。