forked from armarchindo/ULO-Builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ulo
executable file
·825 lines (717 loc) · 24.2 KB
/
ulo
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
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
#!/usr/bin/env bash
#
# Copyright (c) 2023 ulo
#
# Licensed under the MIT.
#
lolcat=/usr/games/lolcat
tmp="./tmp"
out="./out"
minsize=640
# SOC
amlogic=`ls -l ./core/loader/amlogic | grep s9 | awk '{ print $9 }' | cut -d. -f1`
allwinner=`ls -l ./core/loader/allwinner | grep u-boot-sunxi-with-spl | awk '{ print $9 }' | cut -c 23- | cut -d. -f1`
rockchip=`ls -l ./core/loader/rockchip | grep idbloader | awk '{ print $9 }' | cut -c 11- | cut -d. -f1`
# directory path
device_path="./device"
kernel_path="./core/kernel"
rootfs_path="./rootfs"
fwdriver_path="./core/root/lib"
# Kernel & Firmware Repository
repos="https://github.com/bobbyunknown/ULO-repository"
start_cnt=$SECONDS
die() {
echo -e "ERROR.. = $1"
exit 1
}
check_depedencies() {
echo -e "Preparing install ulo dependies"
req=(lolcat pigz aria2 wget)
list=`dpkg -l | grep -E "lolcat|pigz|aria2|wget" | awk '{ print $2 }'`
for req_pkg in ${req[*]}; do
for lst_pkg in $list; do
stat=0
if [ ${req_pkg} == $lst_pkg ] ; then
echo " $req_pkg Installed"
stat=0
break;
else
stat=1
fi
done
if [[ $stat = 1 ]] ; then
echo " Package $req_pkg not found"
echo " Installing $req_pkg "
apt -y install $req_pkg > /dev/null 2>&1
fi
done
echo -e "Done...!!!" | $lolcat -a -d 20
}
check_requirement_files() {
statx=0
find_devices
find_rootfs
find_kernels
[ ${#devices[*]} = 0 ] && die "No ${device_path:2} file or directory!"
[ ${#rootfs[*]} = 0 ] && statx=1
[ ${#kernels[*]} = 0 ] && statx=2
[ -d "${fwdriver_path}/firmware" ] || statx=3
if [ $statx = 1 ]; then
echo -e "ROOTFS files not available!"
download_requirement_files false
elif [ $statx = 2 ]; then
echo -e "Kernel files is not found!"
download_requirement_files false
elif [ $statx = 3 ]; then
echo -e "Firmware files is not found!"
download_requirement_files false
fi
}
download_requirement_files() {
local tmp_path="./tmp"
local cmd=$1
if [ $cmd = true ]; then
rm -rf ./core/kernel/*
rm -rf ./rootfs/*
rm -rf $fwdriver_path/firmware
fi
[ -d "${tmp_path}" ] || mkdir $tmp_path
if [ ! -f "${tmp_path}/data.zip" ]; then
echo -e "Downloading KERNEL, ROOTFS, & Driver Firmware" | $lolcat -a -d 1
aria2c --out=${tmp_path}/data.zip "${repos}/archive/refs/heads/main.zip"
echo -e "Unzipping KERNEL, ROOTFS, & Driver Firmware" | $lolcat -a -d 1
unzip -q $tmp_path/data.zip -d $tmp_path
cp -rf $tmp_path/ULO-repository-main/kernel ./core/
cp -rf $tmp_path/ULO-repository-main/rootfs ./
cp -rf $tmp_path/ULO-repository-main/firmware $fwdriver_path/
echo -e "Done..." | $lolcat -a -d 5
rm -r $tmp_path
fi
echo -e "All required files are present." | $lolcat -a -d 1
find_devices
find_rootfs
find_kernels
}
check_depedencies
cleaning() {
for x in $(lsblk | grep $(pwd) | grep -oE 'loop[0-9]+' | sort | uniq); do
umount -f /dev/${x}p[1-2] 2>/dev/null
umount -f /dev/$x 2>/dev/null
losetup -d /dev/$x 2>/dev/null
losetup -D 2>/dev/null
done
rm -rf $tmp
[ "$1" ] || rm -rf $out
}
kernel_checker() {
local kernelx=$1
local cmdx=$2
local is_amlogic=false
local is_allwinner=false
local is_rockchip=false
local kinfo=`ls core/kernel/${kernelx} | grep dtb | cut -d- -f2`
echo $amlogic | grep -iq $device && is_amlogic=true
echo $allwinner | grep -iq $device && is_allwinner=true
echo $rockchip | grep -iq $device && is_rockchip=true
if [ $is_amlogic = true ] && [ $kinfo = "amlogic" ]; then
[ $cmdx = false ] && echo -e "${kernel}\n" | $lolcat -a -d 5
elif [ $is_allwinner = true ] && [ $kinfo = "allwinner" ]; then
[ $cmdx = false ] && echo -e "${kernel}\n" | $lolcat -a -d 5
elif [ $is_rockchip = true ] && [ $kinfo = "rockchip" ]; then
[ $cmdx = false ] && echo -e "${kernel}\n" | $lolcat -a -d 5
elif [ $cmdx = true ]; then
die "This kernel is for ${kinfo} devices!!!"
else
echo "This kernel is for ${kinfo} devices!!!"
echo "Please re-select"
find_kernels
choose_kernel
fi
}
find_devices() {
local path=$device_path
[ -d $path ] || return
local len=0
IFS=$'\n'
for x in $(ls $path); do
[ -f $path/$x/boot-*.tar.gz ] && devices[len++]=$x
done
}
find_kernels() {
local path=$kernel_path
[ -d $path ] || return
local len=0
IFS=$'\n'
for x in $(ls $path); do
[ -f $path/$x/dtb-*.tar.gz ] && [ -f $path/$x/boot-*.tar.gz ] && [ -f $path/$x/modules-*.tar.gz ] \
&& kernels[len++]=$x
done
}
find_rootfs() {
local path=$rootfs_path
[ -d $path ] || return
local len=0
IFS=$'\n'
for x in $(ls $path); do
rootfs[len++]=$x
done
}
choose_device() {
local i=0
echo -e "Chipset: " | $lolcat -a -d 5
choose_option "${devices[*]}" ${#devices[*]}
local opt=$?
device=${devices[opt]}
devices=($device)
echo -e "${device}\n" | $lolcat -a -d 5
}
choose_rootfs() {
local i=0
echo -e "ROOTFS: " | $lolcat -a -d 5
choose_option "${rootfs[*]}" ${#rootfs[*]}
local opt=$?
firmware=${rootfs[opt]}
echo -e "${firmware}\n" | $lolcat -a -d 5
echo $firmware > $rootfs_path/rootfs.log
}
choose_kernel() {
local i=0
echo -e "Kernel:" | $lolcat -a -d 5
choose_option "${kernels[*]}" ${#kernels[*]} "kernel"
local opt=$?
kernel=${kernels[opt]}
kernels=($kernel)
kernel_checker "${kernel}" false
}
choose_option() {
local options=$1
local len=$2
local optx=$3
local cnt=0
if [ ! $optx ]; then
for x in ${options[*]}; do
echo -e "($((++i))) => $x "
done
else
for x in ${options[*]}; do
local kinfo=`ls core/kernel/${x} | grep dtb | cut -d- -f2`
if [ $kinfo = 'amlogic' ]; then
kinfo='Amlogic '
elif [ $kinfo = 'allwinner' ]; then
kinfo='AllWinner'
elif [ $kinfo = 'rockchip' ]; then
kinfo='Rockchip '
else
kinfo='Undefined'
fi
echo -e "($((++i))) => $kinfo $x "
done
fi
[ "$len" = 1 ] && return 0
while [ $cnt -lt 3 ]; do
echo "Select Number:" | $lolcat -a -d 5
read -p "" opt
if [ ! "$opt" ]; then
opt=0
break
elif [[ "$opt" -ge 1 && "$opt" -le "$len" ]] 2>/dev/null; then
((opt--))
break
else
((cnt++))
echo -e "Salah pilih ulo.."
sleep 1s
fi
done
[ $cnt = 3 ] && die "Bye NooB...!!!"
return $opt
}
make_losetup() {
local path=$1
loop=$(losetup -Pf --show $path)
[ $loop ] || die "Error... ${path:2}"
[ $2 ] && return 0
loop_seq=$(ls $loop | grep -oE 'loop[0-9]+')
mount="$tmp/mount"
mkdir -p $mount
[ -e ${loop}p1 ] && {
mkdir -p $mount/${loop_seq}p1
mount ${loop}p1 $mount/${loop_seq}p1
}
[ -e ${loop}p2 ] && {
mkdir -p $mount/${loop_seq}p2
mount ${loop}p2 $mount/${loop_seq}p2
}
[[ ! -e ${loop}p1 && ! -e ${loop}p2 && -e ${loop} ]] && {
mkdir -p $mount/${loop_seq}
mount ${loop} $mount/${loop_seq}
}
}
unpack_openwrt() {
local path="$rootfs_path/$firmware"
local suffix="${firmware##*.}"
common_root="$tmp/core/root"
start_build=$SECONDS
mkdir -p $common_root
while true; do
case "$suffix" in
xz)
xz -dc $path > $tmp/${firmware%.*}
path=$tmp/${firmware%.*}
suffix=${path##*.}
;;
gz)
# special for .tar.gz
if ls $path | grep -q '.tar.gz$'; then
tar xzf $path -C $common_root
break
else
gzip -dc $path > $tmp/${firmware%.*}
path=$tmp/${firmware%.*}
suffix=${path##*.}
fi
;;
img|ext4)
make_losetup $path
if [ -d $mount/${loop_seq}p2 ]; then
cp -r $mount/${loop_seq}p2/* $common_root
elif [ -d $mount/${loop_seq}p1 ]; then
cp -r $mount/${loop_seq}p1/* $common_root
elif [ -d $mount/${loop_seq} ]; then
cp -r $mount/${loop_seq}/* $common_root
else
die "error unpack $path"
fi
break
;;
*)
die "Format error!"
;;
esac
done
rm -rf $common_root/lib/modules/*/
}
unpack_boot_kernel() {
local path="$kernel_path/$kernel"
common_boot="$tmp/core/kernel/$kernel/boot"
last_device="$tmp/device/$device"
local is_amlogic=false
local is_allwinner=false
local is_rockchip=false
echo $amlogic | grep -iq $device && is_amlogic=true
echo $allwinner | grep -iq $device && is_allwinner=true
echo $rockchip | grep -iq $device && is_rockchip=true
mkdir -p $common_boot
tar xzf $path/boot-*.tar.gz -C $common_boot 2>/dev/null
if [ $is_amlogic = true ]; then
mkdir -p ${last_device}/$kernel/{boot,boot/dtb,boot/dtb/amlogic,root,root/lib/modules}
tar xzf $kernel_path/$kernel/dtb-*.tar.gz -C ${last_device}/$kernel/boot/dtb/amlogic
elif [ $is_allwinner = true ]; then
mkdir -p ${last_device}/$kernel/{boot,boot/dtb,boot/dtb/allwinner,root,root/lib/modules}
tar xzf $kernel_path/$kernel/dtb-*.tar.gz -C ${last_device}/$kernel/boot/dtb/allwinner
elif [ $is_rockchip = true ]; then
mkdir -p ${last_device}/$kernel/{boot,boot/dtb,boot/dtb/rockchip,root,root/lib/modules}
tar xzf $kernel_path/$kernel/dtb-*.tar.gz -C ${last_device}/$kernel/boot/dtb/rockchip
fi
cp -r $common_boot/* ${last_device}/$kernel/boot
cp -r $common_root/* ${last_device}/$kernel/root
tar xzf $device_path/$device/boot-$device.tar.gz -C ${last_device}/$kernel/boot
tar xzf $path/modules-*.tar.gz -C ${last_device}/$kernel/root/lib/modules
(cd $tmp/device/$device/$kernel/root/lib/modules/$kernel/ && rm -f build source *.ko 2>/dev/null &&
find ./ -type f -name '*.ko' -exec ln -s {} ./ \;)
[ $(ls $device_path/$device/root | wc -l) = 0 ] || cp -r $device_path/$device/root/* ${last_device}/$kernel/root
[ $(ls ./core/root | wc -l) = 0 ] || cp -r ./core/root/* ${last_device}/$kernel/root
}
make_image() {
local image="$out/$device/$(cat ${rootfs_path}/rootfs.log | cut -d '-' -f1-3)-$device-k$kernel.img"
[ -d $out/$device ] || mkdir -p $out/$device
fallocate -l $((16 + 256 + rootsize))M $image
parted -s $image mklabel msdos
parted -s $image mkpart primary fat32 17M 273M
parted -s $image mkpart primary ext4 273M 100%
make_losetup $image 1
local is_amlogic=false
echo $amlogic | grep -iq $device && is_amlogic=true
local is_rockchip=false
echo $rockchip | grep -iq $device && is_rockchip=true
local is_allwinner=false
echo $allwinner | grep -iq $device && is_allwinner=true
mkfs.vfat -n "BOOT" ${loop}p1 >/dev/null 2>&1
mke2fs -F -q -t ext4 -L "ROOTFS" -m 0 ${loop}p2 >/dev/null 2>&1
txtloader=""
if [ $is_amlogic = true ]; then
# AMLOGIC DEVICES BOOTLOADER
loader="./core/loader/amlogic/${device}.bin"
txtloader="${device}.bin"
dd if=$loader of=$loop bs=1 count=444 conv=fsync 2>/dev/null
dd if=$loader of=$loop bs=512 skip=1 seek=1 conv=fsync 2>/dev/null
fi
if [ $is_allwinner = true ]; then
# ALLWINNER DEVICES BOOTLOADER
loader="./core/loader/allwinner/u-boot-sunxi-with-spl-${device}.bin"
loader1="./core/loader/allwinner/u-boot-mainline-${device}.bin"
dd if=$loader of=$loop bs=8k seek=1 conv=fsync,notrunc 2>/dev/null
if [ -f ${loader} ]; then
dd if=$loader of=$loop bs=8k seek=1 conv=fsync,notrunc 2>/dev/null
txtloader="${txtloader}u-boot-sunxi-with-spl-${device}.bin"
fi
if [ -f ${loader1} ]; then
dd if=$loader1 of=$loop bs=8k seek=5 conv=fsync,notrunc 2>/dev/null
txtloader="${txtloader} | u-boot-mainline-${device}.bin"
fi
fi
if [ $is_rockchip = true ]; then
# ROCKCHIP DEVICES BOOTLOADER
loader="./core/loader/rockchip/idbloader-${device}.img"
loader1="./core/loader/rockchip/u-boot-${device}.itb"
loader2="./core/loader/rockchip/trust-${device}.bin"
if [ -f ${loader} ]; then
dd if=$loader of=$loop conv=fsync,notrunc bs=512 seek=64 2>/dev/null
txtloader="${txtloader}idbloader-${device}.img"
fi
if [ -f ${loader1} ]; then
dd if=$loader1 of=$loop conv=fsync,notrunc bs=512 seek=16384 2>/dev/null
txtloader="${txtloader} | u-boot-${device}.itb"
fi
if [ -f ${loader2} ]; then
dd if=$loader2 of=$loop conv=fsync,notrunc bs=512 seek=24576 2>/dev/null
txtloader="${txtloader} | trust-${device}.bin"
fi
fi
echo $txtloader > $rootfs_path/uboot.log
losetup -d ${loop}
make_losetup $image
{
set -e
cp -r ${last_device}/$kernel/boot/* $mount/${loop_seq}p1
cp -r ${last_device}/$kernel/root/* $mount/${loop_seq}p2
(
cd $mount/${loop_seq}p1
if [ $is_allwinner = true ]; then
cp uInitrd-* uInitrd
cp vmlinuz-* Image
elif [ $is_rockchip = true ]; then
cp uInitrd-* uInitrd
cp vmlinuz-* Image
elif [ $is_amlogic = true ]; then
mv uInitrd-* uInitrd
mv vmlinuz-* zImage
fi
)
lain_lain "$mount/${loop_seq}p2"
}
}
lain_lain() {
local path=$1
[ -d $path ] && {
mkdir -p $path/{boot,opt,run}
local is_amlogic=false
local is_allwinner=false
local is_rockchip=false
echo $amlogic | grep -iq $device && is_amlogic=true
echo $allwinner | grep -iq $device && is_allwinner=true
echo $rockchip | grep -iq $device && is_rockchip=true
if [ $is_amlogic = true ]; then
printf 'pwm_meson' > $path/etc/modules.d/pwm-meson
sed -i 's/ttyAMA0/ttyAML0/' $path/etc/inittab
sed -i 's/ttyS0/tty0/' $path/etc/inittab
if ! grep -q '/tmp/upgrade' $path/etc/init.d/boot; then
sed -i '/kmodloader/i\\tmkdir -p \/tmp\/upgrade' $path/etc/init.d/boot
fi
elif [ $is_allwinner = true ]; then
sed -i 's/ttyAMA0/tty1/' $path/etc/inittab
sed -i 's/ttyS0/ttyS2/' $path/etc/inittab
elif [ $is_rockchip = true ]; then
sed -i 's/ttyAMA0/tty1/' $path/etc/inittab
sed -i 's/ttyS0/ttyS2/' $path/etc/inittab
fi
if ! grep -q 'ulimit -n' $path/etc/init.d/boot; then
sed -i '/kmodloader/i\\tulimit -n 131072\n' $path/etc/init.d/boot
fi
wireless_mac80211="$path/lib/netifd/wireless/mac80211.sh"
[[ -f "${wireless_mac80211}" ]] && {
cp -f ${wireless_mac80211} ${wireless_mac80211}.bak
sed -i "s|iw |ipconfig |g" ${wireless_mac80211}
}
rm -rf $path/lib/firmware/
cp -rf $fwdriver_path/firmware $path/lib/
chmod 777 $path/lib/firmware/*
chown -R 0:0 $path
}
}
set_rootsize() {
local cnt=0
while [ $cnt -lt 3 ]; do
echo "Your rootfs size" | $lolcat -a -d 5
echo "Input number (256 512 640 768 1024 1536) default ${minsize}" | $lolcat -a -d 5
read -p "" rootsize
if [ ! "$rootsize" ]; then
rootsize=$minsize
break
elif [[ "$rootsize" -ge "256" ]] 2>/dev/null; then
break
else
((cnt++))
echo -e "Salah ulo...\n"
sleep 1s
fi
done
[ $cnt = 3 ] && die "Bye NooB..."
echo -e "${rootsize}\n"
}
extract_kernel() {
choose_rootfs
local path="$rootfs_path/$firmware"
local suffix="${firmware##*.}"
while true; do
case "$suffix" in
xz)
[ -d $tmp ] || mkdir -p $tmp
echo -e "unpack"
xz -dc $path > $tmp/${firmware%.*}
path=$tmp/${firmware%.*}
suffix=${path##*.}
;;
img)
make_losetup $path
break
;;
*)
die "Format error!"
;;
esac
done
local kversion=$(ls $mount/${loop_seq}p2/lib/modules)
local version=$(echo $kversion | grep -oE '^[4-5].[0-9]+.[0-9]+')
echo -e "kernel version => $kversion"
mkdir -p $tmp/$version/{boot,boot/dtb,boot/dtb/amlogic,root/lib}
cp -r $mount/${loop_seq}p1/{config-*,initrd.img-*,System.map-*,uInitrd-*,vmlinuz-*} $tmp/$version/boot
cp -r $mount/${loop_seq}p2/lib/modules $tmp/$version/root/lib/modules/*
(
cd $tmp/$version/root/lib/modules/*/
rm -rf *.ko
find ./ -type f -name '*.ko' -exec ln -s {} ./ \;
)
if [ $is_amlogic = true ]; then
echo -e "package\t\t=> dtb-*.tar.gz"
cd $tmp/$version/boot/dtb/amlogic
tar czf dtb-*.tar.gz * dtb/amlogic
mv dtb-*.tar.gz ../
elif [ $is_allwinner = true ]; then
echo -e "package\t\t=> dtb-*.tar.gz"
cd $tmp/$version/boot/dtb/allwinner
tar czf dtb-*.tar.gz * dtb/allwinner
mv dtb-*.tar.gz ../
elif [ $is_rockchip = true ]; then
echo -e "package\t\t=> dtb-*.tar.gz"
cd $tmp/$version/boot/dtb/rockchip
tar czf dtb-*.tar.gz * dtb/rockchip
mv dtb-*.tar.gz ../
fi
(
echo -e "package\t\t=> boot-$version.tar.gz"
cd $tmp/$version/boot
tar czf boot-$version.tar.gz *
mv boot-$version.tar.gz ../
)
(
echo -e "package\t\t=> modules-$version.tar.gz"
cd $tmp/$version/root
tar czf modules-$version.tar.gz lib/
mv modules-$version.tar.gz ../
)
rm -rf $tmp/$version/{boot,root}
[ -f $tmp/$version/boot-$version.tar.gz ] && [ -f $tmp/$version/modules-$version.tar.gz ] && {
[ -d $kernel_path/$version ] && {
echo && read -p "this version $(echo -e "${version}") Replace? [Y/n] " yn && echo
case "$yn" in
n|N) yn=n ;;
*) yn=y ;;
esac
}
[[ ! "$yn" || "$yn" = "y" ]] && {
[ -d $kernel_path ] || mkdir -p $kernel_path
cp -r $tmp/$version $kernel_path
chown -R 1000:1000 $kernel_path/$version
echo -e "done"
}
}
cleaning
}
mount_image() {
choose_rootfs
local path="$rootfs_path/$firmware"
local suffix="${firmware##*.}"
while true; do
case "$suffix" in
xz)
[ -d $tmp ] || mkdir -p $tmp
echo -e "unpack"
xz -dc $path > $tmp/${firmware%.*}
path=$tmp/${firmware%.*}
suffix=${path##*.}
;;
img)
do_losetup $path
break
;;
*)
die "Format error!"
;;
esac
done
echo -e "success mounted to ${mount:2}/${loop_seq}"
}
usage() {
cat <<-EOF
Usage:
ulo [options]
Options:
-h, --help : Show this Text
-c, --clean : Cleaning old cache
-u, --update : Update Kernel, ROOTFS, and Firmware files from ULO-Repository
(Will Destroy your old Kernel, ROOTFS, and Firmware files!!!)
-k : set the kernel (-k 5.9.16)
-m : set the device (-m s905x2)
-r : set the rootfs files (-r ImmortalWrt-21.02.7-DBAI-armvirt-rootfs.tar.gz)
-s, --size=SIZE : set size (-s 768)
EOF
}
echo -e "
======================================================================
----------------------------------------------------------------------
ULO BUILDER
By DBAI
----------------------------------------------------------------------
======================================================================
" | $lolcat -a -d 5
[ $(id -u) = 0 ] || die "please run this script as root"
check_requirement_files
while [ "$1" ]; do
case "$1" in
-h|--help)
usage
exit
;;
-c|--clean)
cleaning
echo -e "Cleaning done"
exit
;;
-u|--update)
echo -e "Updating Kernel, ROOTFS, and Firmware files from ULO-Repository"
download_requirement_files true
exit
;;
-d|--default)
: ${device:="all"}
: ${firmware:=${rootfs[0]}}
: ${kernel:="all"}
: ${rootsize:=$minsize}
;;
-e)
extract_kernel
exit
;;
-k)
kernel=$2
if [ -f $kernel_path/$kernel/dtb-*.tar.gz ] && \
[ -f $kernel_path/$kernel/boot-*.tar.gz ] && \
[ -f $kernel_path/$kernel/modules-*.tar.gz ]; then
kernels=($kernel)
kernel_checker "${kernels}" true
shift
else
die "invalid kernel $kernel"
fi
;;
-m)
device=$2
if [ -f $device_path/$device/boot-*.tar.gz ]; then
devices=($device)
shift
elif [ "$device" = "all" ]; then
[ ${#devices[*]} = 0 ] && unset device
shift
else
die "invalid device $device"
fi
;;
-r)
rootf=$2
if [ -f $rootfs_path/$rootf ]; then
firmware=($rootf)
echo $firmware > $rootfs_path/rootfs.log
shift
else
die "invalid rootfs $rootf"
fi
;;
--mount)
mount_image
exit
;;
-s|--size)
rootsize=$2
if [[ "$rootsize" -ge "$minsize" ]] 2>/dev/null; then
shift
else
die "invalid rootsize $rootsize"
fi
;;
*)
usage
die "invalid option $1"
;;
esac
shift
done
[ "$device" ] && {
echo -en "device\t\t=> "
echo -e "${devices[@]}" | sed 's/ /, /g'
}
[ "$firmware" ] && {
echo -en "rootfs\t\t=> "
echo -e "${firmware[@]}" | sed 's/ /, /g'
}
[ "$kernel" ] && {
echo -en "kernel\t\t=> "
echo -e "${kernels[@]}" | sed 's/ /, /g'
}
[ "$rootsize" ] && echo -e "rootsize\t=> $rootsize"
[ "$device" ] || [ "$firmware" ] || [ "$kernel" ] || [ "$rootsize" ] && echo
[ "$device" ] || choose_device
[ "$firmware" ] || choose_rootfs
[ "$kernel" ] || choose_kernel
[ "$rootsize" ] || set_rootsize
unpack_openwrt
echo "Building on progress..." | $lolcat -a -d 5
for kernel in ${kernels[*]}; do
for device in ${devices[*]}; do
{
unpack_boot_kernel
make_image
} &
done
done
wait
Total_size="$((256+$rootsize))"
uboot=$(cat ${rootfs_path}/uboot.log | cut -d '/' -f5-6)
echo -e "Build Information :
Device = $device
Kernel = $kernel
Rootfs = $(cat ${rootfs_path}/rootfs.log | cut -d '-' -f1-3)
Size = $Total_size M
U-boot = ${uboot}" | $lolcat -a -d 5
echo " Output file = out/$device/$(cat ${rootfs_path}/rootfs.log | cut -d '-' -f1-3)-$device-k$kernel.img.gz" | $lolcat -a -d 5
cleaning 0
pigz -qf $out/$device/$(cat ${rootfs_path}/rootfs.log | cut -d '-' -f1-3)-$device-k$kernel.img || gzip $out/$device/$(cat ${rootfs_path}/rootfs.log | cut -d '-' -f1-3)-$device-k$kernel.img
tot_time=$(($SECONDS - $start_cnt))
build_time=$(($SECONDS - $start_build))
echo " Build Time = $(($build_time/60))m $(($build_time%60))s" | $lolcat -a -d 5
echo " Total Time = $(($tot_time/60))m $(($tot_time%60))s" | $lolcat -a -d 5
echo -e 'Done...' | $lolcat -a -d 5
echo -e ""
chmod -R 777 $out
rm $rootfs_path/uboot.log
rm $rootfs_path/rootfs.log