Symlink some common files to bring the size back down some
[auto-patcher.git] / auto_patcher
blobcad74eaf24402f847fa3f4defed1d943ba6755b2
1 #!/bin/bash
3 # version: beta v2.4.7, patches 2012.011.02.
5 # PDroid created by svyat. Official PDroid thread is
6 # http://forum.xda-developers.com/showthread.php?t=1357056
8 # The Auto-Patcher created by pastime1971 and mateorod
9 # Thread and support for the Auto-Patcher can be found at
10 # http://forum.xda-developers.com/showthread.php?p=27589651#post27589651
12 # ChangeLog
13 # 2012.05.00. (v0.1)
14 # ...........
15 # 2012.05.12. (v0.2) allows user to specify a different version of patches
16 # 2012.05.13. (v0.3.0) force "patch -N", remove temp upon failure, generate log output
17 # 2012.05.13. (v0.3.1) revised the generation of updater-script (SGS2)
18 # 2012.05.15. added AOSP patches
19 # 2012.05.15. added crespo-aosp patches; device-specific patching if patch exists
20 # 2012.05.15. remove restore.zip upon failure
21 # 2012.05.15. (v0.4.1) added CM7 (GB) patches
22 # 2012.05.18. (v0.4.2) added checking for tool commands
23 # 2012.05.21. (v0.4.3) apply device-specific patches only when it is specified
24 # 2012.05.26. added task title to log
25 # 2012.05.31. (v0.4.4) CM9 patches updated, crespo-aosp added
26 # 2012.06.04. (v0.4.5) added checking tools and rom, added aroma installer support
27 # add patch outputs reroute
28 # 2012.06.15. CM9 patches updated
29 # 2012.06.16. (v0.4.6) AOKP patches updated, patch versions restructured
30 # 2012.06.17. (v0.5.0) patcher script reorganized, removed build.prop
31 # 2012.06.17. (v0.6.0) auto patcher script for pdroid and v6 patches
32 # 2012.06.19. (v0.6.1) add patches for CM7.2 Final
33 # 2012.06.20. (v0.6.2) updated CM 7.2 patches
34 # 2012.06.23. (v0.6.3) fix symlinks
35 # 2012.06.26. (v0.6.4) added 0618 patches for cm7 nightlies; removed 0619 cm7.2 final
36 # 2012.06.27. (v0.6.5) added new CM9 patches (20120626)
37 # 2012.06.27. (v0.6.6) added CM7 nightly patches (20120625) (finally!)
38 # 2012.07.02. (v0.7.0) Redid AOSP/AOKP; add Windows support (using Cygwin). Thanks kobik77!
39 # 2012.07.06. (v0.7.1) updated CM9 patches (20120706)
40 # 2012.07.08. (v0.7.2) updated AOKP (20120707) and CM9 (20120708) pdroid patches
41 # 2012.07.11. (v1.0.0) reworked script works on Linux, Mac OSX, and Windows (on Cygwin);
42 # added new ICS/JellyBean support for the new V6-Supercharger
43 # 2012.07.18. (v1.0.1) new CM7/CM9 Pdroid patches (20120718)
44 # 2012.07.23. (v1.0.2) updated CM9 patches (20120723)
45 # 2012.07.23. (v1.0.3) updated CM9 patches (20120724)
46 # 2012.08.06. (v1.5.0) updated smali/baksmali binaries to 1.33
47 # 2012.08.06. Added Pdroid/V6supercharger support for CM10 Jellybean!
48 # 2012.08.06. Improved PDroid stability and efficiency (Thanks CollegeDev)
49 # 2012.08.06. (v1.6.0) added aokp-jb patches for pdroid/v6supercharger, script update
50 # 2012.08.17. (v1.9.5) Added support for pdroid_addon, by CollegeDev.
51 # Added insecure boot.img mod
52 # Added support for aosp-jb (This needs testing, and may not be
53 # a wide patch due to large variation between AOSP roms.
54 # -Please report all experiences!
55 # Updated all v6supercharger patches w/new edits to ProcessList
56 # Major script overhaul in preparation for additional mods!
57 # 2012.08.20. (v1.9.6) Conditional support for Official cm10 and aokp-jb builds
58 # 2012.08.23. (v1.9.7) Final/confirmed pdroid support for Official CM10 and AOKP-JB
59 # 2012.09.04 (v1.9.8) Bundled cygwin-compatible tools (original was corrupt).
60 # For Cygwin, replaced h2b function with simple bash math
61 # conversion (req'd for compat w/ Cygwin tools).
62 # 2012.08.26. (v2.0.0) Added .apk patching
63 # Added 3G Dongle support for Nexus 7
64 # TabletUI support for Nexus 7 (maybe more)
65 # Google Voice support for Nexus 7
66 # mods are 3gdongle, tabletUI, voice, or nexus7suite (for all)
67 # Added provisional file copy menu to widen patching base
68 # 2012.09.11. (v2.0.1) Cygwin support fixes
69 # 2012.09.11. (v2.0.2) Bugfix for 3gdongle (all)
70 # 2012.09.16. (v2.1.0) Significant restructuring of core operations; added edit text file
71 # fix for "method-cap" errors in pdroid.
72 # 2012.09.20. (v2.1.1) Fix for Phone FC's; OSX support finalized; ContentResolver resolved
73 # 2012.09.28. (v2.1.2) Hotfix for failed pdroid patching. Logging improvements.
74 # 2012.10.07. (v2.1.5) Final pdroid support for CM7.2 Official Releases
75 # Added aosp-mod patches for pdroid patching of AOSP kangs
76 # Switched to Chainfire's (f)aapt for speed/space reasons
77 # 2012.10.13. (v2.1.6) New PDroid patches for aokp-jb and cm10 4.1.2
78 # Revert (f)aapt- temporary due to reported issues
79 # 2012.10.15. (v2.17) New (again) CM10 pdroid patches.
80 # Move files to be copied into $p/$R/$B
81 # -This required a bunch of file moving-report broken symlinks.
82 # Some error check on the old RIL delete functions (thanks bundrik)
83 # 2012.10.16. (v2.1.7.5) Fix FC on phone with CM10 pdroid patches
84 # 2012.10.19. (v2.1.9) Testing CM10 support for PDroid Extension by CollegeDev.
85 # 2012.10.22. (v2.2.0) aosp/aokp and cm10 support for pdroid extension by CollegeDev
86 # MAJOR reworking of patches and improved query. only 4 mod types:
87 # cm, aokp, aosp, and pa. See our OP for details.
88 # 2012.10.26. (v2.3.0) Final (LTS) version. Stable for now until upstream breaks any patches
89 # Thanks to KicknGuitar for the OSX testing!
90 # 2012.11.01. (v2.3.1) Fix for pdroid RIL deletion for older roms
91 # Better Build query logic and help messages
92 # 2012.11.02. (v2.3.5) Add Evervolv support for all mods- Thanks to new maintainer poncik!
93 # Fix method cap for pdroid/pd2.0 for AOKP and kangs
94 # 2012.11.06. (v2.4.0) Update pd2.0 patches to latest pd2.0 release- all except Evervolv
95 # add GsmService to smali.txt; improve rom probe
96 # 2012.11.08. (v2.4.2) Add Evervolv support for pd2.0; Device-specific scripts
97 # Will display error if using a mod on an inapplicable rom
98 # 2012.11.09. (v2.4.5) Error catch for random method issues, fix pd2.0 Evervolv and aosp-jb
99 # 2012.11.17. (v2.4.6) Fix pdroid for CM7. FINALLY!.
100 # 2012.11.17. (v2.4.7) Internal debugging improvements
102 # SHELL PROGRAMMING NOTES:
103 # [ -s FILE ]
104 # [[ -n STRING ]] or [[ -z STRING ]]
106 VERSION="v2.4.7"
107 CURRENT_ANDROID="4.2.1"
109 # pass variables to children
110 set -a
112 printusage_help () {
113 usage_help
114 exit
117 usage_help () {
118 # This could REALLY use some better formatting. Even I find it intimidating looking.
119 echo " The Auto-Patcher $VERSION"
120 echo ""
121 echo "usage: $0 [ROMNAME].zip [MODS] [ROMTYPE] [PATCHDATE]"
122 echo ""
123 echo "* [MODS] can be pdroid, pd2.0, v6supercharger, tabletUI, etc..."
124 echo "MODS can be combined by separating them with a comma and NO SPACES!!!"
125 echo ""
126 echo "* [ROMTYPE] can be cm, aokp, aosp or pa [recommended]"
127 echo "* [PATCHDATE] will select older patch versions, e.g 20121030 [optional]"
128 echo ""
129 echo " try \"$0 ROM.ZIP -h\" to see what is available"
130 echo ""
133 usage_more_help () {
134 usage_help
135 echo ""
136 echo "press 'q' to see a list of available patches or CTRL-c to quit the help menu"
139 display_help () {
140 cd patches
141 echo ""
142 echo "AVAILABLE PATCHES"
143 echo ""
144 echo "Note: There are ONLY 4 ROMTYPES: [pa, cm, aokp, and aosp]."
145 echo "The Auto-Patcher will automatically slot if you need aosp-jb or aosp-mod"
146 echo ""
147 echo "*******************************************************************"
148 echo ""
149 echo "Please keep in mind the Android version covers a range {2.3+, 4.0+,...etc.}"
150 echo " is there only for your information and is not needed on the command line"
151 echo ""
152 find -H * -name 2012* | more -d -10
153 echo ""
154 echo "*****************************************************************"
155 echo ""
156 echo "All listed mods are currently supported. So if you only see older patches,"
157 echo "that simply means those early patches are still working for current roms."
158 echo ""
159 cleanup
160 printusage_help
163 debug_help () {
164 # From print_error. For problems decompiling or patching mostly.
165 echo "! please refer to $LOG for any debugging"
166 echo ""
167 echo "! patching failed."
168 echo "! it may be possible to patch $ROM using other patch version"
169 echo ""
170 cleanup
171 printusage_help
174 romtype_help () {
175 # From rom_error (bad romtype) and date_error (patch date w/o specifying romtype)
176 echo ""
177 echo "!!!There are only four supported ROMTYPES: 1) cm 2) aokp 3) aosp 4) pa"
178 echo ""
179 echo "Find out which of the above ROMTYPES your rom is based on and try again!"
180 echo "**********************************************"
181 echo ""
182 cleanup
183 printusage_help
186 cleanup () {
187 [ -d "$TEMP" ] && \rm -rf "$TEMP"
190 garbage () {
191 unset GARBAGE
192 GARBAGE=($(find $@ -name "*.orig")) && rm -rf ${GARBAGE[@]} && echo "GARBAGE= ${GARBAGE[@]}" >> "$LOG"
193 GARBAGE=($(find $@ -name "*.rej")) && rm -rf ${GARBAGE[@]} && echo "GARBAGE= ${GARBAGE[@]}" >> "$LOG"
197 print_error () {
198 # General purpose error. Used for errors in main, as opposed to probe or set-up.
199 echo ""
200 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
201 printtask "!!! error: $@"
202 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
203 echo ""
204 debug_help
207 smali_error () {
208 # Smali binary error. Problem often goes away on second run.
209 echo ""
210 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
211 printtask "!!! error: $@"
212 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
213 echo ""
214 if [[ `grep 'method index is too large' "$LOG"` != "" ]]; then
215 printtask "!!! Problem with method cap !!!"
216 printtask "... attempting fix ..."
217 . patches/common/framework.jar.sh 2>&1 > ${JAR}.log
218 printtask "... rebuild framework.jar ..."
219 java -Xmx512M -jar smali.jar -a $API tmp/${FILE}.out/smali -o tmp/${FILE}.out/classes.dex >> "$LOG" 2>> "$LOG"
220 [ -f tmp/${FILE}.out/classes.dex ] || print_error "Could not resolve method cap issue- please submit log"
221 else
222 printtask "!!! This error is generally due to an unknown bug in the smali binary!"
223 echo "In our experience, it goes away if you run the patcher a second time."
224 echo " Please run the Auto-Patcher with the same command once again."
225 echo ""
226 echo "If after the third attempt the same thing happens,"
227 echo " please upload your logfile to our support thread!"
228 echo ""
229 cleanup
230 exit
234 mismatch_error () {
235 # Function that exposes attempts to apply a mod to an upsupported Android version
236 echo ""
237 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
238 printtask "!!! error: $@"
239 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
240 echo ""
241 cleanup
242 printusage_help
245 date_error () {
246 # Remind users to include a romtype if they are going to specify a patch date
247 echo ""
248 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
249 printtask "!!! error: $@"
250 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
251 echo ""
252 echo "Please put a ROMTYPE before the patch date and run again!!"
253 romtype_help
256 rom_error () {
257 # For when an unsupported romtype is manually entered on the command-line
258 echo ""
259 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
260 printtask "!!! error: $@"
261 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
262 romtype_help
265 misspatch_error () {
266 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
267 printtask "!! error: $@ "
268 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
269 echo ""
270 printtask "!! The Auto-Patcher could not find its patches and/or tools!"
271 echo ""
272 echo "* Did you run ./batch.sh first?"
273 echo ""
274 echo "The patch_patches.tgz and patch_tools.tgz need to be in this directory,"
275 echo " one way or another..."
276 echo ""
277 cleanup
278 printusage_help
281 misstools_error () {
282 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
283 printtask "!! error: $@ "
284 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
285 printtask "Your set-up is missing a dependency."
286 echo "We require JDK, patch and cpio."
287 echo ""
288 echo ""
289 echo "Each distro is different"
290 echo "but you must ensure you have them all installed and try again."
291 echo ""
292 cleanup
293 printusage_help
296 printtask () {
297 echo "" >> "$LOG"
298 echo $@ | tee -a "$LOG"
301 copyfailed () {
302 echo ""
303 printtask "File for which patching failed:"
304 printtask "---------------------------------------------"
305 echo ""
306 printtask "${FAIL##*/}"
307 echo ""
308 echo "---------------------------------------------"
309 echo ""
310 echo "We can try to add a premade copy of those files."
311 echo "This sometimes works."
312 echo ""
313 echo "But IT MAY NOT WORK!!!"
314 echo ""
315 echo ""
316 askconsent && return 0 || return 1
319 askconsent () {
320 sleep 1
321 echo -n "Do you want to proceed ? (YES/no) "
322 read PROCEED
323 echo "askconsent final = ${PROCEED}: for $FAIL" >> "$LOG"
324 case $PROCEED in
325 [Yy] | [Yy][Ee][Ss])
326 return 0; # successful:
327 echo "*** You (or ApG) have elected to use a prepatched copy of $FAIL ***" >> "$LOG"
330 return 1; # error
331 echo "*** You have declined to insert $FAIL by not answering 'yes' at the prompt. ***" >> "$LOG"
333 esac
336 replace_updater () {
338 # Function for devices that use SDcard installs. Also to be tested for CM7
339 # since CM7 seems to use an updater-script that wipes EMMC. Testing
341 UPDIR=META-INF/com/google/android
342 \rm $UPDIR/updater-script
343 \cp patches/common/$UPDIR/updater-script $UPDIR
344 echo "run_program(\"/sbin/busybox\", \"umount\", \"/system\");" >> UPDATE.txt
345 cat UPDATE.txt >> $UPDIR/updater-script
346 echo ""
347 echo "New updater-script being used:" >> "$LOG"
348 echo "-----------------------------" >> "$LOG"
349 cat $UPDIR/updater-script >> "$LOG"
352 abspath () {
353 case `uname -s` in
354 CYGWIN*)
355 echo $(cygpath -ua "$1")
357 Darwin)
358 #[[ $(echo $1 | awk '/^\//') == $1 ]] && echo "$1" || echo "$PWD/$1"
359 [[ ${1:0:1} == "/" ]] && echo "$1" || echo "$PWD/$1"
361 Linux)
362 echo $(readlink -f "$1")
365 if [[ ${1:0:1} == "/" ]]; then
366 echo "$1"
367 elif [[ ${1:0:2} == "./" ]]; then
368 echo "$PWD/${1:2}"
369 else
370 echo "$PWD/$1"
373 esac
376 mods_info () {
377 CEILING=$CURRENT_ANDROID # Default is that everything works...we'll see.
378 case $PID in
379 mods)
380 echo ""
381 echo "The Auto-Patcher $VERSION"
382 echo "*************************************"
383 echo ""
384 echo "The available mods are"
385 echo "**************************************************"
386 echo "* pdroid openpdroid voice v6supercharger *"
387 echo "* voice insecure secure external_internal *"
388 echo "* tabletUI 3gdongle pd2.0 *"
389 echo "**************************************************"
390 echo ""
391 echo "To find out more about any mod, simply enter:"
392 echo " ./auto_patcher -h <MODNAME>"
393 echo ""
394 echo " For usage info: ./auto_patcher -h"
395 echo ""
396 exit
398 auto*)
399 echo ""
400 echo "**************************************"
401 echo "The Auto-Patcher ate a kitten once..."
402 echo "**************************************"
403 printusage_help
405 voice)
406 FLOOR=4.0.0
407 DESC="Use on wifi-only tablets to have the software register as 'voice-enabled'. Allows VOIP like Google Voice to function."
409 v6supercharger)
410 FLOOR=4.0.0
411 CEILING=4.2.1
412 DESC="A memory-management tool. It requires smali edits for Android roms 4.0+."
413 DESC1="The Auto-Patcher applies all 56 edits recommended by the dev."
414 DEV="Zeppelinrox"
415 DEPENDENCY="The V6 Supercharger Script. Get it at http://forum.xda-developers.com/showthread.php?t=991276/"
417 pdroid)
418 FLOOR=2.3.7
419 CEILING=4.1.2
420 DESC="Security Software that blocks permissions w/o causing FC's. No longer under development. Try the open-source expansion of this program, PDroid Manager."
421 DESC1="It is the 'openpdroid' mod within the Auto-Patcher."
422 DEV="Svyat"
423 DEPENDENCY="The Pdroid app. You can get it at http://forum.xda-developers.com/showthread.php?t=1923576"
425 pd2.0)
426 FLOOR=4.1.2
427 CEILING=4.1.2
428 DESC="A closed-source expansion of the PDroid application."
429 DEV="CollegeDev"
430 DEPENDENCY="The PDroid2.0 app available at http://forum.xda-developers.com/showthread.php?t=1923576"
432 openpdroid)
433 FLOOR=4.1.2
434 CEILING=4.2.1
435 DESC="An 100% open-source expansion of the PDroid application/framework."
436 DEV="FFU5y/Community"
437 DEPENDENCY="The PDroidManager app available from Google Play or http://forum.xda-developers.com/showthread.php?t=1994860"
439 external_internal)
440 FLOOR=2.3.3
441 DESC="Swap internal and external storage."
443 insecure)
444 FLOOR=2.3.3
445 DESC="Make any boot.img insecure and allow remount as well as adb push/pull of system files. True root."
447 secure)
448 FLOOR=2.3.3
449 DESC="Make any boot.img secure."
451 3gdongle)
452 FLOOR=4.1.0
453 CEILING=4.2.1
454 DESC="Allows 3gdongles to work on wifi tablets w/o 3rd party applications."
455 DEV="trevd"
456 DEPENDENCY="None, but read the troubleshooting guide at http://forum.xda-developers.com/showthread.php?t=1798631"
458 tabletUI)
459 FLOOR=4.1.0
460 CEILING=4.1.2
461 DESC="Changes the user interface of Phones and Phablets to the popular Tablet UI."
462 DEV="barmullio"
464 esac
465 # strip decimals from android version (i.e. 2.3.7 becomes 237) so we can do math
466 NVID=${VID//[.]/}
467 COMPATF=${FLOOR//[.]/}
468 COMPATC=${CEILING//[.]/}
471 apk_check () {
472 if [ -f patches/$P/$A/$R/$B/$FILE ]; then
473 echo "... Patching $APK failed, but we will copy over a prepatched file ..."
474 \cp -av patches/$P/$A/$R/$B/$FILE $FILE >> "$LOG"
475 else
476 print_error "failed patching $APK!!!"
479 compat_check () {
480 for P in ${PID[@]}; do
481 mods_info
482 if [[ "$NVID" -lt "$COMPAT" ]]; then
483 mismatch_error "Your Android $VID rom is too old! The minimum for $P is Android $FLOOR!"
485 if [[ "$NVID" -gt "$COMPATC" ]]; then
486 mismatch_error "Sorry, $P has not been made available for Android $VID yet!"
488 done
490 extpath () {
491 case `uname -s` in
492 CYGWIN*)
493 echo $(cygpath -da "$1")
496 echo $(abspath "$1")
498 esac
501 #contains () { for e in "${@:2}"; do [[ "$e" = "$1" ]] && return 0; done; return 1; }
503 parse () { echo "${1%%_*}"; }
505 getbuildprop () {
506 if [ -f system/build.prop ]; then
507 result=(`grep $1 system/build.prop | tr -d '\r' | tr '=' ' '`)
508 echo "${result[1]}"
509 else
510 echo ""
515 aosp_mod_check() {
516 jar -xvf "$ROMX" system/framework/framework2.jar >> $LOG
517 if [ -s system/framework/framework2.jar ]; then
518 ever_check
519 else
520 AOSP=aosp-jb
524 ever_check() {
525 MID=$(getbuildprop ro.build.romversion)
526 if [[ "$MID" == "Evervolv"* ]]; then
527 AOSP=aosp-ever
528 else
529 MID=$(getbuildprop ro.build.display.id)
530 if [[ "$MID" == "ev"* ]]; then
531 AOSP=aosp-ever
532 else
533 AOSP=aosp-mod
538 pa_check() {
539 CMID=$(getbuildprop ro.modversion)
540 PAID=$(getbuildprop ro.pa.version)
541 MID=$(getbuildprop ro.build.display.id)
542 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
543 DID=$(getbuildprop ro.product.device)
544 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
545 if [[ -n $PAID ]]; then
546 RID=pa
547 else
548 case $CMID in
549 [Pp][Aa]*)
550 RID=pa;
553 RID=cm;
555 esac
559 proberom () {
560 VID=$(getbuildprop ro.build.version.release)
561 ANDR="${VID%.*}" # Cut flavor to 1 significant digit to cover specific range or release.
562 if [ "$ANDR" == "2.3" ]; then
563 FLAVR=gingerbread
564 API=10
565 RID=cm;
566 elif [ "$ANDR" == "4.0" ]; then
567 FLAVR=ics
568 API=15
569 MID=$(getbuildprop ro.rommanager.developerid)
570 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.modversion))
571 DID=$(getbuildprop ro.product.device)
572 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
574 case "$MID" in
575 pa|cm9|cm|cyanogenmod*)
576 RID=cm;
578 aokp|teamkang)
579 RID=aokp;
581 aosp*)
582 RID=aosp;
585 echo "!!! $MID is not supported yet, trying generic latest !!!"
587 esac
588 elif [ "$ANDR" == "4.1" ]; then
589 FLAVR=jellybean
590 API=16
591 CMID=$(getbuildprop ro.cm.version)
592 if [[ -n $CMID ]]; then
593 pa_check
594 else
595 MID=$(getbuildprop ro.build.display.id)
596 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
597 DID=$(getbuildprop ro.product.device)
598 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
599 case "$MID" in
600 cm10|cm*|cyanogenmod*)
601 RID=cm;
603 aokp*|teamkang)
604 RID=aokp;
606 pa*)
607 RID=pa;
609 ev*)
610 RID=aosp-ever;
613 RID=`aosp_mod_check`;
615 esac
617 elif [ "$ANDR" == "4.2" ]; then
618 FLAVR=jellybean
619 API=17
620 CMID=$(getbuildprop ro.cm.version)
621 MID=$(getbuildprop ro.build.display.id)
622 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
623 DID=$(getbuildprop ro.product.device)
624 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
626 case "$MID" in
627 cm10|cm*|cyanogenmod*)
628 RID=cm;
630 aokp*|teamkang)
631 RID=aokp;
633 pa*) # Defaults to cm for now, since there is a chance we can patch forks
634 RID=cm;
637 RID=aosp;
639 esac
641 else
642 print_error "unknown ROM version $VID"
644 echo "... result of ROM check: version= $VID rom= $RID ..."
647 # Advanced build date query
648 # This should set the patch date automatically.
650 buildquery() {
651 UTC=$(getbuildprop ro.build.date.utc)
653 # Difference in how OS X and Linux/Cygwin handles 'date' utility
654 case `uname -s` in
655 [Dd]arwin)
656 BDID=`date -r $UTC +%Y%m%d`
657 echo "#### Darwin Build Query used ####" >> "$LOG"
660 BDID=`date -d "1970-01-01 UTC $UTC seconds" +"%Y%m%d"`
661 echo "#### Standard Build Query ####" >> "$LOG"
663 esac
665 # If patch date is specified on CLI, use that patch date
666 if [ $# -gt 3 ]; then
667 BID=${4//,/ };
669 # Multiple mods all default to latest- this isn't ideal. We should institute $BID array
670 # In python, we would use dictionary. Not sure about best for shell. A GUI would fix.
671 elif [[ ${#PID[@]} -gt 1 ]];then
672 BID=latest;
673 else
674 case $ANDR in
675 gingerbread)
676 # CM7 roms do not have UTC time stamp- so no build query.
677 BID=latest;
678 echo "*** CM7 roms default to latest patches. If using an older rom ***"
679 echo "*** specify patch date on command line. Use -h to see available patches ***"
682 for P in ${PID[@]}; do
683 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
684 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
685 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
686 PAR=patches/$P/$A/$R
687 PARB=patches/$P/$A/$R/$B
688 DATES=`ls patches/$P/$A/$R/ | grep '201*'`
689 # Intialize variable - High so as to determine lowest in first loop.
690 BID=20201231
691 # find earliest available patch date
692 for i in $DATES; do
693 if [[ $i -lt $BID ]]; then
694 BID=$i
696 done
697 # Check if earliest patches are from before build date. Else use earliest
699 # If older than earliest patch set, then find best match
700 if [[ $(($BID-$BDID)) -lt 0 ]]; then
701 for g in $DATES; do
702 # use any patch that matches $UTC
703 if [[ $(($BDID-$g)) -eq 0 ]]; then
704 BID=$g
705 break
706 # Set highest $BID w/o going over $UTC
707 elif [[ $(($BDID-$g)) -gt 0 ]] && [[ $g -gt $BID ]]; then
708 BID=$g
710 done
712 echo "... $PID patch date has been set to: $BID..."
713 B=$BID
714 done
716 esac
720 proberil () {
721 RIL=$(getbuildprop ro.telephony.ril_class)
722 [[ -n $RIL ]] && printtask "... result of ROM check: RIL= $RIL"
725 rominfo () {
726 echo "# VER= $VERSION" >> "$LOG"
727 echo "# OS= $OSTYPE ${BIT}bit" >> "$LOG"
728 echo "# VID= $VID" >> "$LOG"
729 echo "# PID= ${PID[@]}" >> "$LOG"
730 echo "# MID= $MID" >> "$LOG"
731 echo "# RID= $RID" >> "$LOG"
732 echo "# ANDR= $ANDR" >> "$LOG"
733 echo "# BDID= $BDID" >> "$LOG"
734 echo "# DID= $DID" >> "$LOG"
735 echo "# BID= $BID" >> "$LOG"
739 if [[ $1 == -h ]]; then
740 if [ $# -gt 1 ]; then
741 PID=$2
742 mods_info
743 echo ""
744 echo "The Auto-Patcher $VERSION by Mateorod and Pastime1971"
745 echo "*************************************************"
746 echo ""
747 echo "Mod Name: $PID"
748 echo ""
749 echo " $DESC"
750 echo "$DESC1"
751 echo ""
752 echo "Developer: $DEV"
753 echo "Dependancies: $DEPENDENCY"
754 echo ""
755 echo "Works on Android ROMs from $FLOOR to $CEILING"
756 echo
757 exit
761 [[ $# -lt 1 || -z $1 ]] && printusage_help
762 [[ $1 == "-h" ]] && usage_more_help | less && display_help
764 echo ""
765 echo "The Auto-Patcher $VERSION"
766 echo ""
767 # by pastime1971 and mateorod
769 ROOT=$(abspath `dirname "$0"`)
770 TOOL="$ROOT/patch_tools.tgz"
771 PTCH="$ROOT/patch_patches.tgz"
772 ROM=$(abspath "$1")
773 ROMX=$(extpath "$1")
775 if [[ $OSTYPE == "cygwin" ]]; then
776 EXE=".exe"
777 PGFORM="0x"
780 DATE=`date +%Y%m%d%H%M%S`
781 TEMP=$(abspath ./tmp$DATE)
782 LOG=$(abspath ./log$DATE.txt)
783 #echo $ROOT $TOOL $ROM $TEMP "$LOG"
784 echo "ROOT= $ROOT" >> "$LOG"
785 echo "TOOL= $TOOL" >> "$LOG"
786 echo "ROM= $ROM" >> "$LOG"
787 echo "ROMX= $ROMX" >> "$LOG"
789 \rm -f restore.zip update.zip
791 CHK=$(getconf LONG_BIT)
792 if [[ $CHK = "64" ]]; then
793 BIT=64
794 else [[ $BIT = "32" ]];
795 BIT=32
799 printtask "### verify tools ###"
800 which patch >> "$LOG" || misstools_error "Missing \"patch diff command\""
801 which tar >> "$LOG" || misstools_error "Missing \"tar archive command\""
802 which jar >> "$LOG" || misstools_error "Missing \"jar (JDK)\""
803 which java >> "$LOG" || misstools_error "Missing \"java (JRE)\""
804 which cpio >> "$LOG" || misstools_error "Missing \"cpio archive command\""
805 [ -f "$TOOL" ] || misspatch_error "patch tool is missing"
806 [ -f "$PTCH" ] || misspatch_error "patch patches are missing"
807 printtask "### verify ROM ###"
808 [ -f "$ROM" ] || print_error "Cannot find $ROM"
809 echo "### running $0 $@" >> "$LOG"
810 mkdir "$TEMP"
811 cd "$TEMP"
813 PATH="$TEMP:$PATH"
814 export PATH
815 echo "PATH= $PATH" >> "$LOG"
817 printtask "### unzip patch tools ###"
818 tar xzf "$TOOL" > /dev/null || print_error "failed extracting tools !!!"
820 # Get OS specific tools
821 case `uname -s` in
822 CYGWIN*)
823 \mv cygwin/aapt.exe .
824 \mv cygwin/*.exe boot/
825 \rm -rf cygwin # why? If you want to we can keep/add it to mac/linux, though.
827 [Dd]arwin)
828 \mv mac/aapt .
830 [Ll]inux)
831 \mv linux/aapt .
834 \mv linux/aapt .
836 esac
837 # Ensure aapt permissions - possibly to one day be expanded to all tools in a function.
838 chmod a+x aapt$EXE
840 printtask "### unzip patch patches ###"
841 tar xzf "$PTCH" > /dev/null || print_error "failed extracting patches !!!"
843 # we need build.prop for both RIL probing and ROM probing
844 jar -xvf "$ROMX" system/build.prop 2>> "$LOG" || print_error "failed extracting build.prop from $ROMX !!!"
846 # rom + ril type
847 proberil
848 printtask "### probe rom type ###"
849 proberom
851 # rom type
852 if [ $# -gt 1 ]; then
853 PIT=$2
854 if [[ "$PIT" = "-h" ]]; then
855 display_help
858 if [ $# -gt 2 ]; then
859 RID=$3
860 case "$RID" in
861 cm10|cm*|cyanogenmod*)
863 aokp*|teamkang)
864 RID=aokp;
866 pa*)
867 RID=pa;
869 aosp-ever)
870 RID=aosp-ever;
872 aosp*)
873 case "ANDR" in
874 4.1)
875 RID=`aosp_mod_check`;
878 RID=aosp
880 esac
882 201*)
883 date_error "You must specify ROMTYPE if designating a patch date!!"
886 rom_error "$RID is not a valid ROMTYPE!!"
888 esac
889 echo "... Using $RID patches ..."
890 else
891 echo "... Using results of ROM check ..."
894 # patch type
895 if [ $# -gt 1 ]; then
896 PIL=${2//,/ }
897 else
898 #PIL=`ls patches/`
899 PIL="pdroid v6supercharger"
900 echo "No mods selected. Defaulting to the v6 and Pdroid, just because we can."
902 # a hack to make sure pdroid is the first mod
903 [[ ${PIL[@]} == "pdroid" ]] && PID=(pdroid)
904 for P in ${PIL[@]}; do
905 [[ ${PID[@]} =~ $P ]] || PID=(${PID[@]} $P)
906 done
908 # Check to make sure selected roms are available for the Android version of patched ROM
909 compat_check
911 # Build date
912 if [ $# -gt 3 ]; then
913 BID=$4
914 # even here, we should try and create a function that matches as close to the above
915 # BID as possible. Now, a bad match (user error) defaults to latest
916 echo "... $PID patch date set manually to $BID ..."
917 else
918 buildquery
921 # echo ROM info
922 rominfo
924 # I think I finally may have rendered this VERY long if statement obsolete...CHECK!
925 if [[ ( "$PID" == "-h" || "$RID" == "-h" || "$BID" == "-h" ) ]]; then
926 display_help
927 else
929 #Begin cycle
931 for P in ${PID[@]}; do
932 [ -d patches/$P ] || print_error "$P is not available"
933 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
934 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
935 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
937 unset FILES
938 [ -f patches/$P/files.txt ] && FILES=$(cat patches/$P/files.txt)
939 [ -f patches/$P/$A/files.txt ] && FILES=$(cat patches/$P/$A/files.txt)
940 [ -f patches/$P/$A/$R/files.txt ] && FILES=$(cat patches/$P/$A/$R/files.txt)
941 [ -f patches/$P/$A/$R/$B/files.txt ] && FILES=$(cat patches/$P/$A/$R/$B/files.txt)
942 for FILE in ${FILES[@]}; do
943 case "$FILE" in
944 +system/*)
945 [[ ${CID[@]} =~ ${FILE:1} ]] && print_error "${FILE:1} is already being copied" || CID=(${CID[@]} ${FILE:1})
947 -system/*)
948 [[ ${EID[@]} =~ ${FILE:1} ]] || EID=(${EID[@]} ${FILE:1})
950 system/*.jar)
951 [[ ${JID[@]} =~ $FILE ]] || JID=(${JID[@]} $FILE)
952 echo "set_perm(0, 0, 0644, \"/$FILE\");" >> UPDATE.txt
954 system/*.apk)
955 [[ ${AID[@]} =~ $FILE ]] || AID=(${AID[@]} $FILE)
956 echo "set_perm(0, 0, 0644, \"/$FILE\");" >> UPDATE.txt
958 *.img)
959 [[ ${IID[@]} =~ $FILE ]] || IID=(${IID[@]} $FILE)
961 system/*)
962 [[ ${TID[@]} =~ $FILE ]] || TID=(${TID[@]} $FILE)
964 esac
965 done
966 done
967 echo "### DELETE FILES= ${EID[@]}" >> "$LOG"
968 echo "### COPY FILES= ${CID[@]}" >> "$LOG"
969 echo "### JAR FILES= ${JID[@]}" >> "$LOG"
970 echo "### APK FILES= ${AID[@]}" >> "$LOG"
971 echo "### IMG FILES= ${IID[@]}" >> "$LOG"
972 echo "### TXT FILES= ${TID[@]}" >> "$LOG"
974 printtask "### unzip rom ###"
975 # extract system files
976 jar -xvf "$ROMX" ${JID[@]} ${AID[@]} ${IID[@]} ${TID[@]} 2>> "$LOG" || print_error "failed extracting ${JID[@]} ${AID[@]} ${IID[@]} from $ROMX !!!"
978 printtask "### create updater script ###"
979 jar -xvf "$ROMX" META-INF/com/google/android/updater-script META-INF/com/google/android/update-binary
980 jar -xvf "$ROMX" META-INF/com/google/android/update-binary-installer 1> /dev/null 2> /dev/null
981 if [ -f META-INF/com/google/android/update-binary-installer ]; then
982 printtask "... using Aroma installer ..."
983 \mv META-INF/com/google/android/update-binary-installer META-INF/com/google/android/update-binary
984 else
985 printtask "... using Clockworkmod installer ..."
987 if [ -f META-INF/com/google/android/update-binary ]; then
988 cat META-INF/com/google/android/updater-script | grep ^mount | grep "/system" | head -n 1 > updater-script
989 [ -s updater-script ] || echo "run_program(\"/sbin/busybox\", \"mount\", \"/system\");" > updater-script
990 for FILE in ${EID[@]}; do
991 # restore the original
992 jar -xvf "$ROMX" $FILE 2> /dev/null || printtask "!!! warning $FILE cannot be restored !!!"
993 done
994 for FILE in ${CID[@]}; do
995 # replace with the original or delete it
996 jar -xvf "$ROMX" $FILE 2> /dev/null || echo "delete(\"/$FILE\");" >> updater-script
997 done
998 echo "package_extract_dir(\"system\", \"/system\");" >> updater-script
999 # add permission management
1000 cat META-INF/com/google/android/updater-script | grep set_perm | grep "/system" >> updater-script
1001 # TODO: remove if we don't need it any more
1002 for P in ${PID[@]}; do
1003 if [ -s patches/$P/$A/set_perm.txt ]; then
1004 echo "...setting permissions..."
1005 cat patches/$P/$A/set_perm.txt >> updater-script
1007 done
1008 cat META-INF/com/google/android/updater-script | grep ^unmount | grep "/system" | head -n 1 >> updater-script
1009 [[ ${IID[@]} =~ boot.img ]] && cat META-INF/com/google/android/updater-script | grep "boot.img" >> updater-script
1010 cat updater-script > META-INF/com/google/android/updater-script
1011 echo "# generated updater-script" >> "$LOG"
1012 cat updater-script >> "$LOG"
1013 else
1014 # this is not enough any more
1015 jar -xvf update-template.zip META-INF/com/google/android/update-binary META-INF/com/google/android/updater-script
1018 printtask "### create restore.zip ###"
1019 jar -cvf tmp.zip ${JID[@]} ${AID[@]} ${IID[@]} META-INF > /dev/null 2>> "$LOG"
1020 java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip signed.zip 2>> "$LOG"
1021 \mv signed.zip restore.zip
1022 \rm -f tmp.zip
1024 printtask "### decompile system files ###"
1026 # decompile system files
1027 for FILE in ${JID[@]}; do
1028 JAR=${FILE##*/}
1029 printtask "... decompile $JAR ..."
1030 java -jar baksmali.jar -b -a $API -o tmp/${FILE}.out/smali ${FILE} >> "$LOG" 2>> "$LOG"
1031 if [ $FILE == "system/framework/framework.jar" ]; then
1032 printtask "... extract preloaded-classes ..."
1033 jar -xvf ${FILE} preloaded-classes >> "$LOG" 2>> "$LOG"
1034 \mv preloaded-classes tmp/${FILE}.out/
1036 done
1038 # Pull framework-files for APK...
1039 if [ ${#AID[@]} -gt 0 ]; then
1040 jar -xvf "$ROMX" system/framework/framework-res.apk >> "$LOG"
1041 printtask "... installing framework files ..."
1042 java -jar apktool.jar if system/framework/framework-res.apk
1043 # Decompile APKs
1044 for FILE in ${AID[@]}; do
1045 APK=${FILE##*/}
1046 if [ -f $FILE ]; then
1047 printtask "... decompile $APK ..."
1048 java -jar apktool.jar d -f $FILE tmp/$FILE.out
1050 done
1053 # Unpack image files {boot.img only so far...}
1054 for FILE in ${IID[@]}; do
1055 printtask "### unpacking $FILE ###"
1056 case "$FILE" in
1057 boot.img)
1058 if [ -f boot.img ]; then
1059 cd boot
1060 ./unpackbootimg$EXE -i ../boot.img >> "$LOG" 2>> "$LOG"
1061 mkdir ramdisk
1062 cd ramdisk
1063 gzip -dc ../boot.img-ramdisk.gz | cpio -i >> "$LOG" 2>> "$LOG"
1064 cd ../../
1065 else
1066 print_error "A mod needs to patch boot.img! This rom does not contains boot.img."
1070 print_error "cannot process $FILE"
1072 esac
1073 done
1075 # apply system modification
1077 for P in ${PID[@]}; do
1078 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1079 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1080 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1081 PAR=patches/$P/$A/$R
1082 PARB=patches/$P/$A/$R/$B
1084 unset FILES COPY DELS JARS APKS IMGS TXTS
1085 [ -f patches/$P/files.txt ] && FILES=$(cat patches/$P/files.txt)
1086 [ -f patches/$P/$A/files.txt ] && FILES=$(cat patches/$P/$A/files.txt)
1087 [ -f patches/$P/$A/$R/files.txt ] && FILES=$(cat patches/$P/$A/$R/files.txt)
1088 [ -f patches/$P/$A/$R/$B/files.txt ] && FILES=$(cat patches/$P/$A/$R/$B/files.txt)
1089 for FILE in ${FILES[@]}; do
1090 case $FILE in
1091 +system/*)
1092 COPY=(${COPY[@]} ${FILE:1})
1094 -system/*)
1095 DELS=(${DELS[@]} ${FILE:1})
1097 system/*.jar)
1098 JARS=(${JARS[@]} $FILE)
1100 system/*.apk)
1101 APKS=(${APKS[@]} $FILE)
1103 *.img)
1104 IMGS=(${IMGS[@]} $FILE)
1106 system/*)
1107 TXTS=(${TXTS[@]} $FILE)
1109 esac
1110 done
1112 [[ -n ${COPY[@]} ]] && printtask "### copy patch $P/$A/$R/$B ###"
1113 for FILE in ${COPY[@]}; do
1114 printtask "... copying $FILE ..."
1115 DEST=${FILE%/*}
1116 mkdir -p ./$DEST
1117 if [ -e patches/$P/$A/$R/$B/$FILE ]; then
1118 [ -e $FILE ] && printtask "... overwriting $FILE from $P ..."
1119 \cp -av patches/$P/$A/$R/$B/$FILE ./$DEST >> "$LOG"
1120 else
1121 print_error "$FILE is missing in the patch. Please upload your logfile to the support thread!"
1123 done
1125 # unconditional smali copying
1126 [ -f patches/$P/smali.txt ] && SMALI=$(cat patches/$P/smali.txt)
1127 [ -f patches/$P/$A/smali.txt ] && SMALI=$(cat patches/$P/$A/smali.txt)
1128 [ -f patches/$P/$A/$R/smali.txt ] && SMALI=$(cat patches/$P/$A/$R/smali.txt)
1129 [ -f patches/$P/$A/$R/$B/smali.txt ] && SMALI=$(cat patches/$P/$A/$R/$B/smali.txt)
1130 MOVE=${SMALI##*/}
1131 for SMALI in ${SMALI[@]}; do
1132 printtask "... overwriting $MOVE ..."
1133 if [ -f patches/$P/$A/$R/provisionals/$SMALI ]; then
1134 \cp -av patches/$P/$ANDR/$R/provisionals/$SMALI tmp/$SMALI >> "$LOG"
1135 else
1136 \cp -av patches/$P/$ANDR/provisionals/$SMALI tmp/$SMALI >> "$LOG"
1138 done
1140 [[ -n ${DELS[@]} ]] && printtask "### delete patch $P/$A/$R/$B ###"
1141 for FILE in ${DELS[@]}; do
1142 printtask "... deleting $FILE ..."
1143 \rm -rf ./$FILE
1144 done
1145 [[ -n ${JARS[@]} ]] && printtask "### jar patch $P/$A/$R/$B ###"
1146 for FILE in ${JARS[@]}; do
1147 JAR=${FILE##*/}
1148 NAME=${JAR%.jar}
1149 printtask "... apply $NAME.patch ..."
1150 patch -Nls -p1 -d tmp/${FILE}.out < $PARB/${NAME}.patch 2>&1 > ${JAR}.log
1151 cat ${JAR}.log | tee -a "$LOG"
1152 case "$NAME" in
1153 framework)
1154 # patch preloaded-classes only if a patch exists
1155 if [ -f $PARB/preloaded.patch ]; then
1156 printtask "... apply preloaded.patch ..."
1157 patch -Nls -p1 -d tmp/${FILE}.out < $PARB/preloaded.patch 2>&1 > preloaded.log
1158 cat preloaded.log | tee -a "$LOG"
1159 [[ `grep FAILED preloaded.log` != "" ]] && print_error "failed preloaded.patch"
1163 echo -n "" # do nothing else
1165 esac
1166 # substitute failed smali with premade jar
1167 unset FAILS
1168 FAILS=(`grep FAILED ${JAR}.log | sed -e 's/.*smali\///' | sed -e "s/\.rej'//"`)
1169 if [[ -n ${FAILS[@]} ]]; then
1170 printtask "!!! PATCHING FAILED FOR ${FAILS[@]} !!!"
1171 echo "### replace ${FAILS[@]} ###" > ${JAR}.log
1172 for FAIL in ${FAILS[@]}; do
1173 echo "!!! patch error for $FAIL !!!" >> "$LOG"
1174 #cat tmp/$FILE.out/smali/${FAIL}.rej >> "$LOG"
1175 [[ ${SID[@]} =~ $FAIL ]] && print_error "$FAIL was already replaced before"
1176 [ -f patches/$P/$ANDR/provisionals/${FILE}.out/smali/${FAIL} ] || print_error "failed $FAIL in $JAR cannot be remedied"
1177 copyfailed || print_error "failed $NAME.patch"
1178 printtask "... replace $FAIL ..."
1179 \rm -rf tmp/${FILE}.out/smali/${FAIL} tmp/${FILE}.out/smali/${FAIL}.orig tmp/${FILE}.out/smali/${FAIL}.rej
1180 \cp -av patches/$P/$ANDR/provisionals/${FILE}.out/smali/${FAIL} tmp/${FILE}.out/smali/${FAIL} >> "$LOG" || echo "FAILED to cp $FAIL" >> ${JAR}.log
1181 SID=(${SID[@]} $FAIL)
1182 done
1184 [[ `grep FAILED ${JAR}.log` != "" ]] && print_error "failed $NAME.patch"
1185 garbage tmp/${FILE}.out
1186 if [ -f patches/$P/$A/$R/$B/${JAR}.sh ]; then
1187 printtask "... apply $JAR.sh ..."
1188 . patches/$P/$A/$R/$B/${JAR}.sh 2>&1 > ${JAR}.log
1189 cat ${JAR}.log | tee -a "$LOG"
1191 done
1193 [[ -n ${APKS[@]} ]] && printtask "### apk patch $P/$A/$R/$B ###"
1194 for FILE in ${APKS[@]}; do
1195 APK=${FILE##*/}
1196 if [ -d "tmp/${FILE}.out" ] ; then
1197 printtask "... apply $APK.patch ..."
1198 patch -Nls -p2 -d tmp/${FILE}.out < $PARB/${APK}.patch 2>&1 >> ${APK}.log
1199 cat ${APK}.log | tee -a "$LOG"
1200 [[ `grep FAILED ${APK}.log` != "" ]] && apk_check
1201 garbage tmp/${FILE}.out
1202 else
1203 echo "No $APK in your ROM. Not able to patch this file."
1204 echo "## No $APK in ROM ###" >> "$LOG"
1206 done
1207 [[ -n ${IMGS[@]} ]] && printtask "### img patch $P/$A/$R/$B ###"
1208 for FILE in ${IMGS[@]}; do
1209 IMG=${FILE##*/}
1210 printtask "... applying $IMG.patch ..."
1211 patch -Nls -p1 -d boot/ramdisk < $PARB/${IMG}.patch >> "$LOG" || print_error "failed patching $FILE"
1212 done
1214 [[ -n ${TXTS[@]} ]] && printtask "### text patch $P/$A/$R/$B ###"
1215 for FILE in ${TXTS[@]}; do
1216 TXT=${FILE##*/}
1217 if [[ -f $PARB/${TXT}.patch ]]; then
1218 printtask "... apply $TXT.patch ..."
1219 patch -Nls -p2 -d system/ < $PARB/${TXT}.patch 2>&1 > ${TXT}.log
1220 #cat ${TXT}.log | tee -a "$LOG"
1221 [[ `grep FAILED ${TXT}.log` != "" ]] && print_error "failed $TXT.patch"
1223 if [[ -f $PAR/${TXT}.awk ]]; then
1224 printtask "... apply $TXT.awk ..."
1225 awk -f $PAR/${TXT}.awk $FILE > text || print_error "failed $TXT.awk"
1226 mv text $FILE
1228 if [[ -f $PAR/${TXT}.sed ]]; then
1229 printtask "... apply $TXT.sed ..."
1230 sed -f $PAR/${TXT}.sed $FILE > text || print_error "failed $TXT.sed"
1231 mv text $FILE
1233 if [[ -f $PAR/${TXT}.sh ]]; then
1234 printtask "... apply $TXT.sh ..."
1235 . $PAR/${TXT}.sh 2>&1 >> ${TXT}.log || print_error "failed $TXT.sh"
1237 garbage system/
1238 done
1239 done
1241 # Device specific scripts- Placement is up-for-review
1242 if [ -f patches/devices/$DID/$DID.sh ]; then
1243 . patches/devices/$DID/$DID.sh
1245 # Replace updater-script for CM7-- Testing
1246 if [ "$ANDR" == "gingerbread" ]; then
1247 replace_updater
1249 # Rebuilding system files
1251 [[ -n ${JID[@]} ]] && printtask "### rebuild jar ###"
1252 for FILE in ${JID[@]}; do
1253 JAR=${FILE##*/}
1254 printtask "... rebuild $JAR ..."
1255 java -Xmx512M -jar smali.jar -a $API tmp/${FILE}.out/smali -o tmp/${FILE}.out/classes.dex >> "$LOG" 2>> "$LOG"
1256 [ -f tmp/${FILE}.out/classes.dex ] || smali_error "failed compiling $JAR !!!"
1257 jar -ufv ${FILE} -C tmp/${FILE}.out/ classes.dex >> "$LOG" 2>> "$LOG"
1258 if [ $FILE == "system/framework/framework.jar" ]; then
1259 jar -ufv ${FILE} -C tmp/${FILE}.out/ preloaded-classes >> "$LOG" 2>> "$LOG"
1261 done
1263 [[ -n ${AID[@]} ]] && printtask "### rebuild apk ###"
1264 for FILE in ${AID[@]}; do
1265 APK=${FILE##*/}
1266 if [ -d tmp/${FILE}.out ]; then
1267 printtask "... rebuild $APK ..."
1268 java -jar apktool.jar b tmp/${FILE}.out >> "$LOG" 2>> "$LOG" || print_error "failed compiling $FILE !!!"
1269 jar -uvf $FILE -C tmp/${FILE}.out/build/apk/ . > /dev/null 2>> "$LOG"
1271 done
1273 [[ -n ${IID[@]} ]] && printtask "### rebuild img ###"
1274 for FILE in ${IID[@]}; do
1275 printtask "### rebuild $FILE ###"
1276 case $FILE in
1277 boot.img)
1278 # Rebuilding boot.img
1279 cd boot
1280 printtask "... rebuilding ramdisk ..."
1281 ./mkbootfs$EXE ./ramdisk | gzip > ramdisk-new.gz
1283 printtask "... composing boot.img ..."
1284 BASE=$(cat boot.img-base)
1285 # hex to decimal in cygwin prefixing "0x" w/ C arithmetic
1286 PGSIZE=$((${PGFORM}$(cat boot.img-pagesize)))
1287 CMDLINE=$(cat boot.img-cmdline)
1288 echo "cmdline = no_console_suspend=1 console=null $CMDLINE" >> "$LOG"
1289 echo "pagesize = $PGSIZE" >> "$LOG"
1290 echo "base = $BASE" >> "$LOG"
1291 printtask "... rebuilding boot.img ..."
1292 ./mkbootimg$EXE --kernel boot.img-zImage --ramdisk ramdisk-new.gz --cmdline "no_console_suspend=1 console=null $CMDLINE" --base "$BASE" --pagesize "$PGSIZE" -o ../boot.img || print_error "failed building boot.img"
1293 cd ..
1296 print_error "cannot process $FILE"
1298 esac
1299 done
1301 printtask "### create update.zip ###"
1302 jar -cfv tmp.zip ${IID[@]} ${JID[@]} ${AID[@]} ${CID[@]} ${TID[@]} META-INF >> "$LOG" 2>> "$LOG"
1303 java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip update.zip 2>> "$LOG"
1305 \mv restore.zip update.zip ..
1306 echo "### finished ###"
1307 echo "flash update.zip to install the modified"
1308 echo "flash restore.zip to restore the original"
1310 # add announcement- optional.
1311 for P in ${PID[@]}; do
1312 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1313 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1314 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1315 if [ -f patches/$P/$A/$R/$B/README.txt ]; then
1316 cat patches/$P/$A/$R/$B/README.txt
1317 elif [ -f patches/$P/$A/$R/README.txt ]; then
1318 cat patches/$P/$A/$R/README.txt
1319 elif [ -f patches/$P/$A/README.txt ]; then
1320 cat patches/$P/$A/README.txt
1322 done
1324 cd ..
1325 \rm -rf "$TEMP"