Update.zip renamed; Buildquery always runs; Bad $BID gets error
[auto-patcher.git] / auto_patcher
blob619cce56e5e86c59d955cd7694c75ce05a397840
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 PID="openpdroid,3gdongle" # default example
114 brief_help
117 brief_help () {
118 echo " usage: ./auto_patcher <ROM> <MODS> <ROMTYPE>"
119 echo " example: ./auto_patcher CM10.zip $PID cm"
120 echo ""
121 echo "Use ./auto_patcher -h for the help menu"
122 echo ""
123 cleanup
124 exit
127 usage_help () {
128 PID=mods
129 mods_display
130 echo "Multiple MODS can be combined by separating them with a comma and NO SPACES!!!"
131 echo ""
132 echo " usage: ./auto_patcher <ROM> <MODS> <ROMTYPE>"
133 echo ""
134 echo " example: ./auto_patcher CM10.zip openpdroid,3gdongle cm"
135 echo ""
136 usage_more_help
139 usage_more_help () {
140 echo "* press 'q' available patches or CTRL-c to quit the help menu *"
143 display_help () {
144 cd patches
145 echo ""
146 echo "AVAILABLE PATCHES"
147 echo ""
148 echo "*******************************************************************"
149 echo "Note: There are ONLY 4 ROMTYPES: [pa, cm, aokp, and aosp]."
150 echo ""
151 find -H * \( -name aokp -o -name cm -o -name aosp -o -name pa -o -name all \) -prune | column -c 75
152 echo ""
153 echo "!!! Do not put Android Version number on command line !!!!"
154 echo "*****************************************************************"
155 echo "Specific auto_patcher script options"
156 echo " ./auto_patcher -h [mods] Lists mods"
157 echo " -h [<MODNAME>] Specific <MOD> info"
158 echo " -h [advanced] Advanced usage+lists all available patch dates"
159 echo ""
160 cleanup
161 exit
164 romtype_help () {
165 # From rom_error (bad romtype) and date_error (patch date w/o specifying romtype)
166 echo ""
167 echo "!!!There are only four supported ROMTYPES: 1) cm 2) aokp 3) aosp 4) pa"
168 echo ""
169 echo "Find out which of the above ROMTYPES your rom is based on and try again!"
170 echo "**********************************************"
171 echo ""
172 cleanup
173 brief_help
176 advanced_help () {
177 echo ""
178 echo "The Auto-Patcher Advanced Usage"
179 echo "*********************************"
180 echo ""
181 echo "For those of you determined to try everything..."
182 echo ""
183 echo "You can also try adding a patch date as a final argument."
184 echo ""
185 echo " ./auto_patcher <ROM> <MOD> <ROMTYPE> <DATE>"
186 echo ""
187 echo "Please note: There are only four ROMTYPES: {pa, aokp, aosp and cm}"
188 echo " -The various appellations after that are for internal use only!"
189 echo ""
190 echo "The Auto-Patcher has a pretty great rom probe, specifying the date is"
191 echo " deprecated...you don't need to, we promise."
192 echo ""
195 cleanup () {
196 [ -d "$TEMP" ] && \rm -rf "$TEMP"
199 garbage () {
200 unset GARBAGE
201 GARBAGE=($(find $@ -name "*.orig")) && rm -rf ${GARBAGE[@]} && echo "GARBAGE= ${GARBAGE[@]}" >> "$LOG"
202 GARBAGE=($(find $@ -name "*.rej")) && rm -rf ${GARBAGE[@]} && echo "GARBAGE= ${GARBAGE[@]}" >> "$LOG"
206 print_error () {
207 # General purpose error. Used for errors in main, as opposed to probe or set-up.
208 echo ""
209 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
210 printtask "!!! error: $@"
211 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
212 echo ""
213 brief_help
216 smali_error () {
217 # Smali binary error. Problem often goes away on second run.
218 echo ""
219 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
220 printtask "!!! error: $@"
221 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
222 echo ""
223 if [[ `grep 'method index is too large' "$LOG"` != "" ]]; then
224 printtask "!!! Problem with method cap !!!"
225 printtask "... attempting fix ..."
226 . patches/common/framework.jar.sh 2>&1 > ${JAR}.log
227 printtask "... rebuild framework.jar ..."
228 java -Xmx512M -jar smali.jar -a $API tmp/${FILE}.out/smali -o tmp/${FILE}.out/classes.dex >> "$LOG" 2>> "$LOG"
229 [ -f tmp/${FILE}.out/classes.dex ] || print_error "Could not resolve method cap issue- please submit log"
230 else
231 printtask "!!! This error is generally due to an unknown bug in the smali binary!"
232 echo "In our experience, it goes away if you run the patcher a second time."
233 echo " Please run the Auto-Patcher with the same command once again."
234 echo ""
235 echo "If after the third attempt the same thing happens,"
236 echo " please upload your logfile to our support thread!"
237 echo ""
238 cleanup
239 exit
243 mismatch_error () {
244 # Function that exposes attempts to apply a mod to an upsupported Android version
245 echo ""
246 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
247 printtask "!!! error: $@"
248 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
249 echo ""
250 cleanup
251 brief_help
254 date_error () {
255 # Remind users to include a romtype if they are going to specify a patch date
256 echo ""
257 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
258 printtask "!!! error: $@"
259 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
260 echo ""
261 echo "Please put a ROMTYPE before the patch date and run again!!"
262 romtype_help
265 rom_error () {
266 # For when an unsupported romtype is manually entered on the command-line
267 echo ""
268 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
269 printtask "!!! error: $@"
270 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
271 romtype_help
274 conflict_error () {
275 # For conflicting packages
276 echo ""
277 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
278 printtask "!!! error: $@"
279 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
280 cleanup
281 PID=mods
282 mods_info
285 misspatch_error () {
286 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
287 printtask "!! error: $@ "
288 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
289 echo ""
290 printtask "!! The Auto-Patcher could not find its patches and/or tools!"
291 echo ""
292 echo "* Did you run ./batch.sh first?"
293 echo ""
294 echo "The patch_patches.tgz and patch_tools.tgz need to be in this directory,"
295 echo " one way or another..."
296 echo ""
297 cleanup
298 brief_help
301 misstools_error () {
302 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
303 printtask "!! error: $@ "
304 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
305 printtask "Your set-up is missing a dependency."
306 echo "We require JDK, patch and cpio."
307 echo ""
308 echo ""
309 echo "Each distro is different"
310 echo "but you must ensure you have them all installed and try again."
311 echo ""
312 cleanup
313 brief_help
316 printtask () {
317 echo "" >> "$LOG"
318 echo $@ | tee -a "$LOG"
321 copyfailed () {
322 echo ""
323 printtask "File for which patching failed:"
324 printtask "---------------------------------------------"
325 echo ""
326 printtask "${FAIL##*/}"
327 echo ""
328 echo "---------------------------------------------"
329 echo ""
330 echo "We can try to add a premade copy of those files."
331 echo "This sometimes works."
332 echo ""
333 echo "But IT MAY NOT WORK!!!"
334 echo ""
335 echo ""
336 askconsent && return 0 || return 1
339 askconsent () {
340 sleep 1
341 echo -n "Do you want to proceed ? (YES/no) "
342 read PROCEED
343 echo "askconsent final = ${PROCEED}: for $FAIL" >> "$LOG"
344 case $PROCEED in
345 [Yy] | [Yy][Ee][Ss])
346 return 0; # successful:
347 echo "*** You (or ApG) have elected to use a prepatched copy of $FAIL ***" >> "$LOG"
350 return 1; # error
351 echo "*** You have declined to insert $FAIL by not answering 'yes' at the prompt. ***" >> "$LOG"
353 esac
356 replace_updater () {
358 # Function for devices that use SDcard installs. Also to be tested for CM7
359 # since CM7 seems to use an updater-script that wipes EMMC. Testing
361 \rm $UPDATER_LOC/$UPDS
362 \cp patches/common/$UPDATER_LOC/$UPDS $UPDATER_LOC
363 echo "run_program(\"/sbin/busybox\", \"umount\", \"/system\");" >> UPDATE.txt
364 cat UPDATE.txt >> $UPDATER_LOC/$UPDS
365 echo ""
366 echo "New updater-script being used:" >> "$LOG"
367 echo "-----------------------------" >> "$LOG"
368 cat $UPDATER_LOC/$UPDS >> "$LOG"
371 abspath () {
372 case `uname -s` in
373 CYGWIN*)
374 echo $(cygpath -ua "$1")
376 Darwin)
377 #[[ $(echo $1 | awk '/^\//') == $1 ]] && echo "$1" || echo "$PWD/$1"
378 [[ ${1:0:1} == "/" ]] && echo "$1" || echo "$PWD/$1"
380 Linux)
381 echo $(readlink -f "$1")
384 if [[ ${1:0:1} == "/" ]]; then
385 echo "$1"
386 elif [[ ${1:0:2} == "./" ]]; then
387 echo "$PWD/${1:2}"
388 else
389 echo "$PWD/$1"
392 esac
395 mods_display () {
396 echo ""
397 echo "The Auto-Patcher $VERSION"
398 echo "*******************************"
399 echo ""
400 echo "The available mods are"
401 echo "****************************************************"
402 echo "* pdroid openpdroid voice v6supercharger *"
403 echo "* voice insecure secure external_internal *"
404 echo "* tabletUI 3gdongle pd2.0 *"
405 echo "****************************************************"
406 echo ""
407 echo "To find out more about any mod, simply enter:"
408 echo " ./auto_patcher -h <MODNAME>"
409 echo ""
410 cleanup
413 mods_info () {
414 DEPENDENCY="None" # default
415 DEV="Unknown" # default
416 CEILING=$CURRENT_ANDROID # Default is that everything works...we'll see.
417 case $PID in
418 mods)
419 mods_display
420 exit
422 auto*)
423 echo ""
424 echo "**************************************"
425 echo "The Auto-Patcher ate a kitten once..."
426 echo "**************************************"
427 printusage_help
429 advanced)
430 cd patches/
431 (advanced_help && find -H * -name 2012*) | more -d
432 echo ""
433 brief_help
435 voice)
436 FLOOR=4.0.0
437 DESC="Use on wifi-only tablets to have the software register as 'voice-enabled'. Allows VOIP like Google Voice to function."
439 v6supercharger)
440 FLOOR=4.0.0
441 CEILING=4.2.1
442 DESC="A memory-management tool. It requires smali edits for Android roms 4.0+."
443 DESC1="The Auto-Patcher applies all 56 edits recommended by the dev."
444 DEV="Zeppelinrox"
445 DEPENDENCY="The V6 Supercharger Script. Get it at http://forum.xda-developers.com/showthread.php?t=991276/"
447 pdroid)
448 FLOOR=2.3.7
449 CEILING=4.1.2
450 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."
451 DESC1="(It's the 'openpdroid' mod within the Auto-Patcher)."
452 DEV="Svyat"
453 DEPENDENCY="The Pdroid app. You can get it at http://forum.xda-developers.com/showthread.php?t=1923576"
455 pd2.0)
456 FLOOR=4.1.2
457 CEILING=4.1.2
458 DESC="An expansion of the PDroid application/framework."
459 DEV="CollegeDev"
460 DEPENDENCY="The free PDroid2.0 app available at http://forum.xda-developers.com/showthread.php?t=1923576"
462 openpdroid)
463 FLOOR=4.1.2
464 CEILING=4.2.1
465 DESC="A fork of the open-source PDroid and Pdroid2.0 framework."
466 DEV="FFU5y/wbedard/mateorod/Community"
467 DEPENDENCY="The PDroidManager app freely available from Google Play or http://forum.xda-developers.com/showthread.php?t=1994860"
469 opendroid)
470 echo ""
471 echo "No mod named 'opendroid'. You probably mean 'openpdroid'. Try again."
472 PID="mods"
473 mods_info
475 external_internal)
476 FLOOR=2.3.3
477 DESC="Swap internal and external storage."
479 insecure)
480 FLOOR=2.3.3
481 DESC="Make any boot.img insecure and allow remount as well as adb push/pull of system files. True root."
483 secure)
484 FLOOR=2.3.3
485 DESC="Make any boot.img secure."
487 3gdongle)
488 FLOOR=4.1.0
489 CEILING=4.2.1
490 DESC="Allows 3gdongles to work on wifi tablets w/o 3rd party applications."
491 DEV="trevd"
492 DEPENDENCY="None, but read the troubleshooting guide at http://forum.xda-developers.com/showthread.php?t=1798631"
494 tabletUI)
495 FLOOR=4.1.0
496 CEILING=4.1.2
497 DESC="Changes the user interface of Phones and Phablets to the popular Tablet UI."
498 DEV="barmullio"
500 esac
501 # strip decimals from android version (i.e. 2.3.7 becomes 237) so we can do math
502 NVID=${VID//[.]/}
503 COMPATF=${FLOOR//[.]/}
504 COMPATC=${CEILING//[.]/}
507 apk_check () {
508 if [ -f patches/$P/$A/$R/$B/$FILE ]; then
509 echo "... Patching $APK failed, but we will copy over a prepatched file ..."
510 \cp -av patches/$P/$A/$R/$B/$FILE $FILE >> "$LOG"
511 else
512 print_error "failed patching $APK!!!"
515 compat_check () {
516 for P in ${PID[@]}; do
517 mods_info
518 if [[ "$NVID" -lt "$COMPAT" ]]; then
519 mismatch_error "Your Android $VID rom is too old! The minimum for $P is Android $FLOOR!"
521 if [[ "$NVID" -gt "$COMPATC" ]]; then
522 mismatch_error "Sorry, $P has not been made available for Android $VID yet!"
524 done
526 extpath () {
527 case `uname -s` in
528 CYGWIN*)
529 echo $(cygpath -da "$1")
532 echo $(abspath "$1")
534 esac
537 #contains () { for e in "${@:2}"; do [[ "$e" = "$1" ]] && return 0; done; return 1; }
539 parse () { echo "${1%%_*}"; }
541 getbuildprop () {
542 if [ -f system/build.prop ]; then
543 result=(`grep $1 system/build.prop | tr -d '\r' | tr '=' ' '`)
544 echo "${result[1]}"
545 else
546 echo ""
551 aosp_mod_check() {
552 jar -xvf "$ROMX" system/framework/framework2.jar >> $LOG
553 if [ -s system/framework/framework2.jar ]; then
554 ever_check
555 else
556 AOSP=aosp-jb
560 ever_check() {
561 MID=$(getbuildprop ro.build.romversion)
562 if [[ "$MID" == "Evervolv"* ]]; then
563 AOSP=aosp-ever
564 else
565 MID=$(getbuildprop ro.build.display.id)
566 if [[ "$MID" == "ev"* ]]; then
567 AOSP=aosp-ever
568 else
569 AOSP=aosp-mod
574 pa_check() {
575 CMID=$(getbuildprop ro.modversion)
576 PAID=$(getbuildprop ro.pa.version)
577 MID=$(getbuildprop ro.build.display.id)
578 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
579 DID=$(getbuildprop ro.product.device)
580 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
581 if [[ -n $PAID ]]; then
582 RID=pa
583 else
584 case $CMID in
585 [Pp][Aa]*)
586 RID=pa;
589 RID=cm;
591 esac
595 proberom () {
596 VID=$(getbuildprop ro.build.version.release)
597 if [ ${#VID} -lt 4 ]; then # in case of non-standard versioning in build.prop (defy!)
598 ANDR=$VID
599 else
600 ANDR="${VID%.*}" # Cut to 1 significant digit to cover specific range or release.
602 if [ "$ANDR" == "2.3" ]; then
603 FLAVR=gingerbread
604 API=10
605 RID=cm;
606 elif [ "$ANDR" == "4.0" ]; then
607 FLAVR=ics
608 API=15
609 MID=$(getbuildprop ro.rommanager.developerid)
610 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.modversion))
611 DID=$(getbuildprop ro.product.device)
612 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
614 case "$MID" in
615 pa|cm9|cm|cyanogenmod*)
616 RID=cm;
618 aokp|teamkang)
619 RID=aokp;
621 aosp*)
622 RID=aosp;
625 echo "!!! $MID is not supported yet, trying generic latest !!!"
627 esac
628 elif [ "$ANDR" == "4.1" ]; then
629 FLAVR=jellybean
630 API=16
631 CMID=$(getbuildprop ro.cm.version)
632 if [[ -n $CMID ]]; then
633 pa_check
634 else
635 MID=$(getbuildprop ro.build.display.id)
636 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
637 DID=$(getbuildprop ro.product.device)
638 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
639 case "$MID" in
640 cm10|cm*|cyanogenmod*)
641 RID=cm;
643 aokp*|teamkang)
644 RID=aokp;
646 pa*)
647 RID=pa;
649 ev*)
650 RID=aosp-ever;
653 RID=`aosp_mod_check`;
655 esac
657 elif [ "$ANDR" == "4.2" ]; then
658 FLAVR=jellybean
659 API=17
660 CMID=$(getbuildprop ro.cm.version)
661 MID=$(getbuildprop ro.build.display.id)
662 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
663 DID=$(getbuildprop ro.product.device)
664 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
666 case "$MID" in
667 cm10|cm*|cyanogenmod*)
668 RID=cm;
670 aokp*|teamkang)
671 RID=aokp;
673 pa*) # Defaults to cm for now, since there is a chance we can patch forks
674 echo""
675 sleep 1
676 echo "There is no pa patch for 4.2 at this time..."
677 sleep 1
678 echo " b/c the paranoid Android source for 4.2 is still closed."
679 sleep 2
680 echo ""
681 printtask "### The Auto-Patcher is going to try the 'cm' patches... ###"
682 sleep 1
683 echo ""
684 echo " you might also try manually applying the 'aosp' patches."
685 sleep 2
686 echo ""
687 echo "Try ./auto_patcher -h for help if you need it."
688 sleep 3
689 echo ""
690 RID=cm;
693 RID=aosp;
695 esac
696 else
697 print_error "unknown ROM version $VID"
699 echo "... result of ROM check: version= $VID rom= $RID ..."
702 # Advanced build date query
703 # This should set the patch date automatically.
705 build_query() {
706 UTC=$(getbuildprop ro.build.date.utc)
708 # Difference in how OS X and Linux/Cygwin handles 'date' utility
709 case `uname -s` in
710 [Dd]arwin)
711 BDID=`date -r $UTC +%Y%m%d`
712 echo "#### Darwin Build Query used ####" >> "$LOG"
715 BDID=`date -d "1970-01-01 UTC $UTC seconds" +"%Y%m%d"`
716 echo "#### Standard Build Query ####" >> "$LOG"
718 esac
720 # If patch date is specified on CLI, use that patch date
721 if [ $# -gt 3 ]; then
722 BID=${4//,/ };
723 BDID=$BID
724 else
725 case $ANDR in
726 gingerbread)
727 # CM7 roms do not have UTC time stamp- so no build query.
728 BID=latest;
729 echo "*** CM7 roms default to latest patches. If using an older rom ***"
730 echo "*** specify patch date on command line. Use -h to see available patches ***"
733 for P in ${PID[@]}; do
734 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
735 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
736 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
737 PAR=patches/$P/$A/$R
738 PARB=patches/$P/$A/$R/$B
739 DATES=`ls patches/$P/$A/$R/ | grep '201*'`
740 # Intialize variable - High so as to determine lowest in first loop.
741 BID=20201231
742 # find earliest available patch date
743 for i in $DATES; do
744 if [[ $i -lt $BID ]]; then
745 BID=$i
747 done
748 # Check if earliest patches are from before build date. Else use earliest
750 # If older than earliest patch set, then find best match
751 if [[ $(($BID-$BDID)) -lt 0 ]]; then
752 for g in $DATES; do
753 # use any patch that matches $UTC
754 if [[ $(($BDID-$g)) -eq 0 ]]; then
755 BID=$g
756 break
757 # Set highest $BID w/o going over $UTC
758 elif [[ $(($BDID-$g)) -gt 0 ]] && [[ $g -gt $BID ]]; then
759 BID=$g
761 done
763 echo "... $PID patch date has been set to: $BID ..."
764 B=$BID
765 break
766 done
768 esac
772 proberil () {
773 RIL=$(getbuildprop ro.telephony.ril_class)
774 [[ -n $RIL ]] && printtask "... result of ROM check: RIL= $RIL"
777 rominfo () {
778 echo "# VER= $VERSION" >> "$LOG"
779 echo "# OS= $OSTYPE ${BIT}bit" >> "$LOG"
780 echo "# VID= $VID" >> "$LOG"
781 echo "# PID= ${PID[@]}" >> "$LOG"
782 echo "# MID= $MID" >> "$LOG"
783 echo "# RID= $RID" >> "$LOG"
784 echo "# ANDR= $ANDR" >> "$LOG"
785 echo "# BDID= $BDID" >> "$LOG"
786 echo "# DID= $DID" >> "$LOG"
787 echo "# BID= $BID" >> "$LOG"
791 if [[ $1 == -h ]]; then
792 if [ $# -gt 1 ]; then
793 PID=$2
794 mods_info
795 echo ""
796 echo "The Auto-Patcher $VERSION by Mateorod and Pastime1971"
797 echo "*************************************************"
798 echo ""
799 echo "Mod Name: $PID"
800 echo ""
801 echo " $DESC"
802 if [[ $((DESC1)) -gt 0 ]]; then # test to see is there is a second DESC line
803 echo "$DESC1"
805 if [[ $((DESC2)) -gt 0 ]]; then
806 echo "$DESC2"
808 echo ""
809 echo "Developer: $DEV"
810 echo "Dependancies: $DEPENDENCY"
811 echo ""
812 echo "Works on ROMs from Android $FLOOR -> $CEILING"
813 echo
814 brief_help
815 exit
819 [[ $# -lt 1 || -z $1 ]] && PID="mods" && mods_info
820 [[ $1 == "-h" ]] && usage_help | less && display_help
822 echo ""
823 echo "The Auto-Patcher $VERSION"
824 echo ""
825 # by pastime1971 and mateorod
827 ROOT=$(abspath `dirname "$0"`)
828 TOOL="$ROOT/patch_tools.tgz"
829 PTCH="$ROOT/patch_patches.tgz"
830 ROM=$(abspath "$1")
831 ROMX=$(extpath "$1")
833 if [[ $OSTYPE == "cygwin" ]]; then
834 EXE=".exe"
835 PGFORM="0x"
838 DATE=`date +%Y%m%d%H%M%S`
839 TEMP=$(abspath ./tmp$DATE)
840 LOG=$(abspath ./log$DATE.txt)
841 #echo $ROOT $TOOL $ROM $TEMP "$LOG"
842 echo "ROOT= $ROOT" >> "$LOG"
843 echo "TOOL= $TOOL" >> "$LOG"
844 echo "ROM= $ROM" >> "$LOG"
845 echo "ROMX= $ROMX" >> "$LOG"
847 \rm -f $RESTORE.zip $UPDATE.zip
849 CHK=$(getconf LONG_BIT)
850 if [[ $CHK = "64" ]]; then
851 BIT=64
852 else [[ $BIT = "32" ]];
853 BIT=32
857 printtask "### verify tools ###"
858 which patch >> "$LOG" || misstools_error "Missing \"patch diff command\""
859 which tar >> "$LOG" || misstools_error "Missing \"tar archive command\""
860 which jar >> "$LOG" || misstools_error "Missing \"jar (JDK)\""
861 which java >> "$LOG" || misstools_error "Missing \"java (JRE)\""
862 which cpio >> "$LOG" || misstools_error "Missing \"cpio archive command\""
863 [ -f "$TOOL" ] || misspatch_error "patch tool is missing"
864 [ -f "$PTCH" ] || misspatch_error "patch patches are missing"
865 printtask "### verify ROM ###"
866 [ -f "$ROM" ] || print_error "Cannot find $ROM"
867 echo "### running $0 $@" >> "$LOG"
868 mkdir "$TEMP"
869 cd "$TEMP"
871 PATH="$TEMP:$PATH"
872 export PATH
873 echo "PATH= $PATH" >> "$LOG"
875 printtask "### unzip patch tools ###"
876 tar xzf "$TOOL" > /dev/null || print_error "failed extracting tools !!!"
878 # Get OS specific tools
879 case `uname -s` in
880 CYGWIN*)
881 \mv cygwin/aapt.exe .
882 \mv cygwin/*.exe boot/
883 \rm -rf cygwin # why? If you want to we can keep/add it to mac/linux, though.
885 [Dd]arwin)
886 \mv mac/aapt .
888 [Ll]inux)
889 \mv linux/aapt .
892 \mv linux/aapt .
894 esac
895 # Ensure aapt permissions - possibly to one day be expanded to all tools in a function.
896 chmod a+x aapt$EXE
898 printtask "### unzip patch patches ###"
899 tar xzf "$PTCH" > /dev/null || print_error "failed extracting patches !!!"
901 # we need build.prop for both RIL probing and ROM probing
902 jar -xvf "$ROMX" system/build.prop 2>> "$LOG" || print_error "failed extracting build.prop from $ROMX !!!"
904 # rom + ril type
905 proberil
906 printtask "### probe rom type ###"
907 proberom
909 # rom type
910 if [ $# -gt 1 ]; then
911 PIT=$2
912 if [[ "$PIT" = "-h" ]]; then
913 display_help
916 if [ $# -gt 2 ]; then
917 RID=$3
918 case "$RID" in
919 cm10|cm*|cyanogenmod*)
921 aokp*|teamkang)
922 RID=aokp;
924 pa*)
925 RID=pa;
927 aosp-ever)
928 RID=aosp-ever;
930 aosp*)
931 case "ANDR" in
932 4.1)
933 RID=`aosp_mod_check`;
936 RID=aosp
938 esac
940 201*)
941 date_error "You must specify ROMTYPE if designating a patch date!!"
944 rom_error "$RID is not a valid ROMTYPE!!"
946 esac
947 echo "... Using $RID patches ..."
948 else
949 echo "... Using results of ROM check ..."
952 # patch type
953 if [ $# -gt 1 ]; then
954 PIL=${2//,/ } # If more than one mod, make string separated by spaces
955 else
956 PIL="pdroid v6supercharger"
957 echo "No mods selected. Defaulting to the v6 and Pdroid, just because we can."
960 PID=(${PIL// / }) # turn string into array
961 COPYPID=("${PID[@]}") # working copy to iterate over
962 MODS_NUMBER=${#COPYPID[@]} # number of elements (mods)
964 if [[ $MODS_NUMBER > 1 ]]; then
965 INDEX=0
966 for p in ${COPYPID[@]}; do
967 if [ "$p" = "pdroid" ] || [ "$p" = "pd2.0" ] ||[ "$p" = "openpdroid" ]; then
968 SPID[0]=$p
969 unset COPYPID["$INDEX"]
970 break
971 else
972 INDEX=$((INDEX + 1))
974 done
975 for p in ${COPYPID[@]}; do
976 if [ "$p" = "pdroid" ] || [ $p = "pd2.0" ] ||[ $p = "openpdroid" ]; then
977 conflict_error "Those mods conflict! Only one pdroid mod at a time!"
978 else
979 i=${#SPID[@]}
980 SPID[i]=$p
981 i+=1
983 done
984 else
985 SPID=${COPYPID[@]}
987 for P in ${PIL[@]}; do
988 [[ ${PID[@]} =~ $P ]] || PID=(${PID[@]} $P)
989 done
991 # Check to make sure selected roms are available for the Android version of patched ROM
992 compat_check
994 # Build date
995 if [ $# -gt 3 ]; then # if a date is specified on command line...
997 # Set date to match argument and ensure that patches with that date exist
998 BID=$4
999 [ -d patches/$P/$A/$R/$BID ] || print_error "No $P patches for $RID on $BID!! Try the help menu!!"
1001 # Run build_query- this overrides the above but gets useful info
1002 build_query
1003 # Reset patch date to argument
1004 BID=$4
1005 echo "... $PID patch date set manually to: $BID ..."
1006 else
1007 build_query # if no date specified, use one from build_query
1010 # echo ROM info
1011 rominfo
1013 # I think I finally may have rendered this VERY long if statement obsolete...CHECK!
1014 if [[ ( "$PID" == "-h" || "$RID" == "-h" || "$BID" == "-h" ) ]]; then
1015 #Although this placement may be perfect for romfilter. although it throws the scheme...
1016 display_help
1018 #Begin cycle
1020 for P in ${PID[@]}; do
1021 [ -d patches/$P ] || print_error "$P is not available"
1022 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1023 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1024 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1026 unset FILES
1027 [ -f patches/$P/files.txt ] && FILES=$(cat patches/$P/files.txt)
1028 [ -f patches/$P/$A/files.txt ] && FILES=$(cat patches/$P/$A/files.txt)
1029 [ -f patches/$P/$A/$R/files.txt ] && FILES=$(cat patches/$P/$A/$R/files.txt)
1030 [ -f patches/$P/$A/$R/$B/files.txt ] && FILES=$(cat patches/$P/$A/$R/$B/files.txt)
1031 for FILE in ${FILES[@]}; do
1032 case "$FILE" in
1033 +system/*)
1034 [[ ${CID[@]} =~ ${FILE:1} ]] && print_error "${FILE:1} is already being copied" || CID=(${CID[@]} ${FILE:1})
1036 -system/*)
1037 [[ ${EID[@]} =~ ${FILE:1} ]] || EID=(${EID[@]} ${FILE:1})
1039 system/*.jar)
1040 [[ ${JID[@]} =~ $FILE ]] || JID=(${JID[@]} $FILE)
1041 echo "set_perm(0, 0, 0644, \"/$FILE\");" >> UPDATE.txt
1043 system/*.apk)
1044 [[ ${AID[@]} =~ $FILE ]] || AID=(${AID[@]} $FILE)
1045 echo "set_perm(0, 0, 0644, \"/$FILE\");" >> UPDATE.txt
1047 *.img)
1048 [[ ${IID[@]} =~ $FILE ]] || IID=(${IID[@]} $FILE)
1050 system/*)
1051 [[ ${TID[@]} =~ $FILE ]] || TID=(${TID[@]} $FILE)
1053 esac
1054 done
1055 done
1056 echo "### DELETE FILES= ${EID[@]}" >> "$LOG"
1057 echo "### COPY FILES= ${CID[@]}" >> "$LOG"
1058 echo "### JAR FILES= ${JID[@]}" >> "$LOG"
1059 echo "### APK FILES= ${AID[@]}" >> "$LOG"
1060 echo "### IMG FILES= ${IID[@]}" >> "$LOG"
1061 echo "### TXT FILES= ${TID[@]}" >> "$LOG"
1063 # extract system files
1064 printtask "### unzip rom ###"
1065 jar -xvf "$ROMX" ${JID[@]} ${AID[@]} ${IID[@]} ${TID[@]} 2>> "$LOG" || print_error "failed extracting ${JID[@]} ${AID[@]} ${IID[@]} from $ROMX !!!"
1068 # Update/Restore.zip scripts and prep
1069 printtask "### create updater script ###"
1070 UPDATER_LOC=META-INF/com/google/android
1071 UPDS=updater-script
1072 UPDATE="update-$RID-$BDID-${PIL// /-}"
1073 RESTORE="restore-$RID-$BDID"
1075 jar -xvf "$ROMX" $UPDATER_LOC/$UPDS $UPDATER_LOC/update-binary
1076 jar -xvf "$ROMX" $UPDATER_LOC/update-binary-installer 1> /dev/null 2> /dev/null
1078 # Determine Installer- Aroma or ClockworkMod
1079 if [ -f $UPDATER_LOC/update-binary-installer ]; then
1080 printtask "... using Aroma installer ..."
1081 \mv $UPDATER_LOC/update-binary-installer $UPDATER_LOC/update-binary
1082 else
1083 printtask "... using Clockworkmod installer ..."
1086 # Create updater scripts
1087 cat $UPDATER_LOC/$UPDS | grep ^mount | grep "/system" | head -n 1 > $UPDS
1088 [ -s $UPDS ] || echo "run_program(\"/sbin/busybox\", \"mount\", \"/system\");" > $UPDS
1089 # restore the original
1090 for FILE in ${EID[@]}; do
1091 jar -xvf "$ROMX" $FILE 2> /dev/null || printtask "!!! warning $FILE cannot be restored !!!"
1092 done
1093 # replace with the original or delete it
1094 for FILE in ${CID[@]}; do
1095 jar -xvf "$ROMX" $FILE 2> /dev/null || echo "delete(\"/$FILE\");" >> $UPDS
1096 done
1097 echo "package_extract_dir(\"system\", \"/system\");" >> $UPDS
1098 # permission management for files that need specific perms
1099 cat $UPDATER_LOC/$UPDS | grep set_perm | grep "/system" >> $UPDS
1100 for P in ${PID[@]}; do
1101 if [ -s patches/$P/$A/set_perm.txt ]; then
1102 echo "...setting permissions..."
1103 cat patches/$P/$A/set_perm.txt >> $UPDS
1105 done
1106 cat $UPDATER_LOC/$UPDS | grep ^unmount | grep "/system" | head -n 1 >> $UPDS
1107 [[ ${IID[@]} =~ boot.img ]] && cat $UPDATER_LOC/$UPDS | grep "boot.img" >> $UPDS
1108 cat $UPDS > $UPDATER_LOC/$UPDS
1109 echo "# generated $UPDS" >> "$LOG"
1110 cat $UPDS >> "$LOG"
1112 printtask "### create restore.zip ###"
1113 jar -cvf tmp.zip ${JID[@]} ${AID[@]} ${IID[@]} META-INF > /dev/null 2>> "$LOG"
1114 java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip signed.zip 2>> "$LOG"
1115 \mv signed.zip $RESTORE.zip
1116 \rm -f tmp.zip
1119 # Begin patching process
1121 # decompile system files
1122 printtask "### decompile system files ###"
1123 for FILE in ${JID[@]}; do
1124 JAR=${FILE##*/}
1125 printtask "... decompile $JAR ..."
1126 java -jar baksmali.jar -b -a $API -o tmp/${FILE}.out/smali ${FILE} >> "$LOG" 2>> "$LOG"
1127 if [ $FILE == "system/framework/framework.jar" ]; then
1128 printtask "... extract preloaded-classes ..."
1129 jar -xvf ${FILE} preloaded-classes >> "$LOG" 2>> "$LOG"
1130 \mv preloaded-classes tmp/${FILE}.out/
1132 done
1134 # install framework-files for APK...
1135 if [ ${#AID[@]} -gt 0 ]; then
1136 jar -xvf "$ROMX" system/framework/framework-res.apk >> "$LOG"
1137 printtask "... installing framework files ..."
1138 java -jar apktool.jar if system/framework/framework-res.apk
1139 # Decompile APKs
1140 for FILE in ${AID[@]}; do
1141 APK=${FILE##*/}
1142 if [ -f $FILE ]; then
1143 printtask "... decompile $APK ..."
1144 java -jar apktool.jar d -f $FILE tmp/$FILE.out
1146 done
1149 # Unpack image files {boot.img only so far...}
1150 for FILE in ${IID[@]}; do
1151 printtask "### unpacking $FILE ###"
1152 case "$FILE" in
1153 boot.img)
1154 if [ -f boot.img ]; then
1155 cd boot
1156 ./unpackbootimg$EXE -i ../boot.img >> "$LOG" 2>> "$LOG"
1157 mkdir ramdisk
1158 cd ramdisk
1159 gzip -dc ../boot.img-ramdisk.gz | cpio -i >> "$LOG" 2>> "$LOG"
1160 cd ../../
1161 else
1162 print_error "A mod needs to patch boot.img! This rom does not contains boot.img."
1166 print_error "cannot process $FILE"
1168 esac
1169 done
1171 # apply system modification
1173 for P in ${PID[@]}; do
1174 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1175 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1176 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1177 PAR=patches/$P/$A/$R
1178 PARB=patches/$P/$A/$R/$B
1180 unset FILES COPY DELS JARS APKS IMGS TXTS
1181 [ -f patches/$P/files.txt ] && FILES=$(cat patches/$P/files.txt)
1182 [ -f patches/$P/$A/files.txt ] && FILES=$(cat patches/$P/$A/files.txt)
1183 [ -f patches/$P/$A/$R/files.txt ] && FILES=$(cat patches/$P/$A/$R/files.txt)
1184 [ -f patches/$P/$A/$R/$B/files.txt ] && FILES=$(cat patches/$P/$A/$R/$B/files.txt)
1185 for FILE in ${FILES[@]}; do
1186 case $FILE in
1187 +system/*)
1188 COPY=(${COPY[@]} ${FILE:1})
1190 -system/*)
1191 DELS=(${DELS[@]} ${FILE:1})
1193 system/*.jar)
1194 JARS=(${JARS[@]} $FILE)
1196 system/*.apk)
1197 APKS=(${APKS[@]} $FILE)
1199 *.img)
1200 IMGS=(${IMGS[@]} $FILE)
1202 system/*)
1203 TXTS=(${TXTS[@]} $FILE)
1205 esac
1206 done
1208 [[ -n ${COPY[@]} ]] && printtask "### copy patch $P/$A/$R/$B ###"
1209 for FILE in ${COPY[@]}; do
1210 printtask "... copying $FILE ..."
1211 DEST=${FILE%/*}
1212 mkdir -p ./$DEST
1213 if [ -e patches/$P/$A/$R/$B/$FILE ]; then
1214 [ -e $FILE ] && printtask "... overwriting $FILE from $P ..."
1215 \cp -av patches/$P/$A/$R/$B/$FILE ./$DEST >> "$LOG"
1216 else
1217 print_error "$FILE is missing in the patch. Please upload your logfile to the support thread!"
1219 done
1221 # unconditional smali copying- For particularly troublesome files
1222 [ -f patches/$P/smali.txt ] && SMALI=$(cat patches/$P/smali.txt)
1223 [ -f patches/$P/$A/smali.txt ] && SMALI=$(cat patches/$P/$A/smali.txt)
1224 [ -f patches/$P/$A/$R/smali.txt ] && SMALI=$(cat patches/$P/$A/$R/smali.txt)
1225 [ -f patches/$P/$A/$R/$B/smali.txt ] && SMALI=$(cat patches/$P/$A/$R/$B/smali.txt)
1226 MOVE=${SMALI##*/}
1227 for SMALI in ${SMALI[@]}; do
1228 if [ -f patches/$P/$A/$R/provisionals/$SMALI ]; then
1229 printtask "... overwriting $MOVE ..."
1230 \cp -a patches/$P/$ANDR/$R/provisionals/$SMALI tmp/$SMALI >> "$LOG"
1231 elif [ -f patches/$P/$A/provisionals/$SMALI ]; then
1232 printtask "... overwriting $MOVE ..."
1233 \cp -a patches/$P/$ANDR/provisionals/$SMALI tmp/$SMALI >> "$LOG"
1235 done
1237 [[ -n ${DELS[@]} ]] && printtask "### delete patch $P/$A/$R/$B ###"
1238 for FILE in ${DELS[@]}; do
1239 printtask "... deleting $FILE ..."
1240 \rm -rf ./$FILE
1241 done
1242 [[ -n ${JARS[@]} ]] && printtask "### jar patch $P/$A/$R/$B ###"
1243 for FILE in ${JARS[@]}; do
1244 JAR=${FILE##*/}
1245 NAME=${JAR%.jar}
1246 printtask "... apply $NAME.patch ..."
1247 patch -Nls -p1 -d tmp/${FILE}.out < $PARB/${NAME}.patch 2>&1 > ${JAR}.log
1248 cat ${JAR}.log | tee -a "$LOG"
1249 case "$NAME" in
1250 framework)
1251 # patch preloaded-classes only if a patch exists
1252 if [ -f $PARB/preloaded.patch ]; then
1253 printtask "... apply preloaded.patch ..."
1254 patch -Nls -p1 -d tmp/${FILE}.out < $PARB/preloaded.patch 2>&1 > preloaded.log
1255 cat preloaded.log | tee -a "$LOG"
1256 [[ `grep FAILED preloaded.log` != "" ]] && print_error "failed preloaded.patch"
1260 echo -n "" # do nothing else
1262 esac
1263 # substitute failed smali with provisional (a prepatched smali file)
1264 unset FAILS
1265 FAILS=(`grep FAILED ${JAR}.log | sed -e 's/.*smali\///' | sed -e 's/\.rej//'`)
1266 if [[ -n ${FAILS[@]} ]]; then
1267 printtask "!!! PATCHING FAILED FOR ${FAILS[@]} !!!"
1268 echo "### replace ${FAILS[@]} ###" > ${JAR}.log
1269 for FAIL in ${FAILS[@]}; do
1270 PROVISIONAL="patches/$P/$ANDR/provisionals/${FILE}.out/smali/${FAIL}"
1271 echo "!!! patch error for $FAIL !!!" >> "$LOG"
1272 #cat tmp/$FILE.out/smali/${FAIL}.rej >> "$LOG" # FOR DEBUGGING
1273 [[ ${SID[@]} =~ $FAIL ]] && print_error "$FAIL was already replaced before"
1274 [ -f "$PROVISIONAL" ] || print_error "failed $FAIL in $JAR cannot be remedied"
1275 copyfailed
1276 printtask "... replace $FAIL ..."
1277 \rm -rf tmp/${FILE}.out/smali/${FAIL} tmp/${FILE}.out/smali/${FAIL}.orig tmp/${FILE}.out/smali/${FAIL}.rej
1278 \cp -av "$PROVISIONAL" tmp/${FILE}.out/smali/${FAIL} >> "$LOG"
1279 SID=(${SID[@]} $FAIL)
1280 done
1282 [[ `grep FAILED ${JAR}.log` != "" ]] && print_error "failed $NAME.patch"
1283 garbage tmp/${FILE}.out
1285 # run special $JAR.sh scripts if any JAR needs special attention
1286 if [ -f patches/$P/$A/$R/$B/${JAR}.sh ]; then
1287 printtask "... apply $JAR.sh ..."
1288 . patches/$P/$A/$R/$B/${JAR}.sh 2>&1 > ${JAR}.log
1289 cat ${JAR}.log | tee -a "$LOG"
1291 done
1293 [[ -n ${APKS[@]} ]] && printtask "### apk patch $P/$A/$R/$B ###"
1294 for FILE in ${APKS[@]}; do
1295 APK=${FILE##*/}
1296 if [ -d "tmp/${FILE}.out" ] ; then
1297 printtask "... apply $APK.patch ..."
1298 patch -Nls -p2 -d tmp/${FILE}.out < $PARB/${APK}.patch 2>&1 >> ${APK}.log
1299 cat ${APK}.log | tee -a "$LOG"
1300 [[ `grep FAILED ${APK}.log` != "" ]] && apk_check
1301 garbage tmp/${FILE}.out
1302 else
1303 echo "No $APK in your ROM. Not able to patch this file."
1304 echo "## No $APK in ROM ###" >> "$LOG"
1306 done
1307 [[ -n ${IMGS[@]} ]] && printtask "### img patch $P/$A/$R/$B ###"
1308 for FILE in ${IMGS[@]}; do
1309 IMG=${FILE##*/}
1310 printtask "... applying $IMG.patch ..."
1311 patch -Nls -p1 -d boot/ramdisk < $PARB/${IMG}.patch >> "$LOG" || print_error "failed patching $FILE"
1312 done
1314 # Text Editing Functions --this can really do just about anything. Needs a working restore!
1315 [[ -n ${TXTS[@]} ]] && printtask "### text patch $P/$A/$R/$B ###"
1316 for FILE in ${TXTS[@]}; do
1317 TXT=${FILE##*/}
1318 if [[ -f $PARB/${TXT}.patch ]]; then
1319 printtask "... apply $TXT.patch ..."
1320 patch -Nls -p2 -d system/ < $PARB/${TXT}.patch 2>&1 > ${TXT}.log
1321 #cat ${TXT}.log | tee -a "$LOG"
1322 [[ `grep FAILED ${TXT}.log` != "" ]] && print_error "failed $TXT.patch"
1324 if [[ -f $PAR/${TXT}.awk ]]; then
1325 printtask "... apply $TXT.awk ..."
1326 awk -f $PAR/${TXT}.awk $FILE > text || print_error "failed $TXT.awk"
1327 mv text $FILE
1329 if [[ -f $PAR/${TXT}.sed ]]; then
1330 printtask "... apply $TXT.sed ..."
1331 sed -f $PAR/${TXT}.sed $FILE > text || print_error "failed $TXT.sed"
1332 mv text $FILE
1334 if [[ -f $PAR/${TXT}.sh ]]; then
1335 printtask "... apply $TXT.sh ..."
1336 . $PAR/${TXT}.sh 2>&1 >> ${TXT}.log || print_error "failed $TXT.sh"
1338 garbage system/
1339 done
1340 done
1342 # Device specific scripts- Placement is up-for-review
1343 if [ -f patches/devices/$DID/$DID.sh ]; then
1344 . patches/devices/$DID/$DID.sh
1347 # Replace updater-script for CM7- it formats system -Testing
1348 if [ "$ANDR" == "gingerbread" ]; then
1349 replace_updater
1352 # Rebuilding system files
1354 [[ -n ${JID[@]} ]] && printtask "### rebuild jar ###"
1355 for FILE in ${JID[@]}; do
1356 JAR=${FILE##*/}
1357 printtask "... rebuild $JAR ..."
1358 java -Xmx512M -jar smali.jar -a $API tmp/${FILE}.out/smali -o tmp/${FILE}.out/classes.dex >> "$LOG" 2>> "$LOG"
1359 [ -f tmp/${FILE}.out/classes.dex ] || smali_error "failed compiling $JAR !!!"
1360 jar -ufv ${FILE} -C tmp/${FILE}.out/ classes.dex >> "$LOG" 2>> "$LOG"
1361 if [ $FILE == "system/framework/framework.jar" ]; then
1362 jar -ufv ${FILE} -C tmp/${FILE}.out/ preloaded-classes >> "$LOG" 2>> "$LOG"
1364 done
1366 [[ -n ${AID[@]} ]] && printtask "### rebuild apk ###"
1367 for FILE in ${AID[@]}; do
1368 APK=${FILE##*/}
1369 if [ -d tmp/${FILE}.out ]; then
1370 printtask "... rebuild $APK ..."
1371 java -jar apktool.jar b tmp/${FILE}.out >> "$LOG" 2>> "$LOG" || print_error "failed compiling $FILE !!!"
1372 jar -uvf $FILE -C tmp/${FILE}.out/build/apk/ . > /dev/null 2>> "$LOG"
1374 done
1376 [[ -n ${IID[@]} ]] && printtask "### rebuild img ###"
1377 for FILE in ${IID[@]}; do
1378 printtask "### rebuild $FILE ###"
1379 case $FILE in
1380 boot.img)
1381 # Rebuilding boot.img
1382 cd boot
1383 printtask "... rebuilding ramdisk ..."
1384 ./mkbootfs$EXE ./ramdisk | gzip > ramdisk-new.gz
1386 printtask "... composing boot.img ..."
1387 BASE=$(cat boot.img-base)
1388 # hex to decimal in cygwin prefixing "0x" w/ C arithmetic
1389 PGSIZE=$((${PGFORM}$(cat boot.img-pagesize)))
1390 CMDLINE=$(cat boot.img-cmdline)
1391 echo "cmdline = no_console_suspend=1 console=null $CMDLINE" >> "$LOG"
1392 echo "pagesize = $PGSIZE" >> "$LOG"
1393 echo "base = $BASE" >> "$LOG"
1394 printtask "... rebuilding boot.img ..."
1395 ./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"
1396 cd ..
1399 print_error "cannot process $FILE"
1401 esac
1402 done
1404 printtask "### create $UPDATE.zip ###"
1405 jar -cfv tmp.zip ${IID[@]} ${JID[@]} ${AID[@]} ${CID[@]} ${TID[@]} META-INF >> "$LOG" 2>> "$LOG"
1406 java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip $UPDATE.zip 2>> "$LOG"
1408 \mv $RESTORE.zip $UPDATE.zip ..
1409 echo "### finished ###"
1410 echo "flash $UPDATE.zip to install the patched files"
1411 echo "flash $RESTORE.zip to restore the original system"
1413 # add announcement- optional.
1414 for P in ${PID[@]}; do
1415 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1416 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1417 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1418 if [ -f patches/$P/$A/$R/$B/README.txt ]; then
1419 cat patches/$P/$A/$R/$B/README.txt
1420 elif [ -f patches/$P/$A/$R/README.txt ]; then
1421 cat patches/$P/$A/$R/README.txt
1422 elif [ -f patches/$P/$A/README.txt ]; then
1423 cat patches/$P/$A/README.txt
1425 done
1427 cd ..
1428 \rm -rf "$TEMP"