forked from dsixda/Android-Kitchen
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_rom
More file actions
executable file
·545 lines (428 loc) · 10.8 KB
/
build_rom
File metadata and controls
executable file
·545 lines (428 loc) · 10.8 KB
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
############################################################################
#
# Copyright (c) 2013 - dsixda ([email protected])
#
# Android Kitchen is 100% free. This script file is intended for personal
# and/or educational use only. It may not be duplicated for monetary
# benefit or any other purpose without the permission of the developer.
#
############################################################################
clear
echo
if [ -d WORKING_* ]
then
echo Found working folder
else
echo No working folder found!
exit 0
fi
cd WORKING_*
if [ -e META-INF/com/google/android/update-script ] && [ -e META-INF/com/google/android/updater-script ]
then
echo
echo "Error: Both update-script and updater-script are detected in working folder."
echo " Keep only one of them before building!"
echo
cd ..
exit 0
fi
echo
echo "Cleaning up any leftover files ..."
echo
rm -f *.zip
rm -f testkey.*
rm -f signapk.jar
rm -f signed*.zip
rm -f *smali.jar
#
# Clean up *.DS_Store hidden files
#
find . -name '*.DS_Store' -type f -delete
#
# Clean up stackdump files
#
find . -name sh.exe.stackdump -type f -delete
#
# Clean up temp files left behind by interrupted Amend/Edify conversion scripts
#
if [ -d META-INF/com/google/android ]
then
find META-INF/com/google/android/ -name 'sed*' -type f -delete
fi
#
# Clean up strange temp file issue in root of working folder
#
file_list=`find . -maxdepth 1 -type f`
for filename in $file_list
do
filename=`echo $filename | sed 's/\.\///g'`
header_bytes=`od -A n -H -j 0 -N 4 $filename | sed 's/ //g'`
if [ "$header_bytes" == "04034b50" ]
then
echo -n "Found file in root folder: $filename. Delete (y/n)? (default: y): "
read delete_file
if [ "$delete_file" != "n" ]
then
echo "Deleting $filename"
rm -f $filename
else
echo "Keeping $filename"
fi
fi
done
cd ..
scripts/prompt_nand_type
cd WORKING_*
echo
echo `pwd`
echo
ls -lrt
cd ..
echo
scripts/fix_pre_build
# Check for 'dsixda Null'
cmd_line=`scripts/get_cmdline`
extreme=no
express=no
interactive=no
echo
echo "=========================================================================="
echo
echo "Select a build option:"
echo
echo " 1 = Interactive Mode - recommended for most users"
echo " (Guide me through the build)"
echo
echo " 2 = Lazy Mode - trust the kitchen to do everything without asking"
echo " (Zipalign, Edify, sign ROM, auto-name ZIP)"
echo
echo " 3 = Express Mode - for advanced users"
echo " (Zipalign, Edify, don't sign ROM, auto-name ZIP)"
echo
echo " 4 = Extreme Mode - for advanced users"
echo " (No zipalign, no script conversion, don't sign ROM, auto-name ZIP)"
echo
echo " 5 = Cancel - Don't build now"
echo
echo "=========================================================================="
echo
echo -n "Number (default: 1): "
read build_mode
# Default is 1, so remember to account for Enter key
if [ "$build_mode" == "5" ]
then
echo "Cancelled"
exit 0
elif [ "$build_mode" == "4" ]
then
extreme=yes
elif [ "$build_mode" == "3" ]
then
express=yes
elif [ "$build_mode" == "2" ]
then
lazy=yes
express=yes
else
interactive=yes
fi
if [ "$extreme" == "no" ]
then
scripts/do_zipalign for_build $express
fi
if [ "$?" == "1" ]
then
echo "Cancelling build"
exit 0
fi
cd WORKING_*
#
# Convert update-script (Amend) to updater-script (Edify) for the ZIP file only
#
if [ "$extreme" == "no" ] && [ -e META-INF/com/google/android/update-script ]
then
cd ..
scripts/update_script_should_convert_back
auto_convert="$?"
cd WORKING_*
if [ "$auto_convert" == "1" ] || [ "$express" == "yes" ]
then
convert_it=y
want_file=updater-script
else
echo
echo "--------------------------------------------------------------------------"
echo
echo " update-script detected in ROM"
echo
echo " To ensure compatibility with newer custom recovery images, you have"
echo " the option of using an updater-script (Edify) instead of an"
echo " update-script (Amend) in your ROM's ZIP file."
echo
echo " Your working folder will remain the same and continue to have the "
echo " original update-script."
echo
echo -n " Use updater-script in ROM's ZIP file (y/n)? (default: y): "
read convert_it
fi
if [ "$convert_it" != "n" ]
then
# Remove installbusybox (it's compatible with updater-script, but
# Edify syntax also supports run_program with multiple args)
if [ -e installbusybox ]
then
cd ..
scripts/add_busybox_to_update_script
cd WORKING_*
fi
cd ..
scripts/convert_update_script for_zip $express
# updater-script has been produced
if [ "$?" != "1" ]
then
cd WORKING_*
if [ "$express" == "yes" ]
then
proceed_change=y
else
echo "Proceed with the change (y/n)?"
echo
echo " y = Proceed; updater-script and update-binary will be used in the ZIP"
echo " file; update-script will remain in working folder."
echo " n = Cancel; updater-script and update-binary will be deleted and not"
echo " used."
echo
echo -n "? (default: y): "
read proceed_change
fi
echo
if [ "$proceed_change" != "n" ]
then
if [ -e META-INF/com/google/android/updater-script ]
then
../scripts/convert_to_unix META-INF/com/google/android/updater-script
want_file=updater-script
else
echo "updater-script not found, keeping update-script"
want_file=update-script
fi
else
echo
echo "Cancelling - we'll use the update-script in ZIP file"
want_file=update-script
rm -fv META-INF/com/google/android/updater-script
rm -fv META-INF/com/google/android/update-binary
echo
fi
if [ "$auto_convert" == "1" ] && [ "$proceed_change" == "n" ]
then
echo "You cannot flash a ROM for this device unless it has an updater-script."
echo
cd ..
exit 0
fi
else
echo "Keeping update-script"
cd WORKING_*
want_file=update-script
fi
else
echo
echo
echo "Keeping update-script"
want_file=update-script
fi
echo
else
echo
if [ -e META-INF/com/google/android/update-script ]
then
echo "update-script (Amend) found"
want_file=update-script
fi
if [ -e META-INF/com/google/android/updater-script ]
then
echo "updater-script (Edify) found"
want_file=updater-script
fi
echo
fi
if [ "$want_file" == "updater-script" ]
then
script_not_want=*update-script*
binary_not_want=""
else
# Remove any run_program references to busybox with multiple args
# and replace with the installbusybox script. This is compatible
# with update-script.
if [ -e system/xbin/busybox ]
then
cd ..
scripts/add_busybox_to_update_script amend
cd WORKING_*
fi
script_not_want=*updater-script*
binary_not_want=*update-binary*
fi
if [ "$cmd_line" == "dsixda Null" ]
then
boot_not_want=boot.img
else
boot_not_want=""
fi
#
# Create update.zip
#
echo
echo Making update.zip ...
zip -r -y -q update * -x *.cvs* *.git* *.svn* \
*updater-script.orig* *update-binary.orig* *update-script.orig* \
$script_not_want $binary_not_want $boot_not_want
echo
# Remove updater-script from working folder if update-script already exists
cd META-INF/com/google/android
if [ -e update-script ]
then
rm -f updater-script
rm -f update-binary
fi
cd ../../../..
if [ -e update.zip ]
then
echo update.zip created
echo
else
echo "Error: update.zip not created!"
cd ..
exit 0
fi
#
# Sign update.zip if necessary
#
date_str=`date '+%m%d%y_%H%M%S'`
cd ..
device=`scripts/get_device_name | sed 's/ /_/g'`
cd WORKING_*
sign_update=no
sign_str=unsigned
if [ "$lazy" == "yes" ]
then
do_sign=y
else
do_sign=n
fi
if [ "$interactive" == "yes" ]
then
echo
echo "It is recommended that you sign your ROM."
echo -n "Sign it (y/n)? (default: y): "
read do_sign
fi
if [ "$do_sign" != "n" ]
then
sign_update=yes
sign_str=signed
fi
final_file=$device\_$sign_str\_$date_str.zip
if [ "$sign_update" == "no" ]
then
mv update.zip $final_file
res=$?
else
echo
echo Signing update.zip ...
cp ../tools/signapk_files/testkey.* .
cp ../tools/signapk_files/signapk.jar .
java -jar signapk.jar testkey.x509.pem testkey.pk8 update.zip $final_file
res=$?
rm -f testkey.*
rm -f signapk.jar
rm -f update.zip
fi
if [ -e $final_file ] && [ "$res" == "0" ]
then
#
# Rename zip
#
if [ "$interactive" == "yes" ]
then
cd ..
final_file2=`scripts/set_update_name $final_file`
cd WORKING_*
if [ "$final_file2" != "$final_file" ]
then
mv -fv $final_file $final_file2
final_file=$final_file2
fi
fi
echo
#
# Make output folder
#
if [ -d ../OUTPUT_ZIP ]
then
echo "Found OUTPUT_ZIP folder"
else
echo "Creating folder OUTPUT_ZIP ..."
mkdir ../OUTPUT_ZIP
fi
mv $final_file ../OUTPUT_ZIP/
echo
echo
echo
echo "=========================================================================="
echo
echo "Congratulations ... your ROM is here:"
echo
echo "----> OUTPUT_ZIP/$final_file"
echo
echo "Copy this to your device and flash from custom recovery menu."
echo
echo "=========================================================================="
echo
echo "NOTE 1: Remember to do a factory reset or data/cache wipe if necessary!"
echo
echo "NOTE 2: Always refer to the Android Kitchen FAQ @ xda-developers.com for "
echo "common issues such as:"
echo
echo " - Errors during flashing (e.g. Status 0)"
echo " - Non-booting ROM after flashing ZIP file"
if [ "$sign_update" == "no" ]
then
echo
echo "NOTE 3: You will need to disable signature checks in the recovery"
echo "menu to flash this ROM! If you wish to sign this ROM later, please use"
echo "the Sign ZIP option in the Advanced menu of the kitchen."
fi
echo
echo "Good luck!"
else
echo
echo "Was not able to create $final_file!"
echo
if [ "$sign_update" == "yes" ]
then
if [ `uname | grep Linux` ]
then
echo "Ensure you have a recent version of the Sun Java JDK"
elif [ `uname | grep CYGWIN` ]
then
echo "Ensure you have the Sun Java JDK installed on your PC."
echo
echo "If you already have the JDK, then perhaps the path to java.exe was"
echo "not defined properly:"
echo
echo "e.g. In $HOME/.bash_profile, add to the end:"
echo " PATH=/cygdrive/c/Program\ Files/Java/jdk1.6.0_18/bin:\${PATH}"
echo
echo " The above is an example. Your path may be different."
elif [ `sw_vers | grep -o Mac` ]
then
echo "You may need to install SoyLatte for Mac OS X (to replace the standard "
echo "Java JDK)"
fi
fi
fi
cd ..
# System beep
echo