Finally fixed multiple mod patch dates
[auto-patcher.git] / auto_patcher
bloba9af71a63ac236f242d4701641e252b5452d058c
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 conflict_error () {
266 # For conflicting packages
267 echo ""
268 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
269 printtask "!!! error: $@"
270 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
271 cleanup
272 PID=mods
273 mods_info
276 misspatch_error () {
277 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
278 printtask "!! error: $@ "
279 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
280 echo ""
281 printtask "!! The Auto-Patcher could not find its patches and/or tools!"
282 echo ""
283 echo "* Did you run ./batch.sh first?"
284 echo ""
285 echo "The patch_patches.tgz and patch_tools.tgz need to be in this directory,"
286 echo " one way or another..."
287 echo ""
288 cleanup
289 printusage_help
292 misstools_error () {
293 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
294 printtask "!! error: $@ "
295 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
296 printtask "Your set-up is missing a dependency."
297 echo "We require JDK, patch and cpio."
298 echo ""
299 echo ""
300 echo "Each distro is different"
301 echo "but you must ensure you have them all installed and try again."
302 echo ""
303 cleanup
304 printusage_help
307 printtask () {
308 echo "" >> "$LOG"
309 echo $@ | tee -a "$LOG"
312 copyfailed () {
313 echo ""
314 printtask "File for which patching failed:"
315 printtask "---------------------------------------------"
316 echo ""
317 printtask "${FAIL##*/}"
318 echo ""
319 echo "---------------------------------------------"
320 echo ""
321 echo "We can try to add a premade copy of those files."
322 echo "This sometimes works."
323 echo ""
324 echo "But IT MAY NOT WORK!!!"
325 echo ""
326 echo ""
327 askconsent && return 0 || return 1
330 askconsent () {
331 sleep 1
332 echo -n "Do you want to proceed ? (YES/no) "
333 read PROCEED
334 echo "askconsent final = ${PROCEED}: for $FAIL" >> "$LOG"
335 case $PROCEED in
336 [Yy] | [Yy][Ee][Ss])
337 return 0; # successful:
338 echo "*** You (or ApG) have elected to use a prepatched copy of $FAIL ***" >> "$LOG"
341 return 1; # error
342 echo "*** You have declined to insert $FAIL by not answering 'yes' at the prompt. ***" >> "$LOG"
344 esac
347 replace_updater () {
349 # Function for devices that use SDcard installs. Also to be tested for CM7
350 # since CM7 seems to use an updater-script that wipes EMMC. Testing
352 UPDIR=META-INF/com/google/android
353 \rm $UPDIR/updater-script
354 \cp patches/common/$UPDIR/updater-script $UPDIR
355 echo "run_program(\"/sbin/busybox\", \"umount\", \"/system\");" >> UPDATE.txt
356 cat UPDATE.txt >> $UPDIR/updater-script
357 echo ""
358 echo "New updater-script being used:" >> "$LOG"
359 echo "-----------------------------" >> "$LOG"
360 cat $UPDIR/updater-script >> "$LOG"
363 abspath () {
364 case `uname -s` in
365 CYGWIN*)
366 echo $(cygpath -ua "$1")
368 Darwin)
369 #[[ $(echo $1 | awk '/^\//') == $1 ]] && echo "$1" || echo "$PWD/$1"
370 [[ ${1:0:1} == "/" ]] && echo "$1" || echo "$PWD/$1"
372 Linux)
373 echo $(readlink -f "$1")
376 if [[ ${1:0:1} == "/" ]]; then
377 echo "$1"
378 elif [[ ${1:0:2} == "./" ]]; then
379 echo "$PWD/${1:2}"
380 else
381 echo "$PWD/$1"
384 esac
387 mods_info () {
388 CEILING=$CURRENT_ANDROID # Default is that everything works...we'll see.
389 case $PID in
390 mods)
391 echo ""
392 echo "The Auto-Patcher $VERSION"
393 echo "*******************************"
394 echo ""
395 echo "The available mods are"
396 echo "****************************************************"
397 echo "* pdroid openpdroid voice v6supercharger *"
398 echo "* voice insecure secure external_internal *"
399 echo "* tabletUI 3gdongle pd2.0 *"
400 echo "****************************************************"
401 echo ""
402 echo "To find out more about any mod, simply enter:"
403 echo " ./auto_patcher -h <MODNAME>"
404 echo ""
405 echo " For usage info: ./auto_patcher -h"
406 echo ""
407 cleanup
408 exit
410 auto*)
411 echo ""
412 echo "**************************************"
413 echo "The Auto-Patcher ate a kitten once..."
414 echo "**************************************"
415 printusage_help
417 voice)
418 FLOOR=4.0.0
419 DESC="Use on wifi-only tablets to have the software register as 'voice-enabled'. Allows VOIP like Google Voice to function."
421 v6supercharger)
422 FLOOR=4.0.0
423 CEILING=4.2.1
424 DESC="A memory-management tool. It requires smali edits for Android roms 4.0+."
425 DESC1="The Auto-Patcher applies all 56 edits recommended by the dev."
426 DEV="Zeppelinrox"
427 DEPENDENCY="The V6 Supercharger Script. Get it at http://forum.xda-developers.com/showthread.php?t=991276/"
429 pdroid)
430 FLOOR=2.3.7
431 CEILING=4.1.2
432 DESC="Security Software that safely manages permissions w/o causing FC's. No longer under development. Try the open-source expansion of this program, PDroid Manager."
433 DESC1="(It's the 'openpdroid' mod within the Auto-Patcher)."
434 DEV="Svyat"
435 DEPENDENCY="The Pdroid app. You can get it at http://forum.xda-developers.com/showthread.php?t=1923576"
437 pd2.0)
438 FLOOR=4.1.2
439 CEILING=4.1.2
440 DESC="An expansion of the PDroid application/framework."
441 DEV="CollegeDev"
442 DEPENDENCY="The free PDroid2.0 app available at http://forum.xda-developers.com/showthread.php?t=1923576"
444 openpdroid)
445 FLOOR=4.1.2
446 CEILING=4.2.1
447 DESC="A fork of the open-source PDroid and Pdroid2.0 framework."
448 DEV="FFU5y/wbedard/mateorod/Community"
449 DEPENDENCY="The PDroidManager app freely available from Google Play or http://forum.xda-developers.com/showthread.php?t=1994860"
451 opendroid)
452 echo ""
453 echo "No mod named 'opendroid'. You probably mean 'openpdroid'. Try again."
454 PID="mods"
455 mods_info
457 external_internal)
458 FLOOR=2.3.3
459 DESC="Swap internal and external storage."
461 insecure)
462 FLOOR=2.3.3
463 DESC="Make any boot.img insecure and allow remount as well as adb push/pull of system files. True root."
465 secure)
466 FLOOR=2.3.3
467 DESC="Make any boot.img secure."
469 3gdongle)
470 FLOOR=4.1.0
471 CEILING=4.2.1
472 DESC="Allows 3gdongles to work on wifi tablets w/o 3rd party applications."
473 DEV="trevd"
474 DEPENDENCY="None, but read the troubleshooting guide at http://forum.xda-developers.com/showthread.php?t=1798631"
476 tabletUI)
477 FLOOR=4.1.0
478 CEILING=4.1.2
479 DESC="Changes the user interface of Phones and Phablets to the popular Tablet UI."
480 DEV="barmullio"
482 esac
483 # strip decimals from android version (i.e. 2.3.7 becomes 237) so we can do math
484 NVID=${VID//[.]/}
485 COMPATF=${FLOOR//[.]/}
486 COMPATC=${CEILING//[.]/}
489 apk_check () {
490 if [ -f patches/$P/$A/$R/$B/$FILE ]; then
491 echo "... Patching $APK failed, but we will copy over a prepatched file ..."
492 \cp -av patches/$P/$A/$R/$B/$FILE $FILE >> "$LOG"
493 else
494 print_error "failed patching $APK!!!"
497 compat_check () {
498 for P in ${PID[@]}; do
499 mods_info
500 if [[ "$NVID" -lt "$COMPAT" ]]; then
501 mismatch_error "Your Android $VID rom is too old! The minimum for $P is Android $FLOOR!"
503 if [[ "$NVID" -gt "$COMPATC" ]]; then
504 mismatch_error "Sorry, $P has not been made available for Android $VID yet!"
506 done
508 extpath () {
509 case `uname -s` in
510 CYGWIN*)
511 echo $(cygpath -da "$1")
514 echo $(abspath "$1")
516 esac
519 #contains () { for e in "${@:2}"; do [[ "$e" = "$1" ]] && return 0; done; return 1; }
521 parse () { echo "${1%%_*}"; }
523 getbuildprop () {
524 if [ -f system/build.prop ]; then
525 result=(`grep $1 system/build.prop | tr -d '\r' | tr '=' ' '`)
526 echo "${result[1]}"
527 else
528 echo ""
533 aosp_mod_check() {
534 jar -xvf "$ROMX" system/framework/framework2.jar >> $LOG
535 if [ -s system/framework/framework2.jar ]; then
536 ever_check
537 else
538 AOSP=aosp-jb
542 ever_check() {
543 MID=$(getbuildprop ro.build.romversion)
544 if [[ "$MID" == "Evervolv"* ]]; then
545 AOSP=aosp-ever
546 else
547 MID=$(getbuildprop ro.build.display.id)
548 if [[ "$MID" == "ev"* ]]; then
549 AOSP=aosp-ever
550 else
551 AOSP=aosp-mod
556 pa_check() {
557 CMID=$(getbuildprop ro.modversion)
558 PAID=$(getbuildprop ro.pa.version)
559 MID=$(getbuildprop ro.build.display.id)
560 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
561 DID=$(getbuildprop ro.product.device)
562 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
563 if [[ -n $PAID ]]; then
564 RID=pa
565 else
566 case $CMID in
567 [Pp][Aa]*)
568 RID=pa;
571 RID=cm;
573 esac
577 proberom () {
578 VID=$(getbuildprop ro.build.version.release)
579 ANDR="${VID%.*}" # Cut flavor to 1 significant digit to cover specific range or release.
580 if [ "$ANDR" == "2.3" ]; then
581 FLAVR=gingerbread
582 API=10
583 RID=cm;
584 elif [ "$ANDR" == "4.0" ]; then
585 FLAVR=ics
586 API=15
587 MID=$(getbuildprop ro.rommanager.developerid)
588 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.modversion))
589 DID=$(getbuildprop ro.product.device)
590 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
592 case "$MID" in
593 pa|cm9|cm|cyanogenmod*)
594 RID=cm;
596 aokp|teamkang)
597 RID=aokp;
599 aosp*)
600 RID=aosp;
603 echo "!!! $MID is not supported yet, trying generic latest !!!"
605 esac
606 elif [ "$ANDR" == "4.1" ]; then
607 FLAVR=jellybean
608 API=16
609 CMID=$(getbuildprop ro.cm.version)
610 if [[ -n $CMID ]]; then
611 pa_check
612 else
613 MID=$(getbuildprop ro.build.display.id)
614 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
615 DID=$(getbuildprop ro.product.device)
616 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
617 case "$MID" in
618 cm10|cm*|cyanogenmod*)
619 RID=cm;
621 aokp*|teamkang)
622 RID=aokp;
624 pa*)
625 RID=pa;
627 ev*)
628 RID=aosp-ever;
631 RID=`aosp_mod_check`;
633 esac
635 elif [ "$ANDR" == "4.2" ]; then
636 FLAVR=jellybean
637 API=17
638 CMID=$(getbuildprop ro.cm.version)
639 MID=$(getbuildprop ro.build.display.id)
640 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
641 DID=$(getbuildprop ro.product.device)
642 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
644 case "$MID" in
645 cm10|cm*|cyanogenmod*)
646 RID=cm;
648 aokp*|teamkang)
649 RID=aokp;
651 pa*) # Defaults to cm for now, since there is a chance we can patch forks
652 RID=cm;
655 RID=aosp;
657 esac
658 else
659 print_error "unknown ROM version $VID"
661 echo "... result of ROM check: version= $VID rom= $RID ..."
664 # Advanced build date query
665 # This should set the patch date automatically.
667 buildquery() {
668 UTC=$(getbuildprop ro.build.date.utc)
670 # Difference in how OS X and Linux/Cygwin handles 'date' utility
671 case `uname -s` in
672 [Dd]arwin)
673 BDID=`date -r $UTC +%Y%m%d`
674 echo "#### Darwin Build Query used ####" >> "$LOG"
677 BDID=`date -d "1970-01-01 UTC $UTC seconds" +"%Y%m%d"`
678 echo "#### Standard Build Query ####" >> "$LOG"
680 esac
682 # If patch date is specified on CLI, use that patch date
683 if [ $# -gt 3 ]; then
684 BID=${4//,/ };
685 else
686 case $ANDR in
687 gingerbread)
688 # CM7 roms do not have UTC time stamp- so no build query.
689 BID=latest;
690 echo "*** CM7 roms default to latest patches. If using an older rom ***"
691 echo "*** specify patch date on command line. Use -h to see available patches ***"
694 for P in ${PID[@]}; do
695 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
696 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
697 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
698 PAR=patches/$P/$A/$R
699 PARB=patches/$P/$A/$R/$B
700 DATES=`ls patches/$P/$A/$R/ | grep '201*'`
701 # Intialize variable - High so as to determine lowest in first loop.
702 BID=20201231
703 # find earliest available patch date
704 for i in $DATES; do
705 if [[ $i -lt $BID ]]; then
706 BID=$i
708 done
709 # Check if earliest patches are from before build date. Else use earliest
711 # If older than earliest patch set, then find best match
712 if [[ $(($BID-$BDID)) -lt 0 ]]; then
713 for g in $DATES; do
714 # use any patch that matches $UTC
715 if [[ $(($BDID-$g)) -eq 0 ]]; then
716 BID=$g
717 break
718 # Set highest $BID w/o going over $UTC
719 elif [[ $(($BDID-$g)) -gt 0 ]] && [[ $g -gt $BID ]]; then
720 BID=$g
722 done
724 echo "... $PID patch date has been set to: $BID..."
725 B=$BID
726 break
727 done
729 esac
733 proberil () {
734 RIL=$(getbuildprop ro.telephony.ril_class)
735 [[ -n $RIL ]] && printtask "... result of ROM check: RIL= $RIL"
738 rominfo () {
739 echo "# VER= $VERSION" >> "$LOG"
740 echo "# OS= $OSTYPE ${BIT}bit" >> "$LOG"
741 echo "# VID= $VID" >> "$LOG"
742 echo "# PID= ${PID[@]}" >> "$LOG"
743 echo "# MID= $MID" >> "$LOG"
744 echo "# RID= $RID" >> "$LOG"
745 echo "# ANDR= $ANDR" >> "$LOG"
746 echo "# BDID= $BDID" >> "$LOG"
747 echo "# DID= $DID" >> "$LOG"
748 echo "# BID= $BID" >> "$LOG"
752 if [[ $1 == -h ]]; then
753 if [ $# -gt 1 ]; then
754 PID=$2
755 mods_info
756 echo ""
757 echo "The Auto-Patcher $VERSION by Mateorod and Pastime1971"
758 echo "*************************************************"
759 echo ""
760 echo "Mod Name: $PID"
761 echo ""
762 echo " $DESC"
763 echo "$DESC1"
764 echo ""
765 echo "Developer: $DEV"
766 echo "Dependancies: $DEPENDENCY"
767 echo ""
768 echo "Works on Android ROMs from $FLOOR to $CEILING"
769 echo
770 exit
774 [[ $# -lt 1 || -z $1 ]] && PID="mods" && mods_info
775 [[ $1 == "-h" ]] && usage_more_help | less && display_help
777 echo ""
778 echo "The Auto-Patcher $VERSION"
779 echo ""
780 # by pastime1971 and mateorod
782 ROOT=$(abspath `dirname "$0"`)
783 TOOL="$ROOT/patch_tools.tgz"
784 PTCH="$ROOT/patch_patches.tgz"
785 ROM=$(abspath "$1")
786 ROMX=$(extpath "$1")
788 if [[ $OSTYPE == "cygwin" ]]; then
789 EXE=".exe"
790 PGFORM="0x"
793 DATE=`date +%Y%m%d%H%M%S`
794 TEMP=$(abspath ./tmp$DATE)
795 LOG=$(abspath ./log$DATE.txt)
796 #echo $ROOT $TOOL $ROM $TEMP "$LOG"
797 echo "ROOT= $ROOT" >> "$LOG"
798 echo "TOOL= $TOOL" >> "$LOG"
799 echo "ROM= $ROM" >> "$LOG"
800 echo "ROMX= $ROMX" >> "$LOG"
802 \rm -f restore.zip update.zip
804 CHK=$(getconf LONG_BIT)
805 if [[ $CHK = "64" ]]; then
806 BIT=64
807 else [[ $BIT = "32" ]];
808 BIT=32
812 printtask "### verify tools ###"
813 which patch >> "$LOG" || misstools_error "Missing \"patch diff command\""
814 which tar >> "$LOG" || misstools_error "Missing \"tar archive command\""
815 which jar >> "$LOG" || misstools_error "Missing \"jar (JDK)\""
816 which java >> "$LOG" || misstools_error "Missing \"java (JRE)\""
817 which cpio >> "$LOG" || misstools_error "Missing \"cpio archive command\""
818 [ -f "$TOOL" ] || misspatch_error "patch tool is missing"
819 [ -f "$PTCH" ] || misspatch_error "patch patches are missing"
820 printtask "### verify ROM ###"
821 [ -f "$ROM" ] || print_error "Cannot find $ROM"
822 echo "### running $0 $@" >> "$LOG"
823 mkdir "$TEMP"
824 cd "$TEMP"
826 PATH="$TEMP:$PATH"
827 export PATH
828 echo "PATH= $PATH" >> "$LOG"
830 printtask "### unzip patch tools ###"
831 tar xzf "$TOOL" > /dev/null || print_error "failed extracting tools !!!"
833 # Get OS specific tools
834 case `uname -s` in
835 CYGWIN*)
836 \mv cygwin/aapt.exe .
837 \mv cygwin/*.exe boot/
838 \rm -rf cygwin # why? If you want to we can keep/add it to mac/linux, though.
840 [Dd]arwin)
841 \mv mac/aapt .
843 [Ll]inux)
844 \mv linux/aapt .
847 \mv linux/aapt .
849 esac
850 # Ensure aapt permissions - possibly to one day be expanded to all tools in a function.
851 chmod a+x aapt$EXE
853 printtask "### unzip patch patches ###"
854 tar xzf "$PTCH" > /dev/null || print_error "failed extracting patches !!!"
856 # we need build.prop for both RIL probing and ROM probing
857 jar -xvf "$ROMX" system/build.prop 2>> "$LOG" || print_error "failed extracting build.prop from $ROMX !!!"
859 # rom + ril type
860 proberil
861 printtask "### probe rom type ###"
862 proberom
864 # rom type
865 if [ $# -gt 1 ]; then
866 PIT=$2
867 if [[ "$PIT" = "-h" ]]; then
868 display_help
871 if [ $# -gt 2 ]; then
872 RID=$3
873 case "$RID" in
874 cm10|cm*|cyanogenmod*)
876 aokp*|teamkang)
877 RID=aokp;
879 pa*)
880 RID=pa;
882 aosp-ever)
883 RID=aosp-ever;
885 aosp*)
886 case "ANDR" in
887 4.1)
888 RID=`aosp_mod_check`;
891 RID=aosp
893 esac
895 201*)
896 date_error "You must specify ROMTYPE if designating a patch date!!"
899 rom_error "$RID is not a valid ROMTYPE!!"
901 esac
902 echo "... Using $RID patches ..."
903 else
904 echo "... Using results of ROM check ..."
907 # patch type
908 if [ $# -gt 1 ]; then
909 PIL=${2//,/ } # If more than one mod, make string separated by spaces
910 else
911 PIL="pdroid v6supercharger"
912 echo "No mods selected. Defaulting to the v6 and Pdroid, just because we can."
915 PID=(${PIL// / }) # turn string into array
916 COPYPID=("${PID[@]}") # working copy to iterate over
917 MODS_NUMBER=${#COPYPID[@]} # number of elements (mods)
919 if [[ $MODS_NUMBER > 1 ]]; then
920 INDEX=0
921 for p in ${COPYPID[@]}; do
922 if [ "$p" = "pdroid" ] || [ "$p" = "pd2.0" ] ||[ "$p" = "openpdroid" ]; then
923 SPID[0]=$p
924 unset COPYPID["$INDEX"]
925 break
926 else
927 INDEX=$((INDEX + 1))
929 done
930 for p in ${COPYPID[@]}; do
931 if [ "$p" = "pdroid" ] || [ $p = "pd2.0" ] ||[ $p = "openpdroid" ]; then
932 conflict_error "Those mods conflict! Only one pdroid mod at a time!"
933 else
934 i=${#SPID[@]}
935 SPID[i]=$p
936 i+=1
938 done
939 else
940 SPID=${COPYPID[@]}
941 echo "only one mod found, mod is ${SPID[@]}"
943 for P in ${PIL[@]}; do
944 [[ ${PID[@]} =~ $P ]] || PID=(${PID[@]} $P)
945 done
947 # Check to make sure selected roms are available for the Android version of patched ROM
948 compat_check
950 # Build date
951 if [ $# -gt 3 ]; then
952 BID=$4
953 # even here, we should try and create a function that matches as close to the above
954 # BID as possible. Now, a bad match (user error) defaults to latest
955 echo "... $PID patch date set manually to $BID ..."
956 else
957 buildquery
960 # echo ROM info
961 rominfo
963 # I think I finally may have rendered this VERY long if statement obsolete...CHECK!
964 if [[ ( "$PID" == "-h" || "$RID" == "-h" || "$BID" == "-h" ) ]]; then
965 display_help
966 else
968 #Begin cycle
970 for P in ${PID[@]}; do
971 [ -d patches/$P ] || print_error "$P is not available"
972 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
973 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
974 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
976 unset FILES
977 [ -f patches/$P/files.txt ] && FILES=$(cat patches/$P/files.txt)
978 [ -f patches/$P/$A/files.txt ] && FILES=$(cat patches/$P/$A/files.txt)
979 [ -f patches/$P/$A/$R/files.txt ] && FILES=$(cat patches/$P/$A/$R/files.txt)
980 [ -f patches/$P/$A/$R/$B/files.txt ] && FILES=$(cat patches/$P/$A/$R/$B/files.txt)
981 for FILE in ${FILES[@]}; do
982 case "$FILE" in
983 +system/*)
984 [[ ${CID[@]} =~ ${FILE:1} ]] && print_error "${FILE:1} is already being copied" || CID=(${CID[@]} ${FILE:1})
986 -system/*)
987 [[ ${EID[@]} =~ ${FILE:1} ]] || EID=(${EID[@]} ${FILE:1})
989 system/*.jar)
990 [[ ${JID[@]} =~ $FILE ]] || JID=(${JID[@]} $FILE)
991 echo "set_perm(0, 0, 0644, \"/$FILE\");" >> UPDATE.txt
993 system/*.apk)
994 [[ ${AID[@]} =~ $FILE ]] || AID=(${AID[@]} $FILE)
995 echo "set_perm(0, 0, 0644, \"/$FILE\");" >> UPDATE.txt
997 *.img)
998 [[ ${IID[@]} =~ $FILE ]] || IID=(${IID[@]} $FILE)
1000 system/*)
1001 [[ ${TID[@]} =~ $FILE ]] || TID=(${TID[@]} $FILE)
1003 esac
1004 done
1005 done
1006 echo "### DELETE FILES= ${EID[@]}" >> "$LOG"
1007 echo "### COPY FILES= ${CID[@]}" >> "$LOG"
1008 echo "### JAR FILES= ${JID[@]}" >> "$LOG"
1009 echo "### APK FILES= ${AID[@]}" >> "$LOG"
1010 echo "### IMG FILES= ${IID[@]}" >> "$LOG"
1011 echo "### TXT FILES= ${TID[@]}" >> "$LOG"
1013 printtask "### unzip rom ###"
1014 # extract system files
1015 jar -xvf "$ROMX" ${JID[@]} ${AID[@]} ${IID[@]} ${TID[@]} 2>> "$LOG" || print_error "failed extracting ${JID[@]} ${AID[@]} ${IID[@]} from $ROMX !!!"
1017 printtask "### create updater script ###"
1018 jar -xvf "$ROMX" META-INF/com/google/android/updater-script META-INF/com/google/android/update-binary
1019 jar -xvf "$ROMX" META-INF/com/google/android/update-binary-installer 1> /dev/null 2> /dev/null
1020 if [ -f META-INF/com/google/android/update-binary-installer ]; then
1021 printtask "... using Aroma installer ..."
1022 \mv META-INF/com/google/android/update-binary-installer META-INF/com/google/android/update-binary
1023 else
1024 printtask "... using Clockworkmod installer ..."
1026 if [ -f META-INF/com/google/android/update-binary ]; then
1027 cat META-INF/com/google/android/updater-script | grep ^mount | grep "/system" | head -n 1 > updater-script
1028 [ -s updater-script ] || echo "run_program(\"/sbin/busybox\", \"mount\", \"/system\");" > updater-script
1029 for FILE in ${EID[@]}; do
1030 # restore the original
1031 jar -xvf "$ROMX" $FILE 2> /dev/null || printtask "!!! warning $FILE cannot be restored !!!"
1032 done
1033 for FILE in ${CID[@]}; do
1034 # replace with the original or delete it
1035 jar -xvf "$ROMX" $FILE 2> /dev/null || echo "delete(\"/$FILE\");" >> updater-script
1036 done
1037 echo "package_extract_dir(\"system\", \"/system\");" >> updater-script
1038 # add permission management
1039 cat META-INF/com/google/android/updater-script | grep set_perm | grep "/system" >> updater-script
1040 # TODO: remove if we don't need it any more
1041 for P in ${PID[@]}; do
1042 if [ -s patches/$P/$A/set_perm.txt ]; then
1043 echo "...setting permissions..."
1044 cat patches/$P/$A/set_perm.txt >> updater-script
1046 done
1047 cat META-INF/com/google/android/updater-script | grep ^unmount | grep "/system" | head -n 1 >> updater-script
1048 [[ ${IID[@]} =~ boot.img ]] && cat META-INF/com/google/android/updater-script | grep "boot.img" >> updater-script
1049 cat updater-script > META-INF/com/google/android/updater-script
1050 echo "# generated updater-script" >> "$LOG"
1051 cat updater-script >> "$LOG"
1052 else
1053 # this is not enough any more
1054 jar -xvf update-template.zip META-INF/com/google/android/update-binary META-INF/com/google/android/updater-script
1057 printtask "### create restore.zip ###"
1058 jar -cvf tmp.zip ${JID[@]} ${AID[@]} ${IID[@]} META-INF > /dev/null 2>> "$LOG"
1059 java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip signed.zip 2>> "$LOG"
1060 \mv signed.zip restore.zip
1061 \rm -f tmp.zip
1063 printtask "### decompile system files ###"
1065 # decompile system files
1066 for FILE in ${JID[@]}; do
1067 JAR=${FILE##*/}
1068 printtask "... decompile $JAR ..."
1069 java -jar baksmali.jar -b -a $API -o tmp/${FILE}.out/smali ${FILE} >> "$LOG" 2>> "$LOG"
1070 if [ $FILE == "system/framework/framework.jar" ]; then
1071 printtask "... extract preloaded-classes ..."
1072 jar -xvf ${FILE} preloaded-classes >> "$LOG" 2>> "$LOG"
1073 \mv preloaded-classes tmp/${FILE}.out/
1075 done
1077 # Pull framework-files for APK...
1078 if [ ${#AID[@]} -gt 0 ]; then
1079 jar -xvf "$ROMX" system/framework/framework-res.apk >> "$LOG"
1080 printtask "... installing framework files ..."
1081 java -jar apktool.jar if system/framework/framework-res.apk
1082 # Decompile APKs
1083 for FILE in ${AID[@]}; do
1084 APK=${FILE##*/}
1085 if [ -f $FILE ]; then
1086 printtask "... decompile $APK ..."
1087 java -jar apktool.jar d -f $FILE tmp/$FILE.out
1089 done
1092 # Unpack image files {boot.img only so far...}
1093 for FILE in ${IID[@]}; do
1094 printtask "### unpacking $FILE ###"
1095 case "$FILE" in
1096 boot.img)
1097 if [ -f boot.img ]; then
1098 cd boot
1099 ./unpackbootimg$EXE -i ../boot.img >> "$LOG" 2>> "$LOG"
1100 mkdir ramdisk
1101 cd ramdisk
1102 gzip -dc ../boot.img-ramdisk.gz | cpio -i >> "$LOG" 2>> "$LOG"
1103 cd ../../
1104 else
1105 print_error "A mod needs to patch boot.img! This rom does not contains boot.img."
1109 print_error "cannot process $FILE"
1111 esac
1112 done
1114 # apply system modification
1116 for P in ${PID[@]}; do
1117 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1118 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1119 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1120 PAR=patches/$P/$A/$R
1121 PARB=patches/$P/$A/$R/$B
1123 unset FILES COPY DELS JARS APKS IMGS TXTS
1124 [ -f patches/$P/files.txt ] && FILES=$(cat patches/$P/files.txt)
1125 [ -f patches/$P/$A/files.txt ] && FILES=$(cat patches/$P/$A/files.txt)
1126 [ -f patches/$P/$A/$R/files.txt ] && FILES=$(cat patches/$P/$A/$R/files.txt)
1127 [ -f patches/$P/$A/$R/$B/files.txt ] && FILES=$(cat patches/$P/$A/$R/$B/files.txt)
1128 for FILE in ${FILES[@]}; do
1129 case $FILE in
1130 +system/*)
1131 COPY=(${COPY[@]} ${FILE:1})
1133 -system/*)
1134 DELS=(${DELS[@]} ${FILE:1})
1136 system/*.jar)
1137 JARS=(${JARS[@]} $FILE)
1139 system/*.apk)
1140 APKS=(${APKS[@]} $FILE)
1142 *.img)
1143 IMGS=(${IMGS[@]} $FILE)
1145 system/*)
1146 TXTS=(${TXTS[@]} $FILE)
1148 esac
1149 done
1151 [[ -n ${COPY[@]} ]] && printtask "### copy patch $P/$A/$R/$B ###"
1152 for FILE in ${COPY[@]}; do
1153 printtask "... copying $FILE ..."
1154 DEST=${FILE%/*}
1155 mkdir -p ./$DEST
1156 if [ -e patches/$P/$A/$R/$B/$FILE ]; then
1157 [ -e $FILE ] && printtask "... overwriting $FILE from $P ..."
1158 \cp -av patches/$P/$A/$R/$B/$FILE ./$DEST >> "$LOG"
1159 else
1160 print_error "$FILE is missing in the patch. Please upload your logfile to the support thread!"
1162 done
1164 # unconditional smali copying
1165 [ -f patches/$P/smali.txt ] && SMALI=$(cat patches/$P/smali.txt)
1166 [ -f patches/$P/$A/smali.txt ] && SMALI=$(cat patches/$P/$A/smali.txt)
1167 [ -f patches/$P/$A/$R/smali.txt ] && SMALI=$(cat patches/$P/$A/$R/smali.txt)
1168 [ -f patches/$P/$A/$R/$B/smali.txt ] && SMALI=$(cat patches/$P/$A/$R/$B/smali.txt)
1169 MOVE=${SMALI##*/}
1170 for SMALI in ${SMALI[@]}; do
1171 if [ -f patches/$P/$A/$R/provisionals/$SMALI ]; then
1172 printtask "... overwriting $MOVE ..."
1173 \cp -a patches/$P/$ANDR/$R/provisionals/$SMALI tmp/$SMALI >> "$LOG"
1174 elif [ -f patches/$P/$A/provisionals/$SMALI ]; then
1175 printtask "... overwriting $MOVE ..."
1176 \cp -a patches/$P/$ANDR/provisionals/$SMALI tmp/$SMALI >> "$LOG"
1178 done
1180 [[ -n ${DELS[@]} ]] && printtask "### delete patch $P/$A/$R/$B ###"
1181 for FILE in ${DELS[@]}; do
1182 printtask "... deleting $FILE ..."
1183 \rm -rf ./$FILE
1184 done
1185 [[ -n ${JARS[@]} ]] && printtask "### jar patch $P/$A/$R/$B ###"
1186 for FILE in ${JARS[@]}; do
1187 JAR=${FILE##*/}
1188 NAME=${JAR%.jar}
1189 printtask "... apply $NAME.patch ..."
1190 patch -Nls -p1 -d tmp/${FILE}.out < $PARB/${NAME}.patch 2>&1 > ${JAR}.log
1191 cat ${JAR}.log | tee -a "$LOG"
1192 case "$NAME" in
1193 framework)
1194 # patch preloaded-classes only if a patch exists
1195 if [ -f $PARB/preloaded.patch ]; then
1196 printtask "... apply preloaded.patch ..."
1197 patch -Nls -p1 -d tmp/${FILE}.out < $PARB/preloaded.patch 2>&1 > preloaded.log
1198 cat preloaded.log | tee -a "$LOG"
1199 [[ `grep FAILED preloaded.log` != "" ]] && print_error "failed preloaded.patch"
1203 echo -n "" # do nothing else
1205 esac
1206 # substitute failed smali with premade jar
1207 unset FAILS
1208 FAILS=(`grep FAILED ${JAR}.log | sed -e 's/.*smali\///' | sed -e "s/\.rej'//"`)
1209 if [[ -n ${FAILS[@]} ]]; then
1210 printtask "!!! PATCHING FAILED FOR ${FAILS[@]} !!!"
1211 echo "### replace ${FAILS[@]} ###" > ${JAR}.log
1212 for FAIL in ${FAILS[@]}; do
1213 echo "!!! patch error for $FAIL !!!" >> "$LOG"
1214 #cat tmp/$FILE.out/smali/${FAIL}.rej >> "$LOG"
1215 [[ ${SID[@]} =~ $FAIL ]] && print_error "$FAIL was already replaced before"
1216 [ -f patches/$P/$ANDR/provisionals/${FILE}.out/smali/${FAIL} ] || print_error "failed $FAIL in $JAR cannot be remedied"
1217 copyfailed || print_error "failed $NAME.patch"
1218 printtask "... replace $FAIL ..."
1219 \rm -rf tmp/${FILE}.out/smali/${FAIL} tmp/${FILE}.out/smali/${FAIL}.orig tmp/${FILE}.out/smali/${FAIL}.rej
1220 \cp -av patches/$P/$ANDR/provisionals/${FILE}.out/smali/${FAIL} tmp/${FILE}.out/smali/${FAIL} >> "$LOG" || echo "FAILED to cp $FAIL" >> ${JAR}.log
1221 SID=(${SID[@]} $FAIL)
1222 done
1224 [[ `grep FAILED ${JAR}.log` != "" ]] && print_error "failed $NAME.patch"
1225 garbage tmp/${FILE}.out
1226 if [ -f patches/$P/$A/$R/$B/${JAR}.sh ]; then
1227 printtask "... apply $JAR.sh ..."
1228 . patches/$P/$A/$R/$B/${JAR}.sh 2>&1 > ${JAR}.log
1229 cat ${JAR}.log | tee -a "$LOG"
1231 done
1233 [[ -n ${APKS[@]} ]] && printtask "### apk patch $P/$A/$R/$B ###"
1234 for FILE in ${APKS[@]}; do
1235 APK=${FILE##*/}
1236 if [ -d "tmp/${FILE}.out" ] ; then
1237 printtask "... apply $APK.patch ..."
1238 patch -Nls -p2 -d tmp/${FILE}.out < $PARB/${APK}.patch 2>&1 >> ${APK}.log
1239 cat ${APK}.log | tee -a "$LOG"
1240 [[ `grep FAILED ${APK}.log` != "" ]] && apk_check
1241 garbage tmp/${FILE}.out
1242 else
1243 echo "No $APK in your ROM. Not able to patch this file."
1244 echo "## No $APK in ROM ###" >> "$LOG"
1246 done
1247 [[ -n ${IMGS[@]} ]] && printtask "### img patch $P/$A/$R/$B ###"
1248 for FILE in ${IMGS[@]}; do
1249 IMG=${FILE##*/}
1250 printtask "... applying $IMG.patch ..."
1251 patch -Nls -p1 -d boot/ramdisk < $PARB/${IMG}.patch >> "$LOG" || print_error "failed patching $FILE"
1252 done
1254 [[ -n ${TXTS[@]} ]] && printtask "### text patch $P/$A/$R/$B ###"
1255 for FILE in ${TXTS[@]}; do
1256 TXT=${FILE##*/}
1257 if [[ -f $PARB/${TXT}.patch ]]; then
1258 printtask "... apply $TXT.patch ..."
1259 patch -Nls -p2 -d system/ < $PARB/${TXT}.patch 2>&1 > ${TXT}.log
1260 #cat ${TXT}.log | tee -a "$LOG"
1261 [[ `grep FAILED ${TXT}.log` != "" ]] && print_error "failed $TXT.patch"
1263 if [[ -f $PAR/${TXT}.awk ]]; then
1264 printtask "... apply $TXT.awk ..."
1265 awk -f $PAR/${TXT}.awk $FILE > text || print_error "failed $TXT.awk"
1266 mv text $FILE
1268 if [[ -f $PAR/${TXT}.sed ]]; then
1269 printtask "... apply $TXT.sed ..."
1270 sed -f $PAR/${TXT}.sed $FILE > text || print_error "failed $TXT.sed"
1271 mv text $FILE
1273 if [[ -f $PAR/${TXT}.sh ]]; then
1274 printtask "... apply $TXT.sh ..."
1275 . $PAR/${TXT}.sh 2>&1 >> ${TXT}.log || print_error "failed $TXT.sh"
1277 garbage system/
1278 done
1279 done
1281 # Device specific scripts- Placement is up-for-review
1282 if [ -f patches/devices/$DID/$DID.sh ]; then
1283 . patches/devices/$DID/$DID.sh
1285 # Replace updater-script for CM7-- Testing
1286 if [ "$ANDR" == "gingerbread" ]; then
1287 replace_updater
1289 # Rebuilding system files
1291 [[ -n ${JID[@]} ]] && printtask "### rebuild jar ###"
1292 for FILE in ${JID[@]}; do
1293 JAR=${FILE##*/}
1294 printtask "... rebuild $JAR ..."
1295 java -Xmx512M -jar smali.jar -a $API tmp/${FILE}.out/smali -o tmp/${FILE}.out/classes.dex >> "$LOG" 2>> "$LOG"
1296 [ -f tmp/${FILE}.out/classes.dex ] || smali_error "failed compiling $JAR !!!"
1297 jar -ufv ${FILE} -C tmp/${FILE}.out/ classes.dex >> "$LOG" 2>> "$LOG"
1298 if [ $FILE == "system/framework/framework.jar" ]; then
1299 jar -ufv ${FILE} -C tmp/${FILE}.out/ preloaded-classes >> "$LOG" 2>> "$LOG"
1301 done
1303 [[ -n ${AID[@]} ]] && printtask "### rebuild apk ###"
1304 for FILE in ${AID[@]}; do
1305 APK=${FILE##*/}
1306 if [ -d tmp/${FILE}.out ]; then
1307 printtask "... rebuild $APK ..."
1308 java -jar apktool.jar b tmp/${FILE}.out >> "$LOG" 2>> "$LOG" || print_error "failed compiling $FILE !!!"
1309 jar -uvf $FILE -C tmp/${FILE}.out/build/apk/ . > /dev/null 2>> "$LOG"
1311 done
1313 [[ -n ${IID[@]} ]] && printtask "### rebuild img ###"
1314 for FILE in ${IID[@]}; do
1315 printtask "### rebuild $FILE ###"
1316 case $FILE in
1317 boot.img)
1318 # Rebuilding boot.img
1319 cd boot
1320 printtask "... rebuilding ramdisk ..."
1321 ./mkbootfs$EXE ./ramdisk | gzip > ramdisk-new.gz
1323 printtask "... composing boot.img ..."
1324 BASE=$(cat boot.img-base)
1325 # hex to decimal in cygwin prefixing "0x" w/ C arithmetic
1326 PGSIZE=$((${PGFORM}$(cat boot.img-pagesize)))
1327 CMDLINE=$(cat boot.img-cmdline)
1328 echo "cmdline = no_console_suspend=1 console=null $CMDLINE" >> "$LOG"
1329 echo "pagesize = $PGSIZE" >> "$LOG"
1330 echo "base = $BASE" >> "$LOG"
1331 printtask "... rebuilding boot.img ..."
1332 ./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"
1333 cd ..
1336 print_error "cannot process $FILE"
1338 esac
1339 done
1341 printtask "### create update.zip ###"
1342 jar -cfv tmp.zip ${IID[@]} ${JID[@]} ${AID[@]} ${CID[@]} ${TID[@]} META-INF >> "$LOG" 2>> "$LOG"
1343 java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip update.zip 2>> "$LOG"
1345 \mv restore.zip update.zip ..
1346 echo "### finished ###"
1347 echo "flash update.zip to install the modified"
1348 echo "flash restore.zip to restore the original"
1350 # add announcement- optional.
1351 for P in ${PID[@]}; do
1352 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1353 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1354 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1355 if [ -f patches/$P/$A/$R/$B/README.txt ]; then
1356 cat patches/$P/$A/$R/$B/README.txt
1357 elif [ -f patches/$P/$A/$R/README.txt ]; then
1358 cat patches/$P/$A/$R/README.txt
1359 elif [ -f patches/$P/$A/README.txt ]; then
1360 cat patches/$P/$A/README.txt
1362 done
1364 cd ..
1365 \rm -rf "$TEMP"