-
Notifications
You must be signed in to change notification settings - Fork 24
/
Copy pathconvert_update_script
executable file
·854 lines (650 loc) · 19.5 KB
/
convert_update_script
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
############################################################################
#
# Copyright (c) 2013 - dsixda (dislam@rocketmail.com)
# Copyright (c) 2014 - 越狱 (http://weibo.com/206021119)
#
# Android 厨房是100%免费。此脚本文件仅供个人或学习使用
# by hwh132 越狱 汉化
#
############################################################################
#
# 此脚本有两个可选参数:
#
# $1 = "for_zip" - 使用此选项在 update.zip 建立后
# $2 = yes/no (快速创建模式) - 当前依赖 $1
#
if [ "$1" == "" ]
then
clear
fi
echo
if [ -d WORKING_* ]
then
cd WORKING_*
cd META-INF/com/google/android
else
echo
echo "未发现 Working 文件夹,你需要创建一个!"
exit 0
fi
if [ "$1" == "" ]
then
echo "转换工具: update-script (Amend) 转换为 updater-script (Edify)"
echo "--------------------------------------------------------------------------"
echo
echo "此脚本将会转换 update-script 为 updater-script 并且添加 update-binary 文件。"
echo
echo "此操作项在创建 ROM 时同样会出现, 所以现在并不是必须转换 update-script 脚本。"
echo "厨房不能兼容 updater-scripts 脚本,所以以后只有几个选项是可以选用如果你有一"
echo "个 updater-script 脚本。"
echo
echo "请确认 Working 文件夹 META-INF/com/google/android 下有update-script 脚本。"
echo
echo -n "继续并转换(y/n)? (默认: y): "
read proceed_now
echo
if [ "$proceed_now" == "n" ]
then
cd ../../../../..
exit 0
fi
echo "--------------------------------------------------------------------------"
echo
fi
if [ -e update-script ]
then
if [ -e updater-script ]
then
if [ "$2" == "yes" ]
then
remove_it=y
else
echo "错误: 虽然你有一个 updater-script 脚本, 但你还有一个 update-script 脚本"
echo " 在文件夹中. 删除其中之一."
echo
echo -n "删除 updater-script 脚本然后继续转换(y/n)? (默认: y): "
read remove_it
echo
fi
if [ "$remove_it" != "n" ]
then
rm -vf updater-script
echo
else
cd ../../../../..
exit 0
fi
fi
else
echo "错误: 未发现 update-script 脚本!"
cd ../../../../..
exit 0
fi
cd ../../../../..
if [ "$1" != "for_zip" ]
then
echo "在转换前先检查 update-script 的最终修改 ..."
scripts/fix_pre_build
fi
cd WORKING_*
cd META-INF/com/google/android
echo
echo "--------------------------------------------------------------------------"
echo
echo "转换为 updater-script, 请稍等 ..."
echo
cp update-script updater-script
orig_list=( DATA SYSTEM PRELOAD CACHE SDEXT BOOT SDCARD )
new_list=( userdata system preload cache sdext boot sdcard )
new_list_str="0 1 2 3 4 5 6"
echo "- 初始格式设置 ..."
#
# In Samsung Galaxy S2 and equivalent, convert 'format' back to delete_recursive,
# which was changed earlier
#
cd ../../../../..
scripts/check_galaxy_s_and_s2
ss2=$?
scripts/check_galaxy_s2x
s2x=$?
scripts/check_galaxy_s3_common
s3_common=$?
scripts/check_galaxy_s4_common
s4_common=$?
cd WORKING_*
cd META-INF/com/google/android
if [ "$ss2" == "1" ] || [ "$s2x" == "1" ] || [ "$s3_common" == "1" ] || [ "$s4_common" == "1" ]
then
sed -i -e 's/format /delete_recursive /g' updater-script
fi
# 第三行: 删除在每行上前导和结尾空格
sed -i \
-e ':a;N;$!ba;s/,\n//g' \
-e 's/assert[^\n]*[\n]*//g' \
updater-script
#
# 删除前导/结尾的空格和制表符
# 不确定这需要一个单独的语句从上述工作
#
sed -i -e 's/^[ \t]*//;s/[ \t]*$//g' updater-script
#
# 删除注释行
#
sed -i -e '/^#/d' updater-script
#
# boot.img / radio.img / bootloader.img
#
img_list=( boot radio bootloader )
for (( i = 0 ; i < ${#img_list[@]} ; i++ ))
do
img_name=${img_list[${i}]}
str="write_raw_image PACKAGE:$img_name.img"
#
# Check to see if image file is written in a different manner;
# e.g. in CyanogenMod for Galaxy S they use run_program instead of
# write_raw_image for the boot.img in the updater-script.
#
line_num=`sed -n -e '/'"$str"'/{=;q}' updater-script`
if [ "$line_num" != "" ]
then
str2="package_extract_file PACKAGE:$img_name.img TMP:$img_name.img"
str3="delete TMP:$img_name.img"
line_num3=`sed -n -e '/'"$str3"'/{=;q}' updater-script`
if [ "$line_num3" != "" ]
then
line_num_temp2=$(($line_num3-2))
str_temp=`sed -n -e ''"$line_num_temp2"'p' updater-script`
if [ "$str_temp" == "$str2" ] && [ $line_num3 -lt $line_num ]
then
sed -i -e ''"$line_num"'d' updater-script
continue
fi
fi
fi
sed -i -e 's/'"$str"'.*$/assert(package_extract_file("'"$img_name"'.img", "\/tmp\/'"$img_name"'.img"),\n write_raw_image("\/tmp\/'"$img_name"'.img", "'"$img_name"'"),\n delete("\/tmp\/'"$img_name"'.img"));/g' updater-script
done
#
# radio.img
#
if [ `grep -c write_radio_image updater-script` -gt 0 ]
then
echo "- 抱歉,正在忽略 'write_radio_image' - 无法转换 ..."
sed -i -e 's/write_radio_image PACKAGE:radio.img//g' updater-script
fi
#
# hboot.img
#
if [ `grep -c write_hboot_image updater-script` -gt 0 ]
then
echo "- 抱歉,正在忽略 'write_hboot_image' - 无法转换 ..."
sed -i -e 's/write_hboot_image PACKAGE:hboot.img//g' updater-script
fi
#
# copy_dir
#
echo "- copy_dir ..."
sed -i \
-e 's/copy_dir \(.*\)/package_extract_dir(\"\1\");/g' \
-e 's/\(package_extract_dir.*\) \(.*\)/\1", "\2/g' \
-e 's/\(package_extract_dir.*\)PACKAGE:/\1/g' \
-e 's/\(package_extract_dir.*\)SYSTEM:\([^)]*\))/\1\/system\/\2)/g' \
-e 's/\(package_extract_dir.*\)PRELOAD:\([^)]*\))/\1\/preload\/\2)/g' \
-e 's/\(package_extract_dir.*\)DATA:\([^)]*\))/\1\/data\/\2)/g' \
-e 's/\(package_extract_dir.*\)TMP:\([^)]*\))/\1\/tmp\/\2)/g' \
-e 's/\(package_extract_dir.*\)SDCARD:\([^)]*\))/\1\/sdcard\/\2)/g' \
-e 's/\(package_extract_dir.*\)BOOT:\([^)]*\))/\1\/boot\/\2)/g' \
-e 's/\(package_extract_dir.*\)CACHE:\([^)]*\))/\1\/cache\/\2)/g' \
updater-script
#
# set_perm_recursive
#
echo "- set_perm_recursive ..."
sed -i \
-e 's/set_perm_recursive \(.*\)/set_perm_recursive(\1);/g' \
-e 's/\(set_perm_recursive.*[0-9]*\) \([0-9]*\) \([0-9]*\) \([0-9]*\) /\1, \2, \3, \4, /g' \
-e 's/\(set_perm_recursive.*\)SYSTEM:)/\1\"\/system\")/g' \
-e 's/\(set_perm_recursive.*\)SYSTEM:\([^)]*\))/\1\"\/system\/\2\")/g' \
-e 's/\(set_perm_recursive.*\)DATA:\([^)]*\))/\1\"\/data\/\2\")/g' \
-e 's/\(set_perm_recursive.*\)TMP:\([^)]*\))/\1\"\/tmp\/\2\")/g' \
-e 's/\(set_perm_recursive.*\)CACHE:\([^)]*\))/\1\"\/cache\/\2\")/g' \
-e 's/\(set_perm_recursive.*\) \/\(.*\)\([^)]*\))/\1\ "\/\2\3\")/g' \
updater-script
#
# set_perm
#
echo "- set_perm ..."
sed -i \
-e 's/set_perm \(.*\)/set_perm(\1);/g' \
-e 's/\(set_perm.*[0-9]*\) \([0-9]*\) \([0-9]*\) /\1, \2, \3, /g' \
-e 's/\(set_perm.*\)SYSTEM:\([^)]*\))/\1\"\/system\/\2\")/g' \
-e 's/\(set_perm.*\)DATA:\([^)]*\))/\1\"\/data\/\2\")/g' \
-e 's/\(set_perm.*\)TMP:\([^)]*\))/\1\"\/tmp\/\2\")/g' \
-e 's/\(set_perm.*\)CACHE:\([^)]*\))/\1\"\/cache\/\2\")/g' \
-e 's/\(set_perm.*\) \/\(.*\)\([^)]*\))/\1\ "\/\2\3\")/g' \
updater-script
#
# run_program
#
echo "- run_program ..."
line_num=`sed -n -e '/run_program /{=;q}' updater-script`
while [ "$line_num" != "" ]
do
sed -i \
-e ''$line_num' s/run_program \(.*\)/run_program(\"\1\");/g' \
-e ''$line_num' s/ /", "/g' \
-e ''$line_num' s/PACKAGE:/\//g' \
-e ''$line_num' s/TMP:/\/tmp\//g' \
-e ''$line_num' s/BOOT:/\/boot\//g' \
-e ''$line_num' s/SYSTEM:/\/system\//g' \
-e ''$line_num' s/DATA:/\/data\//g' \
updater-script
# 检查 ROM的ROOT脚本;将它们移到 /tmp;
# 否则为他们将不会运行 !!设置权限之前你从 /tmp 运行它们.
sed -i \
-e ''$line_num' s/run_program("\/\([^\/^\"]*\)"\(.*\)/package_extract_file("\1", "\/tmp\/\1");\nrun_program("\/tmp\/\1"\2/g' \
updater-script
# 添加之前首先检查权限是否已经存在
prog_name=`sed -n -e ''$line_num' s/package_extract_file("[^\"]*",[ ]*"\([^\"]*\)");/\1/p' updater-script`
if [ "$prog_name" != "" ]
then
sed -i \
-e ''$line_num' s/package_extract_file("\([^\"]*\)",[ ]*"\([^\"]*\)");/package_extract_file("\1", "\2");\nset_perm(0, 0, 0777, "\2");/g' \
updater-script
fi
line_num=`sed -n -e '/run_program /{=;q}' updater-script`
done
#
# package_extract_file
#
echo "- package_extract_file ..."
sed -i \
-e 's/package_extract_file PACKAGE:/package_extract_file /g' \
-e 's/package_extract_file \(.*\)/package_extract_file(\"\1\");/g' \
-e 's/\(package_extract_file[^,]*\) \(.*\)/\1", "\2/g' \
-e 's/\(package_extract_file.*\)(\"SYSTEM:\([^)]*\))/\1(\"system\/\2)/g' \
-e 's/\(package_extract_file.*\)(\"DATA:\([^)]*\))/\1(\"data\/\2)/g' \
-e 's/\(package_extract_file.*\)(\"TMP:\([^)]*\))/\1(\"tmp\/\2)/g' \
-e 's/\(package_extract_file.*\)SYSTEM:\([^)]*\))/\1\/system\/\2)/g' \
-e 's/\(package_extract_file.*\)DATA:\([^)]*\))/\1\/data\/\2)/g' \
-e 's/\(package_extract_file.*\)TMP:\([^)]*\))/\1\/tmp\/\2)/g' \
-e 's/\(package_extract_file.*\)CACHE:\([^)]*\))/\1\/cache\/\2)/g' \
updater-script
#
# show_progress
#
echo "- show_progress ..."
sed -i \
-e 's/show_progress \(.*\)/show_progress(\1);/g' \
-e 's/\(show_progress.*\) \(.*\)/\1, \2/g' \
updater-script
#
# set_progress
#
echo "- set_progress ..."
sed -i \
-e 's/set_progress \(.*\)/set_progress(\1);/g' \
updater-script
#
# sleep
#
echo "- sleep ..."
sed -i \
-e 's/sleep \(.*\)/sleep(\1);/g' \
updater-script
#
# delete / delete_recursive
#
echo "- delete/delete_recursive ..."
sed -i \
-e 's/delete \(.*\)/delete(\"\1\");/g' \
-e 's/delete_recursive \(.*\)/delete_recursive(\"\1\");/g' \
-e 's/\(delete.*\)SYSTEM:/\1\/system\//g' \
-e 's/\(delete.*\)PRELOAD:/\1\/preload\//g' \
-e 's/\(delete.*\)DATA:/\1\/data\//g' \
-e 's/\(delete.*\)SDCARD:/\1\/sdcard\//g' \
-e 's/\(delete.*\)CACHE:/\1\/cache\//g' \
-e 's/\(delete.*\)TMP:\([^)]*\))/\1\/tmp\/\2)/g' \
-e 's/\(delete.*\)TMP:/\1\/tmp\//g' \
-e 's/\(delete.*\)SDEXT:/\1\/sdext\//g' \
updater-script
#
# symlink
#
echo "- symlink ..."
sed -i \
-e 's/symlink \(.*\)/symlink(\"\1\");/g' \
-e 's/\(symlink("[^\ ]*\)[ ]*\([^\"]*");\)/\1", "\2/g' \
-e 's/\(symlink.*\)SYSTEM:\(.*\)/\1\/system\/\2/g' \
-e 's/\(symlink.*\)DATA:\(.*\)/\1\/data\/\2/g' \
updater-script
#
# write_raw_image
#
echo "- write_raw_image ..."
sed -i \
-e 's/write_raw_image \(.*\)/write_raw_image(\"\1\");/g' \
-e 's/\(write_raw_image.*"[^,]*\) \(.*\)/\1", "\2/g' \
-e 's/\(write_raw_image.*\)PACKAGE:/\1/g' \
-e 's/\(write_raw_image.*\)BOOT:/\1boot/g' \
-e 's/\(write_raw_image.*\)TMP:\([^)]*\))/\1\/tmp\/\2)/g' \
-e 's/\(write_raw_image.*\)CACHE:\([^)]*\))/\1\/cache\/\2)/g' \
updater-script
#
# format, mount
#
echo "- format and mount ..."
# 在 package_extract_dir 和 delete.* 之前添加'mount'
for new in ${new_list[@]}
do
if [ "$new" == "userdata" ]
then
new2=data
else
if [ "$new" == "sdcard" ]
then
continue
fi
new2=$new
fi
# 发现哪些是第一个
line_num_del=`sed -n -e '/delete.*("\/'"$new2"'.*")/{=;q}' updater-script`
line_num_pkg=`sed -n -e '/package_extract_dir([^,]*, "\/'"$new2"'.*")/{=;q}' updater-script`
use_pkg=0
use_del=0
if [ "$line_num_del" == "" ] && [ "$line_num_pkg" == "" ]
then
continue
fi
if [ "$line_num_del" == "" ]
then
use_pkg=1
else
if [ "$line_num_pkg" == "" ]
then
use_del=1
else
if [ "$line_num_del" -lt "$line_num_pkg" ]
then
use_del=1
else
use_pkg=1
fi
fi
fi
# 替换出现的第一个
if [ $use_del == 1 ]
then
sed -i \
-e '0,/\(delete.*\)("\/'"$new2"'\(.*\)")/s//mount("MTD", "'"$new"'", "\/'"$new2"'");\n\1("\/'"$new2"'\2")/' \
updater-script
else
sed -i \
-e '0,/package_extract_dir(\([^,]*\), "\/'"$new2"'\(.*\)")/s//mount("MTD", "'"$new"'", "\/'"$new2"'");\npackage_extract_dir(\1, "\/'"$new2"'\2")/' \
updater-script
fi
done
for i in $new_list_str
do
orig=${orig_list[${i}]}
new=${new_list[${i}]}
new2=$new
if [ "$new" == "userdata" ]
then
new2=data
fi
#
# 转换 'format' 行
#
sed -i -e 's/format '"$orig"':/format("MTD", "'"$new"'");/g' updater-script
sed -i -e 's/format \(.*\) '"$orig"':/format("\1", "MTD", "'"$new"'");\nmount("\1", "MTD", "'"$new"'", "\/'"$new2"'");/g' updater-script
#
# 我们不想移动/删除 mount boot 分区命令, 由于
# 我们以前使用的 boot.img 命令... 除非我们有 NAND ROM!
#
if [ "$new" == "boot" ]
then
if [ -e ../../../../boot/initrd.gz ] && [ -e ../../../../boot/zImage ]
then
sed -i -e 's/\(format(.*"\/boot");\)/\1\nmount("MTD", "boot", "\/boot");/g' updater-script
grep_mnt=`grep "mount(.* \"/boot\");" updater-script`
if [ "$grep_mnt" == "" ]
then
sed -i -e 's/\(mount.*"\/system");\)/\1\nmount("MTD", "boot", "\/boot");/g' updater-script
fi
fi
continue
fi
grep_mnt=`grep "mount(\"MTD\", \"$new\", \"/$new2\");" updater-script`
#
# 如果发现特殊 mount,然后删除常规 mount
#
grep_fmt2=`grep "format(\"[A-Za-z0-9]*\", \"MTD\", \"$new\");" updater-script`
if [ "$grep_fmt2" != "" ]
then
grep_mnt2=`grep "mount(\"[A-Za-z0-9]*\", \"MTD\", \"$new\", \"/$new2\");" updater-script`
if [ "$grep_mnt" != "" ] && [ "$grep_mnt2" != "" ]
then
sed -i -e '/mount("MTD", "'"$new"'", "\/'"$new2"'");/d' updater-script
fi
fi
#
# 移动关联的 'mount' 行 (如果存在), 这样他会在下面的 'format' 行
#
grep_fmt=`grep "format(\"MTD\", \"$new\");" updater-script`
if [ "$grep_fmt" != "" ]
then
if [ "$grep_mnt" != "" ]
then
# 删除行
sed -i -e '/mount("MTD", "'"$new"'", "\/'"$new2"'");/d' updater-script
# 添加 format 后
sed -i -e 's/format("MTD", "'"$new"'");/format("MTD", "'"$new"'");\nmount("MTD", "'"$new"'", "\/'"$new2"'");/g' updater-script
fi
fi
done
#
# 看看上面没有涉及任何其他 'format' 命令
#
line_num=`sed -n -e '/format /{=;q}' updater-script`
while [ "$line_num" != "" ]
do
sed -i \
-e ''$line_num' s/format \(.*\)/format(\"\1\");/g' \
-e ''$line_num' s/ /", "/g' \
-e ''$line_num' s/format\(.*\));/format\1);\nmount\1, "???");/g' \
updater-script
line_num=`sed -n -e '/format /{=;q}' updater-script`
done
#
# 修复任何不完整的 ("???") mounts, 使用 updater-script.orig 文件
#
if [ -e updater-script.orig ]
then
line_num=`sed -n -e '/^mount(.*???/{=;q}' updater-script`
while [ "$line_num" != "" ]
do
partial_str=`grep "^mount(" updater-script | grep -m 1 ??? | \
sed \
-e 's/"???");//g' \
-e 's/"/\\\"/g' `
# 从原始文件, 得到我们想要的字符串
# 但替换特殊字符如斜杠,防止格式问题
orig_str=`grep -m 1 "$partial_str" updater-script.orig | sed -e 's/\//fwdslash/g'`
if [ "$orig_str" != "" ]
then
sed -i \
-e ''$line_num' s/.*/'"$orig_str"'/g' \
-e ''$line_num' s/fwdslash/\//g' \
updater-script
else
# 我们不想停留在一个无限循环
break
fi
line_num=`sed -n -e '/^mount(.*???/{=;q}' updater-script`
done
fi
#
# unmount
#
echo "- unmount ..."
for new in ${new_list[@]}
do
if [ "$new" == "userdata" ]
then
new2=data
else
new2=$new
fi
grep_mnt=`grep "mount(.* \"/$new\");" updater-script`
if [ "$grep_mnt" != "" ]
then
echo "unmount(\"/$new2\");" >> updater-script
fi
done
#
# 修复 systems 具有不同 mounts, 例如: ext3 类型
# 例如: 'userdata' 被替换为 /dev/block/whatever
#
grep_mnt=`grep "mount(.* \"/data\");" updater-script`
if [ "$grep_mnt" != "" ]
then
echo "unmount(\"/data\");" >> updater-script
fi
echo "- 最终的格式 ..."
sed -i \
-e 's/SYSTEM:/\/system\//g' \
-e 's/TMP:/\/tmp\//g' \
-e 's/DATA:/\/data\//g' \
-e 's/SDCARD:/\/sdcard\//g' \
-e 's/CACHE:/\/cache\//g' \
-e 's/SDEXT:/\/sdext\//g' \
-e 's/BOOT:/\/boot\//g' \
updater-script
#
# 修复包含特殊字符的 run_program 参数
#
sed -i \
-e 's/\[sp\]/ /g' \
-e 's/\[cr\]/\n/g' \
-e 's/\[sc\]/;/g' \
-e 's/\[co\]/,/g' \
updater-script
#
# 检查 shell 脚本是否已取消卸载该分区
#
if [ `grep -c "run_program.*umount" updater-script` ]
then
for new in ${new_list[@]}
do
if [ "$new" == "userdata" ]
then
new=data
fi
grep_mnt=`grep "mount(.* \"/$new\");" updater-script`
grep_umnt=`grep -c "umount /$new" updater-script`
if [ $grep_umnt -gt 0 ] && [ "$grep_mnt" != "" ]
then
sed -i -e '/unmount("\/'"$new"'");/d' updater-script
done
fi
#
# 其他命令
#
sed -i \
-e 's/add_upgrade_property/add_upgrade_property();/g' \
-e 's/install_modem_package/install_modem_package();/g' \
updater-script
sed -i -e 's/write_blob_raw_image PACKAGE:blob/assert(package_extract_file("blob", "\/tmp\/blob"),\n write_blob_raw_image("\/tmp\/blob", "staging"),\n delete("\/tmp\/blob"));/g' updater-script
#
# 清理我的脚本留下任何烂摊子
#
sed -i \
-e 's/\/");/");/g' \
-e 's/; $/;/g' \
updater-script
#
# 删除空行
#
sed -i -e '/^$/d' updater-script
#
# Web 的解决方案 :-)
#
# 从文件中删除重复的、 连续的行 (模拟 "uniq").
# 设置第一行的复制的行数是保留了的, 其余的都将被删除.
#
sed -i -e '$!N; /^\(.*\)\n\1$/!P; D' updater-script
#
# 特定设备的 mount 点
#
cd ../../../../..
scripts/adjust_mnt updater-script
cd WORKING_*
cd META-INF/com/google/android
sed -i -e '/^$/d' updater-script
test_mnt=`grep "^mount(" updater-script`
test_mnt2=`grep "sbin/mount\", \"" updater-script`
test_mnt3=`grep "boot.img\"" updater-script | grep dev`
if [ "$test_mnt" != "" ] || [ "$test_mnt2" != "" ] || [ "$test_mnt3" != "" ]
then
echo
echo
echo "请确认这些设备 mount 语句是否正确:"
echo "--------------------------------------------------------------------------"
if [ "$test_mnt" != "" ]
then
echo $test_mnt
fi
if [ "$test_mnt2" != "" ]
then
echo $test_mnt2
fi
if [ "$test_mnt3" != "" ]
then
echo $test_mnt3
fi
echo "--------------------------------------------------------------------------"
fi
if [ -e updater-script ]
then
cd ../../../../..
scripts/check_which_update_binary
cd WORKING_*
cd META-INF/com/google/android
echo
echo "--------------------------------------------------------------------------"
echo
if [ "$2" != "yes" ]
then
echo "updater-script 脚本已经被创建在工作文件夹中 META-INF/com/google/android 下,"
echo "请检查它并作出必要更改。update-binary 文件同样被添加。"
echo ""
fi
if [ "$1" != "for_zip" ]
then
mv -f update-script update-script.orig
echo "原始 update-script 脚本已被重命名为 update-script.orig - 它将不会包括在"
echo "完成的 ROM 刷机包的 ZIP 文件中。"
else
if [ "$2" == "no" ]
then
echo "不要删除 META-INF/com/google/android 下的任何文件。"
echo
fi
fi
grep_fmt=`grep -n "^format(" updater-script`
grep_mount=`grep -n "^mount(" updater-script`
grep_huh=`grep -n "???" updater-script`
if [ "$grep_huh" != "" ]
then
echo
echo "--------------------------------------------------------------------------"
echo
echo "注意: 请确认修正行代码下的未知参数,对照原始 updater-script 脚本。"
echo
echo $grep_huh | sed -e 's/;[ ]*/;\n/g'
echo
fi
else
echo "错误: updater-script 脚本未创建!"
fi
cd ../../../../..