forked from yeliqin666/TIK3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTIK3.sh
1355 lines (1291 loc) · 35.7 KB
/
TIK3.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
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
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/bin/bash
LOCALDIR="$(cd $(dirname $0); pwd)"
binner=$LOCALDIR/bin
source $binner/settings
tempdir=$LOCALDIR/TEMP
tiklog=$LOCALDIR/TIK3_`date "+%y%m%d"`.log
MBK="$binner/MBK"
platform=$(uname -m)
ebinner="$binner/Linux/$platform"
mkdtimg_tool="$binner/mkdtboimg.py"
dtc="$ebinner/dtc"
yecho(){ echo -e "\033[36m[$(date '+%H:%M:%S')]${1}\033[0m" ; } #显示打印
rmdir(){ if [ -d "$1" ];then rm -rf $1 ;fi ; } #显示打印
ywarn(){ echo -e "\033[31m${1}\033[0m" ; } #显示打印
ysuc(){ echo -e "\033[32m[$(date '+%H:%M:%S')]${1}\033[0m" ; } #显示打印
getinfo(){ export info=$($ebinner/gettype -i $1) ; }
getsize(){ export filesize=$(du -sb $1 | awk '{print $1}' | bc -q) ; }
cleantemp(){ sudo rm -rf $tempdir/* ; }
# 项目菜单
function promenu(){
clear && cd $LOCALDIR
content=$(curl -s https://v1.jinrishici.com/all.json)
shiju=$(echo $content| cut -d \" -f 4 )
from=$(echo $content| cut -d \" -f 8)
author=$(echo $content| cut -d \" -f 12)
echo -e "\033[31m $(cat $binner/banners/$banner) \033[0m"
echo
echo -ne "\033[36m “$shiju”"
echo -e "\033[36m---$author《$from》\033[0m"
echo -e " \n"
echo -e " >\033[33m 项目列表 \033[0m\n"
echo -e "\033[31m [00] 删除项目\033[0m\n"
echo -e " [0] 新建项目\n"
pro=0 && del=0 && chooPro=0
if ls TI_* >/dev/null 2>&1;then
for pros in $(ls -d TI_*/| sed 's/\///g')
do
if [ -d "./$pros" ];then
pro=$((pro+1))
echo -e " [$pro] $pros\n"
eval "pro$pro=$pros"
fi
done
fi
echo -e " --------------------------------------"
echo -e "\033[33m [55] 解压 [66] 退出 [77] 设置 [88] TIK实验室\033[0m"
echo -e ""
echo -e " \n"
read -p " 请输入序号:" op_pro
if [ "$op_pro" == "55" ]; then
unpackrom
elif [ "$op_pro" == "88" ]; then
echo ""
echo "维护中..."
echo ""
sleep $sleeptime
miuiupdate
elif [ "$op_pro" == "00" ]; then
read -p " 请输入你要删除的项目序号:" op_pro
del=1 && Project
elif [ "$op_pro" == "0" ]; then
read -p "请输入项目名称(非中文):TI_" projec
if test -z "$projec";then
ywarn "Input error!"
sleep $sleeptime
promenu
else
project=TI_$projec
if [[ -d "$project" ]]; then
project="$project"-`date "+%m%d%H%M%S"`
ywarn "项目已存在!自动命名为:$project"
sleep $sleeptime
fi
mkdir $project $project/config
menu
fi
elif [ "$op_pro" == "66" ]; then
clear
exit
elif [ "$op_pro" == "77" ]; then
settings
elif [[ $op_pro =~ ^-?[1-9][0-9]*$ ]]; then
chooPro=1 && Project
else
ywarn " Input error!"
sleep $sleeptime
fi
promenu
}
# 主菜单
function menu(){
PROJECT_DIR=$LOCALDIR/$project
clear && cd $PROJECT_DIR
if [[ ! -d "config" ]]; then
ywarn "项目已损坏!"
menu
fi
echo -e "\n"
echo -e " \033[31m>ROM菜单 \033[0m\n"
echo -e " 项目:$project"
if [[ -f $PROJECT_DIR/system/system/build.prop ]]; then
SYSTEM_DIR="$PROJECT_DIR/system/system"
elif [[ -f $PROJECT_DIR/system/build.prop ]]; then
SYSTEM_DIR="$PROJECT_DIR/system"
else
SYSTEM_DIR=0
ywarn " 非完整ROM项目"
fi
echo
echo -e "\033[31m 1> 项目 2> 解包\033[0m\n"
echo -e "\033[32m 3> 打包 4> 插件\033[0m\n"
echo -e "\033[32m 5> 封装\033[0m\n"
echo
read -p " 请输入编号: " op_menu
case $op_menu in
1)
promenu
;;
2)
unpackChoo
;;
3)
packChoo
;;
4)
subbed
;;
5)
# packzip
echo ""
echo "维护中..."
echo ""
sleep $sleeptime
;;
*)
ywarn " Input error!"
sleep $sleeptime
esac
menu
}
function Project(){
eval "project=\$pro$op_pro"
if [[ $project == "" ]];then
ywarn " Input error!"
sleep $sleeptime
promenu
else
if [[ "$del" == "1" ]]; then
read -p " 确认删除?[1/0]" delr
if [ "$delr" == "1" ];then
eval "pro$pro="
rm -fr $project && ysuc " 删除成功!" && sleep $sleeptime
fi
promenu
elif [[ "$chooPro" == "1" ]]; then
cd $project
menu
fi
fi
}
#解包
function unpackChoo(){
clear && cd $PROJECT_DIR
echo -e " \033[31m >分解 \033[0m\n"
filen=0
ywarn " 请将文件放于$project根目录下!"
echo
echo -e " [0]- 分解所有文件\n"
if ls -d *.br >/dev/null 2>&1;then
echo -e "\033[33m [Br]文件\033[0m\n"
for br0 in $(ls *.br)
do
if [ -f "$br0" ] ; then
filen=$((filen+1))
echo -e " [$filen]- $br0\n"
eval "file$filen=$br0"
eval "info$filen=br"
fi
done
fi
if ls -d *.new.dat >/dev/null 2>&1;then
echo -e "\033[33m [Dat]文件\033[0m\n"
for dat0 in $(ls *.new.dat)
do
if [ -f "$dat0" ] ; then
filen=$((filen+1))
echo -e " [$filen]- $dat0\n"
eval "file$filen=$dat0"
eval "info$filen=dat"
fi
done
fi
if ls -d *.new.dat.1 >/dev/null 2>&1;then
for dat10 in $(ls *.dat.1)
do
if [ -f "$dat10" ] ; then
filen=$((filen+1))
echo -e " [$filen]- $dat10 <分段DAT>\n"
eval "file$filen=$dat10"
eval "info$filen=dat.1"
fi
done
fi
if ls -d *.img >/dev/null 2>&1;then
echo -e "\033[33m [Img]文件\033[0m\n"
for img0 in $(ls *.img)
do
if [ -f "$img0" ] ; then
info=$($ebinner/gettype -i $img0)
filen=$((filen+1))
if [ "$info" == "ext" ]; then
echo -e " [$filen]- $img0 <EXT4>\n"
elif [ "$info" == "erofs" ]; then
echo -e " [$filen]- $img0 <EROFS>\n"
elif [ "$info" == "dtbo" ]; then
echo -e " [$filen]- $img0 <DTBO>\n"
elif [ "$info" == "boot" ]; then
echo -e " [$filen]- $img0 <BOOT>\n"
elif [ "$info" == "vendor_boot" ]; then
echo -e " [$filen]- $img0 <VENDOR_BOOT>\n"
elif [ "$info" == "super" ]; then
echo -e " [$filen]- $img0 <SUPER>\n"
else
ywarn " [$filen]- $img0 <UNKNOWN>\n"
fi
eval "file$filen=$img0"
eval "info$filen=img"
if [ "$info" == "sparse" ]; then
echo -e " [$filen]- $img0 <Sparse>\n"
fi
fi
done
fi
if ls -d *.bin >/dev/null 2>&1;then
for bin0 in $(ls *.bin)
do
if [ -f "$bin0" ] ; then
info=$($ebinner/gettype -i $bin0)
if [ "$info" == "payload" ]; then
filen=$((filen+1))
echo -e " [$filen]- $bin0 <BIN>\n"
eval "file$filen=$bin0"
eval "info$filen=payload"
fi
fi
done
fi
if ls -d *.ozip >/dev/null 2>&1;then
echo -e "\033[33m [Ozip]文件\033[0m\n"
for ozip0 in $(ls *.ozip)
do
if [ -f "$ozip0" ] ; then
info=$($ebinner/gettype -i $ozip0)
if [ "$info" == "ozip" ]; then
filen=$((filen+1))
echo -e " [$filen]- $ozip0\n"
eval "file$filen=$ozip0"
eval "info$filen=ozip"
fi
fi
done
fi
if ls -d *.ofp >/dev/null 2>&1;then
echo -e "\033[33m [Ofp]文件\033[0m\n"
for ofp0 in $(ls *.ofp)
do
if [ -f "$ofp0" ] ; then
info=$($ebinner/gettype -i $ofp0)
filen=$((filen+1))
echo -e " [$filen]- $ofp0\n"
eval "file$filen=$ofp0"
eval "info$filen=ofp"
fi
done
fi
if ls -d *.ops >/dev/null 2>&1;then
echo -e "\033[33m [Ops]文件\033[0m\n"
for ops0 in $(ls *.ops)
do
if [ -f "$ops0" ] ; then
filen=$((filen+1))
echo -e " [$filen]- $ops0\n"
eval "file$filen=$ops0"
eval "info$filen=ops"
fi
done
fi
if ls -d *.win >/dev/null 2>&1;then
echo -e "\033[33m [Win]文件\033[0m\n"
for win0 in $(ls *.win)
do
if [ -f "$win0" ] ; then
filen=$((filen+1))
echo -e " [$filen]- $win0 <WIN> \n"
eval "file$filen=$win0"
eval "info$filen=win"
fi
done
fi
if ls -d *.win000 >/dev/null 2>&1;then
for win0000 in $(ls *.win000)
do
if [ -f "$win0000" ] ; then
filen=$((filen+1))
echo -e " [$filen]- $win0000 <分段WIN> \n"
eval "file$filen=$win0000"
eval "info$filen=win000"
fi
done
fi
if ls -d *dtb >/dev/null 2>&1;then
echo -e "\033[33m [Dtb]文件\033[0m\n"
for dtb0 in $(ls)
do
if [ -f "$dtb0" ] ; then
info=$($ebinner/gettype -i $dtb0)
if [ "$info" == "dtb" ]; then
filen=$((filen+1))
echo -e " [$filen]- $dtb0\n"
eval "file$filen=$dtb0"
infile=$PROJECT_DIR/$infile
eval "info$filen=dtb"
fi
fi
done
fi
echo -e ""
echo -e "\033[33m [77] 菜单 [88] 循环解包 [99] 占位\033[0m"
echo -e " --------------------------------------"
read -p " 请输入对应序号:" filed
if [[ "$filed" = "0" ]]; then
echo
for ((filed = 1; filed <= $filen; filed++))
do
eval "infile=\$file$filed"
infile=`realpath $infile`
sf=`basename $infile`
eval "info=\$info$filed"
unpack $infile
done
unpackChoo
elif [[ "$filed" = "88" ]]; then
echo
read -p " 是否解包所有文件? [1/0] " upacall
for ((filed = 1; filed <= $filen; filed++))
do
eval "infile=\$file$filed"
infile=`realpath $infile`
sf=`basename $infile`
eval "info=\$info$filed"
if [ "$upacall" != "1" ];then
read -p " 是否解包$sf?[1/0] " imgcheck </dev/tty
fi
if [[ "$upacall" == "1" ]] || [ "$imgcheck" != "0" ];then
unpack $infile
fi
done
unpackChoo
elif [[ "$filed" = "77" ]]; then
menu
elif [[ "$filed" = "99" ]]; then
echo && menu
elif [[ $filed =~ ^-?[1-9][0-9]*$ ]]; then
if [ $filed -gt $filen ];then
ywarn "Input error!"
sleep $sleeptime && menu
else
eval "infile=\$file$filed"
infile=`realpath $infile`
eval "info=\$info$filed"
unpack $infile
fi
unpackChoo
else
ywarn "Input error!" && menu
sleep $sleeptime
fi
}
function packChoo(){
clear && cd $PROJECT_DIR
echo -e " \033[31m >打包 \033[0m\n"
partn=0
if ls -d config/*_fs_config >/dev/null 2>&1;then
echo -e " [0]- 打包所有镜像\n"
for packs in $(ls config/*_fs_config)
do
sf=$(basename $packs | sed 's/_fs_config//g')
if [ -f "$packs" ] ; then
partn=$((partn+1))
eval "part$partn=$sf"
typeo=$(cat config/${sf}_type.txt)
eval "type$partn=$typeo"
echo -e " [$partn]- $sf <$typeo>\n"
fi
done
fi
if ls -d config/*.img >/dev/null 2>&1;then
for packs in $(ls config/*.img)
do
sf=$(basename $packs | sed 's/.img//g')
if [ -f "$packs" ] ; then
partn=$((partn+1))
echo -e " [$partn]- $sf <bootimg>\n"
eval "part$partn=$sf"
eval "type$partn=bootimg"
fi
done
fi
if ls -d config/dtbinfo_* >/dev/null 2>&1;then
for packs in $(ls config/dtbinfo_*)
do
sf=$(basename $packs | sed 's/dtbinfo_//g')
if [ -f "$packs" ] ; then
partn=$((partn+1))
echo -e " [$partn]- $sf <dtb>\n"
eval "part$partn=$sf"
eval "type$partn=dtb"
fi
done
fi
if ls -d config/dtboinfo_* >/dev/null 2>&1;then
for packs in $(ls config/dtboinfo_*)
do
sf=$(basename $packs | sed 's/dtboinfo_//g')
if [ -f "$packs" ] ; then
partn=$((partn+1))
echo -e " [$partn]- $sf <dtbo>\n"
eval "part$partn=$sf"
eval "type$partn=dtbo"
fi
done
fi
echo -e ""
echo -e "\033[33m [55] 循环打包 [66] 打包Super [77]菜单\033[0m"
echo -e " --------------------------------------"
read -p " 请输入对应序号:" filed
if [[ "$filed" = "0" ]]; then
read -p " 输出文件格式[1]br [2]dat [3]img:" op_menu
case $op_menu in
1)
isbr=1 && isdat=1
;;
2)
isbr=0 && isdat=1
;;
*)
isbr=0 && isdat=0
esac
if [[ "$diyimgtype" == "1" ]];then
echo "手动打包所有分区格式为:[1]ext4 [2]erofs" syscheck
case $syscheck in
2)
imgtype="erofs"
;;
*)
imgtype="ext4"
esac
fi
for ((filed = 1; filed <= $partn; filed++))
do
eval "partname=\$part$filed"
eval "imgtype=\$type$filed"
yecho "打包$partname..."
if [[ "$imgtype" == "bootimg" ]];then
bootpac $partname >> $tiklog
elif [[ "$imgtype" == "dtb" ]];then
makedtb $partname >> $tiklog
elif [[ "$imgtype" == "dtbo" ]];then
makedtbo $partname >> $tiklog
else
inpacker $partname >> $tiklog
fi
done
elif [[ "$filed" = "55" ]]; then
echo
read -p " 是否打包所有镜像? [1/0] " pacall
read -p " 输出所有文件格式[1]br [2]dat [3]img:" op_menu
case $op_menu in
1)
isbr=1 && isdat=1
;;
2)
isbr=0 && isdat=1
;;
*)
isbr=0 && isdat=0
esac
if [[ "$diyimgtype" == "1" ]];then
echo "您要手动打包所有分区格式为:[1]ext4 [2]erofs" syscheck
case $syscheck in
2)
imgtype="erofs"
;;
*)
imgtype="ext4"
esac
fi
for ((filed = 1; filed <= $partn; filed++))
do
eval "partname=\$part$filed"
eval "imgtype=\$type$filed"
if [ "$pacall" != "1" ];then
read -p " 是否打包$partname?[1/0] " imgcheck </dev/tty
fi
if [[ "$pacall" == "1" ]] || [ "$imgcheck" != "0" ];then
yecho "打包$partname..."
if [[ "$imgtype" == "bootimg" ]];then
bootpac $partname >> $tiklog
elif [[ "$imgtype" == "dtb" ]];then
makedtb $partname >> $tiklog
elif [[ "$imgtype" == "dtbo" ]];then
makedtbo $partname >> $tiklog
else
inpacker $partname >> $tiklog
fi
fi
done
elif [[ "$filed" = "66" ]]; then
packsuper
elif [[ "$filed" = "77" ]]; then
menu
elif [[ $filed =~ ^-?[1-9][0-9]*$ ]]; then
if [ $filed -gt $partn ];then
ywarn "Input error!"
sleep $sleeptime && menu
else
eval "partname=\$part$filed"
eval "imgtype=\$type$filed"
if [[ ! "$diyimgtype" == "1" ]] && [[ ! "$imgtype" == "bootimg" ]] && [[ ! "$imgtype" == "dtb" ]] && [[ ! "$imgtype" == "dtbo" ]];then
read -p " 输出文件格式[1]br [2]dat [3]img:" op_menu
case $op_menu in
1)
isbr=1 && isdat=1
;;
2)
isbr=0 && isdat=1
;;
*)
isbr=0 && isdat=0
esac
fi
if [[ "$diyimgtype" == "1" ]] && [[ ! "$imgtype" == "bootimg" ]] && [[ ! "$imgtype" == "dtb" ]] && [[ ! "$imgtype" == "dtbo" ]];then
echo "您要手动打包分区格式为:[1]ext4 [2]erofs" syscheck
case $syscheck in
2)
imgtype="erofs"
;;
*)
imgtype="ext4"
esac
fi
yecho "打包$partname..."
if [[ "$imgtype" == "bootimg" ]];then
bootpac $partname >> $tiklog
elif [[ "$imgtype" == "dtb" ]];then
makedtb $partname >> $tiklog
elif [[ "$imgtype" == "dtbo" ]];then
makedtbo $partname >> $tiklog
else
inpacker $partname >> $tiklog
fi
fi
else
ywarn "Input error!" && menu
sleep $sleeptime
fi
packChoo
}
#
inpacker(){
if [[ ! -d "${PROJECT_DIR}/TI_out" ]]; then
mkdir ${PROJECT_DIR}/TI_out
fi
source $binner/settings && cleantemp
name=${1}
mount_path="/$name"
file_contexts="${PROJECT_DIR}/config/${name}_file_contexts"
fs_config="${PROJECT_DIR}/config/${name}_fs_config"
if [[ "$utcstamp" == "" ]];then
UTC=$(date -u +%s)
fi
out_img="$tempdir/${name}.img"
in_files="${PROJECT_DIR}/${name}"
img_size0=$(cat $PROJECT_DIR/config/${name}_size.txt)
img_size1=`du -sb $name | awk {'print $1'}`
if [[ "$diysize" == "1" ]] && [ "$img_size0" -lt "$img_size1" ] ;then
ywarn "您设置的size过小,将动态调整size!"
img_size0=`echo "$img_size1 + 104857600" |bc`
elif [[ "$diysize" == "1" ]] ;then
img_size0=$img_size0
else
img_size0=`echo "$img_size1 * 1.06" |bc`
fi
img_size=`echo $img_size0 | sed 's/\..*//g'`
size=`echo "$img_size0 / $BLOCKSIZE" |bc`
if [[ "$auto_fsconfig" == "1" ]] ;then
python3 $binner/fspatch.py $in_files $fs_config
fi
echo $img_size >$PROJECT_DIR/config/${name}_size.txt
if [[ -f "dynamic_partitions_op_list" ]]; then
sed -i "s/resize ${name}\s.*/resize ${name} $img_size/" $PROJECT_DIR/dynamic_partitions_op_list
fi
if [[ "$imgtype" == "erofs" ]];then
${su} $ebinner/mkfs.erofs $erofslim --mount-point $mount_path --fs-config-file $fs_config --file-contexts $file_contexts $out_img $in_files
else
if [ "$pack_e2" = "0" ];then
sed -i "/+found/d" $file_contexts
$ebinner/make_ext4fs -J -T $UTC -S $file_contexts -l $img_size -C $fs_config -L $name -a $name $out_img $in_files
else
$ebinner/mke2fs -O ^has_journal -L $name -I 256 -M $mount_path -m 0 -t ext4 -b $BLOCKSIZE $out_img $size
${su} $ebinner/e2fsdroid -e -T $UTC $extrw -C $fs_config -S $file_contexts $rw -f $in_files -a $mount_path $out_img
fi
fi
if [[ "$diysize" == "" ]] ;then
yecho "压缩img中..."
resize2fs -f -M $out_img
fi
if [ "$pack_sparse" = "1" ] || [ "$isdat" = "1" ];then
$ebinner/img2simg $out_img $tempdir/${name}.s.img
mv -f $tempdir/${name}.s.img $tempdir/${name}.img
fi
if [ "$isbr" = "1" ];then
rm -fr TI_out/${sf}.new.dat.br TI_out/${sf}.patch.dat TI_out/${sf}.transfer.list
elif [ "$isdat" = "1" ];then
rm -fr TI_out/${sf}.new.dat TI_out/${sf}.patch.dat TI_out/${sf}.transfer.list
else
mv -f $tempdir/${name}.img $PROJECT_DIR/TI_out/${name}.img
fi
if [ "$isdat" = "1" ];then
rm -fr TI_out/${sf}.new.* TI_out/${sf}.patch.dat TI_out/${sf}.transfer.list
python3 $binner/img2sdat/img2sdat.py $out_img -o $tempdir/ -v 4 -p ${name}
rm -rf $out_img
fi
if [ "$isbr" = "1" ];then
brotli -q $brcom $tempdir/${name}.new.dat -o $PROJECT_DIR/TI_out/${name}.new.dat.br
mv $tempdir/${name}.transfer.list $tempdir/${name}.patch.dat $PROJECT_DIR/TI_out
elif [ "$isdat" = "1" ];then
mv $tempdir/${name}.transfer.list $tempdir/${name}.new.dat $tempdir/${name}.patch.dat $PROJECT_DIR/TI_out
fi
cleantemp
}
#boot打包——magiskboot
bootpac(){
if [[ ! -d "${PROJECT_DIR}/TI_out" ]]; then
mkdir ${PROJECT_DIR}/TI_out
fi
sf=${1}
${su} $MBK/repackimg.sh $PROJECT_DIR/config/$sf.img $PROJECT_DIR/$sf
mv -f $PROJECT_DIR/$sf/new-boot.img $PROJECT_DIR/TI_out/$sf.img
sleep $sleeptime
}
function undtb(){
dtbdir="$PROJECT_DIR/`basename $infile`_dtbs"
rm -rf $dtbdir && mkdir -p $dtbdir/dtb_files $dtbdir/dts_files
extract-dtb $infile -o $dtbdir/dtb_files
yecho "正在反编译dtb..."
for i in `ls $dtbdir/dtb_files/*.dtb`;do
sf=$(basename $i | rev |cut -d'.' -f1 --complement | rev)
$dtc -@ -I dtb -O dts "$dtbdir/dtb_files/$sf.dtb" -o "$dtbdir/dts_files/$sf.dts" > $PROJECT_DIR/config/dtbinfo_`basename $infile`
done
ysuc "反编译完成!"
sleep $sleeptime
if [[ $userid = "root" ]]; then
chmod 777 -R $dtbdir
fi
}
function makedtb(){
sf=$1
dtbdir="$PROJECT_DIR/${sf}_dtbs"
rm -rf $dtbdir/new_dtb_files && mkdir $dtbdir/new_dtb_files
for dts_files in $(ls $dtbdir/dts_files) ;do
new_dtb_files=$(echo "$dts_files" | rev |cut -d'.' -f1 --complement | rev)
yecho "正在回编译$dts_files为$new_dtb_files.dtb"
$dtc -@ -I "dts" -O "dtb" "$dtbdir/dts_files/$dts_files" -o "$dtbdir/new_dtb_files/$new_dtb_files.dtb"
[ $? != 0 ] && ywarn "回编译dtb失败"
done
find $dtbdir/new_dtb_files -name "*.dtb" -exec cat {} > $PROJECT_DIR/TI_out/${sf} \;
ysuc "回编译完成!"
sleep $sleeptime
if [[ $userid = "root" ]]; then
chmod 777 -R $dtbdir
fi
}
function undtbo(){
dtbodir="${sf}_dtbo"
rm -rf $dtbodir
mkdir -p $dtbodir/dtbo_files $dtbodir/dts_files
yecho "正在解压dtbo.img"
python3 $mkdtimg_tool dump "$infile" -b "$dtbodir/dtbo_files/dtbo" > $PROJECT_DIR/config/dtboinfo_$sf
for dtbo_files in $(ls $dtbodir/dtbo_files) ;do
dts_files=$(echo "$dtbo_files" | sed 's/dtbo/dts/g')
yecho "正在反编译$dtbo_files为$dts_files"
$dtc -@ -I "dtb" -O "dts" "$dtbodir/dtbo_files/$dtbo_files" -o "$dtbodir/dts_files/$dts_files" > /dev/null 2>&1
[ $? != 0 ] && ywarn "反编译$dtbo_files失败"
done
ysuc "解压完成!"
if [[ $userid = "root" ]]; then
chmod 777 -R $dtbodir
fi
}
function makedtbo(){
sf=$1
dtbodir="$PROJECT_DIR/${sf}_dtbo"
rm -rf $dtbodir/new_dtbo_files $PROJECT_DIR/TI_out/${sf}.img && mkdir -p $dtbodir/new_dtbo_files
dts_files_name=$(ls $dtbodir/dts_files)
for dts_files in $dts_files_name ;do
new_dtbo_files=$(echo "$dts_files" | sed 's/dts/dtbo/g')
yecho "正在回编译$dts_files为$new_dtbo_files"
$dtc -@ -I "dts" -O "dtb" "$dtbodir/dts_files/$dts_files" -o "$dtbodir/new_dtbo_files/$new_dtbo_files" > /dev/null 2>&1
done
#file_number=$(ls -l $dtbodir/new_dtbo_files | grep "^-" | wc -l)
yecho "正在生成dtbo.img..."
python3 $mkdtimg_tool create "$PROJECT_DIR/TI_out/${sf}.img" --page_size="4096" $dtbodir/new_dtbo_files/*
if [ $? = 0 ];then
ysuc "${sf}.img生成完毕!"
if [[ $userid = "root" ]]; then
chmod 777 -R $dtbodir
fi
else
ywarn "${sf}.img生成失败!"
fi
sleep $sleeptime
}
#文件解包
function unpack(){
sf=$(basename $infile | sed 's/.new.dat//g'| rev |cut -d'.' -f1 --complement | rev )
if [[ ! -d "$PROJECT_DIR/config" ]]; then
mkdir $PROJECT_DIR/config
fi
cleantemp
${su} rmdir ${sf} ${sf}_dtbs ${sf}_dtbo >> $tiklog
rm -rf config/${sf}_file_contexts config/${sf}_fs_config config/${sf}_size.txt config/${sf}_type.txt
yecho "解包$sf中..."
if [ "$info" = "sparse" ];then
yecho "当前sparseimg转换为rimg中..."
$ebinner/simg2img $infile $tempdir/$sf.img >> $tiklog
yecho "解压rimg中..."
infile=$tempdir/${sf}.img && getinfo $infile && imgextra
elif [ "$info" = "dtbo" ];then
undtbo
elif [ "$info" = "br" ];then
${su} brotli -d $infile -o $tempdir/$sf.new.dat > /dev/null
python3 $binner/sdat2img.py $sf.transfer.list $tempdir/$sf.new.dat $tempdir/$sf.img >/dev/null 2>&1
infile=$tempdir/${sf}.img && getinfo $infile && imgextra
elif [ "$info" = "dtb" ];then
undtb
elif [ "$info" = "dat" ];then
python3 $binner/sdat2img.py $sf.transfer.list $sf.new.dat $tempdir/$sf.img >/dev/null 2>&1
infile=$tempdir/${sf}.img && getinfo $infile && imgextra
elif [ "$info" = "img" ];then
getinfo $infile && imgextra
elif [ "$info" = "ofp" ];then
read -p " ROM机型处理器为?[1]高通 [2]MTK " ofpm
if [ "$ofpm" = "1" ]; then
python3 $binner/oppo_decrypt/ofp_qc_decrypt.py $infile $PROJECT_DIR/$sf >> $tiklog
elif [ "$ofpm" = "2" ];then
python3 $binner/oppo_decrypt/ofp_mtk_decrypt.py $infile $PROJECT_DIR/$sf >> $tiklog
fi
elif [ "$info" = "ozip" ];then
python3 $binner/oppo_decrypt/ozipdecrypt.py $infile >> $tiklog
elif [ "$info" = "ops" ];then
python3 $binner/oppo_decrypt/ofp_mtk_decrypt.py $infile $PROJECT_DIR/$sf >> $tiklog
elif [ "$info" = "payload" ];then
yecho "$sf所含分区列表:"
$ebinner/payload-dumper-go -l $infile
read -p "请输入需要解压的分区名(空格隔开)/all[全部] " extp </dev/tty
if [ "$extp" = "all" ];then
$ebinner/payload-dumper-go $infile -o $PROJECT_DIR/payload >> $tiklog
else
if [[ ! -d "payload" ]]; then
mkdir $PROJECT_DIR/payload
fi
for d in $extp
do
$ebinner/payload-dumper-go -p $d $infile -o $PROJECT_DIR/payload >> $tiklog
#mv $PROJECT_DIR/payload${d}/* $PROJECT_DIR/payload && rm -fr payload${d}
done
fi
elif [ "$info" = "win000" ];then
${su} $ebinner/simg2img *${sf}.win* $PROJECT_DIR/${sf}.win >> $tiklog
${su} python3 $binner/imgextractor.py $PROJECT_DIR/${sf}.win $PROJECT_DIR >> $tiklog
elif [ "$info" = "win" ];then
${su} python3 $binner/imgextractor.py $infile $PROJECT_DIR >> $tiklog
elif [ "$info" = "dat.1" ];then
${su} cat ./${sf}.new.dat.{1..999} >> $tempdir/${sf}.new.dat
python3 $binner/sdat2img.py $sf.transfer.list $tempdir/${sf}.new.dat $tempdir/$sf.img >/dev/null 2>&1
infile=$tempdir/${sf}.img && getinfo $infile && imgextra
else
ywarn "未知格式!"
fi
if [[ $userid = "root" ]]; then
${su} chmod 777 -R $sf > /dev/null 2>&1
fi
cleantemp
}
#Img解包
function imgextra(){
if [ "$info" = "ext" ]; then
${su} python3 $binner/imgextractor.py $infile $PROJECT_DIR >> $tiklog
echo "ext4" >>$PROJECT_DIR/config/${sf}_type.txt
if [ ! $? = "0" ];then
ywarn "解压失败"
fi
elif [ "$info" = "erofs" ];then
$ebinner/erofsUnpackRust $infile $PROJECT_DIR >> $tiklog
echo "erofs" >>$PROJECT_DIR/config/${sf}_type.txt
if [ ! $? = "0" ];then
ywarn "解压失败"
fi
elif [ "$info" = "dtbo" ];then
undtbo
elif [ "$info" = "super" ];then
super_size=$(wc -c <$infile | awk '{print $1}' | bc -q)
yecho "super分区大小: $super_size bytes 解压${sf}.img中..."
mkdir super
$ebinner/lpunpack $infile $PROJECT_DIR/super
echo $super_size >> $PROJECT_DIR/config/super_size.txt
if [ ! $? = "0" ];then
ywarn "解压失败"
else
ysuc "super输出至 $TARGETDIR"
if [[ $userid = "root" ]]; then
chmod 777 -R $TARGETDIR
fi
fi
elif [ "$info" = "boot" ] || [ "$sf" == "boot" ] || [ "$sf" == "vendor_boot" ] || [ "$sf" == "recovery" ] ; then
${su} mkdir $sf && cd $sf
${su} bash $MBK/unpackimg.sh $infile >> $PROJECT_DIR/config/$sf.info
${su} cp -f $infile $PROJECT_DIR/config
if [[ $userid = "root" ]]; then
${su} chmod 777 -R ./$sf
fi
cd $PROJECT_DIR
else
ywarn "未知格式!请附带文件提交issue!"
sleep $sleeptime
fi
sleep $sleeptime
}
#手动打包Super
function packsuper(){
clear && rm -f $PROJECT_DIR/super/super.img
if [[ ! -d "super" ]]; then
mkdir $PROJECT_DIR/super
fi
ywarn "请将需要打包的分区镜像放置于$PROJECT_DIR/super中!"
read -p "请输入打包模式:[1]A_only [2]AB [3]V-AB " supertype
if [ "$supertype" = "3" ];then
supertype=VAB
elif [ "$supertype" = "2" ];then
supertype=AB
else
supertype=A_only
fi
read -p "是否打包为sparse镜像?[1/0] " ifsparse
if [[ -f $PROJECT_DIR/config/super_size.txt ]]; then
supersize=$(cat $PROJECT_DIR/config/super_size.txt)
read -p "检测到分解super大小为$supersize,是否按此大小继续打包?[1/0]" iforsize
fi
if [ "$iforsize" == "0" ];then
read -p "请输入super分区大小(字节数,常见9126805504 10200547328 16106127360) " supersize
fi
yecho "打包到super/super.img..."
insuper $PROJECT_DIR/super $PROJECT_DIR/super/super.img
packmenu
}
#打包Super
function insuper(){
Imgdir=$1
outputimg=$2
group_size=0
if [[ $userid = "root" ]]; then
${su} chmod -R 777 $Imgdir
fi
find $Imgdir -name "*" -type f -size 0c | xargs -n 1 rm -f
superpa="--metadata-size 65536 --super-name super "
if [ "$ifsparse" = "1" ];then
superpa+="--sparse "
fi
if [ "$supertype" = "VAB" ];then
superpa+="--virtual-ab "
fi
superpa+="-block-size=$BLOCKSIZE "
superpa+="--metadata-slots $slotnumber "
superpa+="--device super:$supersize "
for imag in $(ls $Imgdir/*.img);do
image=$(echo "$imag" | rev | cut -d"/" -f1 | rev | sed 's/_a.img//g' | sed 's/_b.img//g'| sed 's/.img//g')
if ! echo $superpa | grep "partition "$image":readonly" > /dev/null && ! echo $superpa | grep "partition "$image"_a:readonly" > /dev/null ;then
if [ "$supertype" = "VAB" ] || [ "$supertype" = "AB" ];then
if [[ -f $Imgdir/${image}_a.img ]] && [[ -f $Imgdir/${image}_b.img ]];then
img_sizea=$(wc -c <$Imgdir/${image}_a.img) && img_sizeb=$(wc -c <$Imgdir/${image}_b.img)
group_size=`expr ${img_sizea} + ${img_sizeb} + ${group_size}`
superpa+="--partition "$image"_a:readonly:$img_sizea:main --image "$image"_a=$Imgdir/${image}_a.img --partition "$image"_b:readonly:$img_sizeb:main --image "$image"_b=$Imgdir/${image}_b.img "
else
mv $imag $Imgdir/$image.img > /dev/null 2>&1
img_size=$(wc -c <$Imgdir/$image.img)
group_size=`expr ${img_size} + ${group_size}`
superpa+="--partition "$image"_a:readonly:$img_size:main --image "$image"_a=$Imgdir/$image.img --partition "$image"_b:readonly:0:main "
fi
else
img_size=$(wc -c <$Imgdir/$image.img)
superpa+="--partition "$image":readonly:$img_size:main --image "$image"=$Imgdir/$image.img "
group_size=`expr ${img_size} + ${group_size}`
fi
fi
done
superpa+=" --group main:$group_size "
superpa+="-F --output $outputimg"
if ( $ebinner/lpmake $superpa 2>&1 );then
ysuc "成功创建super.img!"
else
ywarn "创建super.img失败!"
fi
sleep $sleeptime
}
#解压制作
function unpackrom(){
clear && cd $Sourcedir &&zipn=0
echo -e " \033[31m >ROM列表 \033[0m\n"
ywarn " 请将ROM置于$Sourcedir下!"
if ls -d $Sourcedir/*.zip >/dev/null 2>&1;then
cd $Sourcedir
for zip0 in $(ls *.zip)
do
if [ -f "$zip0" ]; then
getsize $zip0 >/dev/null 2>&1
if [ $filesize -gt $plugromlit ];then
zip=$(echo "$zip0" )
zipn=$((zipn+1))
echo -e " [$zipn]- $zip\n"
eval "zip$zipn=$zip"
fi
fi
done
cd $LOCALDIR
else
ywarn " 没有ROM文件!"
fi
echo -e "--------------------------------------------------\n"
echo -e ""
read -p "请输入对应序列号:" zipd
eval "tzip=\$zip$zipd"
if [[ "$tzip" == "" ]];then
ywarn "Input error!" && sleep $sleeptime && promenu
else
zs=$(echo "$tzip" | sed 's/.zip//g')
read -p "请输入项目名称(可留空):" projec
if test -z "$projec";then
project=TI_$zs
else