Add UPDATER_LOC variable
[auto-patcher.git] / auto_patcher
blob71ca759e449350ac4a52bccb55a25f9d99d9c00a
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"
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 debug_help () {
165 # From print_error. For problems decompiling or patching mostly.
166 echo "! please refer to $LOG for any debugging"
167 echo ""
168 echo "! patching failed."
169 echo "! it may be possible to patch $ROM using other patch version"
170 echo ""
171 cleanup
172 printusage_help
175 romtype_help () {
176 # From rom_error (bad romtype) and date_error (patch date w/o specifying romtype)
177 echo ""
178 echo "!!!There are only four supported ROMTYPES: 1) cm 2) aokp 3) aosp 4) pa"
179 echo ""
180 echo "Find out which of the above ROMTYPES your rom is based on and try again!"
181 echo "**********************************************"
182 echo ""
183 cleanup
184 printusage_help
187 advanced_help () {
188 echo ""
189 echo "The Auto-Patcher Advanced Usage"
190 echo "*********************************"
191 echo ""
192 echo "For those of you determined to try everything..."
193 echo ""
194 echo "You can also try adding a patch date as a final argument."
195 echo ""
196 echo " ./auto_patcher <ROM> <MOD> <ROMTYPE> <DATE>"
197 echo ""
198 echo "Please note: There are only four ROMTYPES: {pa, aokp, aosp and cm}"
199 echo " -The various appellations after that are for internal use only!"
200 echo ""
201 echo "The Auto-Patcher has a pretty great rom probe, specifying the date is"
202 echo " deprecated...you don't need to, we promise."
203 echo ""
206 cleanup () {
207 [ -d "$TEMP" ] && \rm -rf "$TEMP"
210 garbage () {
211 unset GARBAGE
212 GARBAGE=($(find $@ -name "*.orig")) && rm -rf ${GARBAGE[@]} && echo "GARBAGE= ${GARBAGE[@]}" >> "$LOG"
213 GARBAGE=($(find $@ -name "*.rej")) && rm -rf ${GARBAGE[@]} && echo "GARBAGE= ${GARBAGE[@]}" >> "$LOG"
217 print_error () {
218 # General purpose error. Used for errors in main, as opposed to probe or set-up.
219 echo ""
220 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
221 printtask "!!! error: $@"
222 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
223 echo ""
224 debug_help
227 smali_error () {
228 # Smali binary error. Problem often goes away on second run.
229 echo ""
230 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
231 printtask "!!! error: $@"
232 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
233 echo ""
234 if [[ `grep 'method index is too large' "$LOG"` != "" ]]; then
235 printtask "!!! Problem with method cap !!!"
236 printtask "... attempting fix ..."
237 . patches/common/framework.jar.sh 2>&1 > ${JAR}.log
238 printtask "... rebuild framework.jar ..."
239 java -Xmx512M -jar smali.jar -a $API tmp/${FILE}.out/smali -o tmp/${FILE}.out/classes.dex >> "$LOG" 2>> "$LOG"
240 [ -f tmp/${FILE}.out/classes.dex ] || print_error "Could not resolve method cap issue- please submit log"
241 else
242 printtask "!!! This error is generally due to an unknown bug in the smali binary!"
243 echo "In our experience, it goes away if you run the patcher a second time."
244 echo " Please run the Auto-Patcher with the same command once again."
245 echo ""
246 echo "If after the third attempt the same thing happens,"
247 echo " please upload your logfile to our support thread!"
248 echo ""
249 cleanup
250 exit
254 mismatch_error () {
255 # Function that exposes attempts to apply a mod to an upsupported Android version
256 echo ""
257 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
258 printtask "!!! error: $@"
259 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
260 echo ""
261 cleanup
262 printusage_help
265 date_error () {
266 # Remind users to include a romtype if they are going to specify a patch date
267 echo ""
268 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
269 printtask "!!! error: $@"
270 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
271 echo ""
272 echo "Please put a ROMTYPE before the patch date and run again!!"
273 romtype_help
276 rom_error () {
277 # For when an unsupported romtype is manually entered on the command-line
278 echo ""
279 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
280 printtask "!!! error: $@"
281 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
282 romtype_help
285 conflict_error () {
286 # For conflicting packages
287 echo ""
288 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
289 printtask "!!! error: $@"
290 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
291 cleanup
292 PID=mods
293 mods_info
296 misspatch_error () {
297 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
298 printtask "!! error: $@ "
299 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
300 echo ""
301 printtask "!! The Auto-Patcher could not find its patches and/or tools!"
302 echo ""
303 echo "* Did you run ./batch.sh first?"
304 echo ""
305 echo "The patch_patches.tgz and patch_tools.tgz need to be in this directory,"
306 echo " one way or another..."
307 echo ""
308 cleanup
309 printusage_help
312 misstools_error () {
313 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
314 printtask "!! error: $@ "
315 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
316 printtask "Your set-up is missing a dependency."
317 echo "We require JDK, patch and cpio."
318 echo ""
319 echo ""
320 echo "Each distro is different"
321 echo "but you must ensure you have them all installed and try again."
322 echo ""
323 cleanup
324 printusage_help
327 printtask () {
328 echo "" >> "$LOG"
329 echo $@ | tee -a "$LOG"
332 copyfailed () {
333 echo ""
334 printtask "File for which patching failed:"
335 printtask "---------------------------------------------"
336 echo ""
337 printtask "${FAIL##*/}"
338 echo ""
339 echo "---------------------------------------------"
340 echo ""
341 echo "We can try to add a premade copy of those files."
342 echo "This sometimes works."
343 echo ""
344 echo "But IT MAY NOT WORK!!!"
345 echo ""
346 echo ""
347 askconsent && return 0 || return 1
350 askconsent () {
351 sleep 1
352 echo -n "Do you want to proceed ? (YES/no) "
353 read PROCEED
354 echo "askconsent final = ${PROCEED}: for $FAIL" >> "$LOG"
355 case $PROCEED in
356 [Yy] | [Yy][Ee][Ss])
357 return 0; # successful:
358 echo "*** You (or ApG) have elected to use a prepatched copy of $FAIL ***" >> "$LOG"
361 return 1; # error
362 echo "*** You have declined to insert $FAIL by not answering 'yes' at the prompt. ***" >> "$LOG"
364 esac
367 replace_updater () {
369 # Function for devices that use SDcard installs. Also to be tested for CM7
370 # since CM7 seems to use an updater-script that wipes EMMC. Testing
372 \rm $UPDATER_LOC/updater-script
373 \cp patches/common/$UPDATER_LOC/updater-script $UPDATER_LOC
374 echo "run_program(\"/sbin/busybox\", \"umount\", \"/system\");" >> UPDATE.txt
375 cat UPDATE.txt >> $UPDATER_LOC/updater-script
376 echo ""
377 echo "New updater-script being used:" >> "$LOG"
378 echo "-----------------------------" >> "$LOG"
379 cat $UPDATER_LOC/updater-script >> "$LOG"
382 abspath () {
383 case `uname -s` in
384 CYGWIN*)
385 echo $(cygpath -ua "$1")
387 Darwin)
388 #[[ $(echo $1 | awk '/^\//') == $1 ]] && echo "$1" || echo "$PWD/$1"
389 [[ ${1:0:1} == "/" ]] && echo "$1" || echo "$PWD/$1"
391 Linux)
392 echo $(readlink -f "$1")
395 if [[ ${1:0:1} == "/" ]]; then
396 echo "$1"
397 elif [[ ${1:0:2} == "./" ]]; then
398 echo "$PWD/${1:2}"
399 else
400 echo "$PWD/$1"
403 esac
406 mods_display () {
407 echo ""
408 echo "The Auto-Patcher $VERSION"
409 echo "*******************************"
410 echo ""
411 echo "The available mods are"
412 echo "****************************************************"
413 echo "* pdroid openpdroid voice v6supercharger *"
414 echo "* voice insecure secure external_internal *"
415 echo "* tabletUI 3gdongle pd2.0 *"
416 echo "****************************************************"
417 echo ""
418 echo "To find out more about any mod, simply enter:"
419 echo " ./auto_patcher -h <MODNAME>"
420 echo ""
421 cleanup
424 mods_info () {
425 DEPENDENCY="None" # default
426 DEV="Unknown" # default
427 CEILING=$CURRENT_ANDROID # Default is that everything works...we'll see.
428 case $PID in
429 mods)
430 mods_display
431 exit
433 auto*)
434 echo ""
435 echo "**************************************"
436 echo "The Auto-Patcher ate a kitten once..."
437 echo "**************************************"
438 printusage_help
440 advanced)
441 cd patches/
442 (advanced_help && find -H * -name 2012*) | more -d
443 echo ""
444 printusage_help
446 voice)
447 FLOOR=4.0.0
448 DESC="Use on wifi-only tablets to have the software register as 'voice-enabled'. Allows VOIP like Google Voice to function."
450 v6supercharger)
451 FLOOR=4.0.0
452 CEILING=4.2.1
453 DESC="A memory-management tool. It requires smali edits for Android roms 4.0+."
454 DESC1="The Auto-Patcher applies all 56 edits recommended by the dev."
455 DEV="Zeppelinrox"
456 DEPENDENCY="The V6 Supercharger Script. Get it at http://forum.xda-developers.com/showthread.php?t=991276/"
458 pdroid)
459 FLOOR=2.3.7
460 CEILING=4.1.2
461 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."
462 DESC1="(It's the 'openpdroid' mod within the Auto-Patcher)."
463 DEV="Svyat"
464 DEPENDENCY="The Pdroid app. You can get it at http://forum.xda-developers.com/showthread.php?t=1923576"
466 pd2.0)
467 FLOOR=4.1.2
468 CEILING=4.1.2
469 DESC="An expansion of the PDroid application/framework."
470 DEV="CollegeDev"
471 DEPENDENCY="The free PDroid2.0 app available at http://forum.xda-developers.com/showthread.php?t=1923576"
473 openpdroid)
474 FLOOR=4.1.2
475 CEILING=4.2.1
476 DESC="A fork of the open-source PDroid and Pdroid2.0 framework."
477 DEV="FFU5y/wbedard/mateorod/Community"
478 DEPENDENCY="The PDroidManager app freely available from Google Play or http://forum.xda-developers.com/showthread.php?t=1994860"
480 opendroid)
481 echo ""
482 echo "No mod named 'opendroid'. You probably mean 'openpdroid'. Try again."
483 PID="mods"
484 mods_info
486 external_internal)
487 FLOOR=2.3.3
488 DESC="Swap internal and external storage."
490 insecure)
491 FLOOR=2.3.3
492 DESC="Make any boot.img insecure and allow remount as well as adb push/pull of system files. True root."
494 secure)
495 FLOOR=2.3.3
496 DESC="Make any boot.img secure."
498 3gdongle)
499 FLOOR=4.1.0
500 CEILING=4.2.1
501 DESC="Allows 3gdongles to work on wifi tablets w/o 3rd party applications."
502 DEV="trevd"
503 DEPENDENCY="None, but read the troubleshooting guide at http://forum.xda-developers.com/showthread.php?t=1798631"
505 tabletUI)
506 FLOOR=4.1.0
507 CEILING=4.1.2
508 DESC="Changes the user interface of Phones and Phablets to the popular Tablet UI."
509 DEV="barmullio"
511 esac
512 # strip decimals from android version (i.e. 2.3.7 becomes 237) so we can do math
513 NVID=${VID//[.]/}
514 COMPATF=${FLOOR//[.]/}
515 COMPATC=${CEILING//[.]/}
518 apk_check () {
519 if [ -f patches/$P/$A/$R/$B/$FILE ]; then
520 echo "... Patching $APK failed, but we will copy over a prepatched file ..."
521 \cp -av patches/$P/$A/$R/$B/$FILE $FILE >> "$LOG"
522 else
523 print_error "failed patching $APK!!!"
526 compat_check () {
527 for P in ${PID[@]}; do
528 mods_info
529 if [[ "$NVID" -lt "$COMPAT" ]]; then
530 mismatch_error "Your Android $VID rom is too old! The minimum for $P is Android $FLOOR!"
532 if [[ "$NVID" -gt "$COMPATC" ]]; then
533 mismatch_error "Sorry, $P has not been made available for Android $VID yet!"
535 done
537 extpath () {
538 case `uname -s` in
539 CYGWIN*)
540 echo $(cygpath -da "$1")
543 echo $(abspath "$1")
545 esac
548 #contains () { for e in "${@:2}"; do [[ "$e" = "$1" ]] && return 0; done; return 1; }
550 parse () { echo "${1%%_*}"; }
552 getbuildprop () {
553 if [ -f system/build.prop ]; then
554 result=(`grep $1 system/build.prop | tr -d '\r' | tr '=' ' '`)
555 echo "${result[1]}"
556 else
557 echo ""
562 aosp_mod_check() {
563 jar -xvf "$ROMX" system/framework/framework2.jar >> $LOG
564 if [ -s system/framework/framework2.jar ]; then
565 ever_check
566 else
567 AOSP=aosp-jb
571 ever_check() {
572 MID=$(getbuildprop ro.build.romversion)
573 if [[ "$MID" == "Evervolv"* ]]; then
574 AOSP=aosp-ever
575 else
576 MID=$(getbuildprop ro.build.display.id)
577 if [[ "$MID" == "ev"* ]]; then
578 AOSP=aosp-ever
579 else
580 AOSP=aosp-mod
585 pa_check() {
586 CMID=$(getbuildprop ro.modversion)
587 PAID=$(getbuildprop ro.pa.version)
588 MID=$(getbuildprop ro.build.display.id)
589 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
590 DID=$(getbuildprop ro.product.device)
591 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
592 if [[ -n $PAID ]]; then
593 RID=pa
594 else
595 case $CMID in
596 [Pp][Aa]*)
597 RID=pa;
600 RID=cm;
602 esac
606 proberom () {
607 VID=$(getbuildprop ro.build.version.release)
608 ANDR="${VID%.*}" # Cut flavor to 1 significant digit to cover specific range or release.
609 if [ "$ANDR" == "2.3" ]; then
610 FLAVR=gingerbread
611 API=10
612 RID=cm;
613 elif [ "$ANDR" == "4.0" ]; then
614 FLAVR=ics
615 API=15
616 MID=$(getbuildprop ro.rommanager.developerid)
617 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.modversion))
618 DID=$(getbuildprop ro.product.device)
619 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
621 case "$MID" in
622 pa|cm9|cm|cyanogenmod*)
623 RID=cm;
625 aokp|teamkang)
626 RID=aokp;
628 aosp*)
629 RID=aosp;
632 echo "!!! $MID is not supported yet, trying generic latest !!!"
634 esac
635 elif [ "$ANDR" == "4.1" ]; then
636 FLAVR=jellybean
637 API=16
638 CMID=$(getbuildprop ro.cm.version)
639 if [[ -n $CMID ]]; then
640 pa_check
641 else
642 MID=$(getbuildprop ro.build.display.id)
643 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
644 DID=$(getbuildprop ro.product.device)
645 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
646 case "$MID" in
647 cm10|cm*|cyanogenmod*)
648 RID=cm;
650 aokp*|teamkang)
651 RID=aokp;
653 pa*)
654 RID=pa;
656 ev*)
657 RID=aosp-ever;
660 RID=`aosp_mod_check`;
662 esac
664 elif [ "$ANDR" == "4.2" ]; then
665 FLAVR=jellybean
666 API=17
667 CMID=$(getbuildprop ro.cm.version)
668 MID=$(getbuildprop ro.build.display.id)
669 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
670 DID=$(getbuildprop ro.product.device)
671 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
673 case "$MID" in
674 cm10|cm*|cyanogenmod*)
675 RID=cm;
677 aokp*|teamkang)
678 RID=aokp;
680 pa*) # Defaults to cm for now, since there is a chance we can patch forks
681 RID=cm;
684 RID=aosp;
686 esac
687 else
688 print_error "unknown ROM version $VID"
690 echo "... result of ROM check: version= $VID rom= $RID ..."
693 # Advanced build date query
694 # This should set the patch date automatically.
696 buildquery() {
697 UTC=$(getbuildprop ro.build.date.utc)
699 # Difference in how OS X and Linux/Cygwin handles 'date' utility
700 case `uname -s` in
701 [Dd]arwin)
702 BDID=`date -r $UTC +%Y%m%d`
703 echo "#### Darwin Build Query used ####" >> "$LOG"
706 BDID=`date -d "1970-01-01 UTC $UTC seconds" +"%Y%m%d"`
707 echo "#### Standard Build Query ####" >> "$LOG"
709 esac
711 # If patch date is specified on CLI, use that patch date
712 if [ $# -gt 3 ]; then
713 BID=${4//,/ };
714 else
715 case $ANDR in
716 gingerbread)
717 # CM7 roms do not have UTC time stamp- so no build query.
718 BID=latest;
719 echo "*** CM7 roms default to latest patches. If using an older rom ***"
720 echo "*** specify patch date on command line. Use -h to see available patches ***"
723 for P in ${PID[@]}; do
724 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
725 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
726 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
727 PAR=patches/$P/$A/$R
728 PARB=patches/$P/$A/$R/$B
729 DATES=`ls patches/$P/$A/$R/ | grep '201*'`
730 # Intialize variable - High so as to determine lowest in first loop.
731 BID=20201231
732 # find earliest available patch date
733 for i in $DATES; do
734 if [[ $i -lt $BID ]]; then
735 BID=$i
737 done
738 # Check if earliest patches are from before build date. Else use earliest
740 # If older than earliest patch set, then find best match
741 if [[ $(($BID-$BDID)) -lt 0 ]]; then
742 for g in $DATES; do
743 # use any patch that matches $UTC
744 if [[ $(($BDID-$g)) -eq 0 ]]; then
745 BID=$g
746 break
747 # Set highest $BID w/o going over $UTC
748 elif [[ $(($BDID-$g)) -gt 0 ]] && [[ $g -gt $BID ]]; then
749 BID=$g
751 done
753 echo "... $PID patch date has been set to: $BID..."
754 B=$BID
755 break
756 done
758 esac
762 proberil () {
763 RIL=$(getbuildprop ro.telephony.ril_class)
764 [[ -n $RIL ]] && printtask "... result of ROM check: RIL= $RIL"
767 rominfo () {
768 echo "# VER= $VERSION" >> "$LOG"
769 echo "# OS= $OSTYPE ${BIT}bit" >> "$LOG"
770 echo "# VID= $VID" >> "$LOG"
771 echo "# PID= ${PID[@]}" >> "$LOG"
772 echo "# MID= $MID" >> "$LOG"
773 echo "# RID= $RID" >> "$LOG"
774 echo "# ANDR= $ANDR" >> "$LOG"
775 echo "# BDID= $BDID" >> "$LOG"
776 echo "# DID= $DID" >> "$LOG"
777 echo "# BID= $BID" >> "$LOG"
781 if [[ $1 == -h ]]; then
782 if [ $# -gt 1 ]; then
783 PID=$2
784 mods_info
785 echo ""
786 echo "The Auto-Patcher $VERSION by Mateorod and Pastime1971"
787 echo "*************************************************"
788 echo ""
789 echo "Mod Name: $PID"
790 echo ""
791 echo " $DESC"
792 if [[ $((DESC1)) -gt 0 ]]; then # test to see is there is a second DESC line
793 echo "$DESC1"
795 if [[ $((DESC2)) -gt 0 ]]; then
796 echo "$DESC2"
798 echo ""
799 echo "Developer: $DEV"
800 echo "Dependancies: $DEPENDENCY"
801 echo ""
802 echo "Works on ROMs from Android $FLOOR -> $CEILING"
803 echo
804 brief_help
805 exit
809 [[ $# -lt 1 || -z $1 ]] && PID="mods" && mods_info
810 [[ $1 == "-h" ]] && usage_help | less && display_help
812 echo ""
813 echo "The Auto-Patcher $VERSION"
814 echo ""
815 # by pastime1971 and mateorod
817 ROOT=$(abspath `dirname "$0"`)
818 TOOL="$ROOT/patch_tools.tgz"
819 PTCH="$ROOT/patch_patches.tgz"
820 ROM=$(abspath "$1")
821 ROMX=$(extpath "$1")
823 if [[ $OSTYPE == "cygwin" ]]; then
824 EXE=".exe"
825 PGFORM="0x"
828 DATE=`date +%Y%m%d%H%M%S`
829 TEMP=$(abspath ./tmp$DATE)
830 LOG=$(abspath ./log$DATE.txt)
831 #echo $ROOT $TOOL $ROM $TEMP "$LOG"
832 echo "ROOT= $ROOT" >> "$LOG"
833 echo "TOOL= $TOOL" >> "$LOG"
834 echo "ROM= $ROM" >> "$LOG"
835 echo "ROMX= $ROMX" >> "$LOG"
837 \rm -f restore.zip update.zip
839 CHK=$(getconf LONG_BIT)
840 if [[ $CHK = "64" ]]; then
841 BIT=64
842 else [[ $BIT = "32" ]];
843 BIT=32
847 printtask "### verify tools ###"
848 which patch >> "$LOG" || misstools_error "Missing \"patch diff command\""
849 which tar >> "$LOG" || misstools_error "Missing \"tar archive command\""
850 which jar >> "$LOG" || misstools_error "Missing \"jar (JDK)\""
851 which java >> "$LOG" || misstools_error "Missing \"java (JRE)\""
852 which cpio >> "$LOG" || misstools_error "Missing \"cpio archive command\""
853 [ -f "$TOOL" ] || misspatch_error "patch tool is missing"
854 [ -f "$PTCH" ] || misspatch_error "patch patches are missing"
855 printtask "### verify ROM ###"
856 [ -f "$ROM" ] || print_error "Cannot find $ROM"
857 echo "### running $0 $@" >> "$LOG"
858 mkdir "$TEMP"
859 cd "$TEMP"
861 PATH="$TEMP:$PATH"
862 export PATH
863 echo "PATH= $PATH" >> "$LOG"
865 printtask "### unzip patch tools ###"
866 tar xzf "$TOOL" > /dev/null || print_error "failed extracting tools !!!"
868 # Get OS specific tools
869 case `uname -s` in
870 CYGWIN*)
871 \mv cygwin/aapt.exe .
872 \mv cygwin/*.exe boot/
873 \rm -rf cygwin # why? If you want to we can keep/add it to mac/linux, though.
875 [Dd]arwin)
876 \mv mac/aapt .
878 [Ll]inux)
879 \mv linux/aapt .
882 \mv linux/aapt .
884 esac
885 # Ensure aapt permissions - possibly to one day be expanded to all tools in a function.
886 chmod a+x aapt$EXE
888 printtask "### unzip patch patches ###"
889 tar xzf "$PTCH" > /dev/null || print_error "failed extracting patches !!!"
891 # we need build.prop for both RIL probing and ROM probing
892 jar -xvf "$ROMX" system/build.prop 2>> "$LOG" || print_error "failed extracting build.prop from $ROMX !!!"
894 # rom + ril type
895 proberil
896 printtask "### probe rom type ###"
897 proberom
899 # rom type
900 if [ $# -gt 1 ]; then
901 PIT=$2
902 if [[ "$PIT" = "-h" ]]; then
903 display_help
906 if [ $# -gt 2 ]; then
907 RID=$3
908 case "$RID" in
909 cm10|cm*|cyanogenmod*)
911 aokp*|teamkang)
912 RID=aokp;
914 pa*)
915 RID=pa;
917 aosp-ever)
918 RID=aosp-ever;
920 aosp*)
921 case "ANDR" in
922 4.1)
923 RID=`aosp_mod_check`;
926 RID=aosp
928 esac
930 201*)
931 date_error "You must specify ROMTYPE if designating a patch date!!"
934 rom_error "$RID is not a valid ROMTYPE!!"
936 esac
937 echo "... Using $RID patches ..."
938 else
939 echo "... Using results of ROM check ..."
942 # patch type
943 if [ $# -gt 1 ]; then
944 PIL=${2//,/ } # If more than one mod, make string separated by spaces
945 else
946 PIL="pdroid v6supercharger"
947 echo "No mods selected. Defaulting to the v6 and Pdroid, just because we can."
950 PID=(${PIL// / }) # turn string into array
951 COPYPID=("${PID[@]}") # working copy to iterate over
952 MODS_NUMBER=${#COPYPID[@]} # number of elements (mods)
954 if [[ $MODS_NUMBER > 1 ]]; then
955 INDEX=0
956 for p in ${COPYPID[@]}; do
957 if [ "$p" = "pdroid" ] || [ "$p" = "pd2.0" ] ||[ "$p" = "openpdroid" ]; then
958 SPID[0]=$p
959 unset COPYPID["$INDEX"]
960 break
961 else
962 INDEX=$((INDEX + 1))
964 done
965 for p in ${COPYPID[@]}; do
966 if [ "$p" = "pdroid" ] || [ $p = "pd2.0" ] ||[ $p = "openpdroid" ]; then
967 conflict_error "Those mods conflict! Only one pdroid mod at a time!"
968 else
969 i=${#SPID[@]}
970 SPID[i]=$p
971 i+=1
973 done
974 else
975 SPID=${COPYPID[@]}
977 for P in ${PIL[@]}; do
978 [[ ${PID[@]} =~ $P ]] || PID=(${PID[@]} $P)
979 done
981 # Check to make sure selected roms are available for the Android version of patched ROM
982 compat_check
984 # Build date
985 if [ $# -gt 3 ]; then
986 BID=$4
987 # even here, we should try and create a function that matches as close to the above
988 # BID as possible. Now, a bad match (user error) defaults to latest
989 echo "... $PID patch date set manually to $BID ..."
990 else
991 buildquery
994 # echo ROM info
995 rominfo
997 # I think I finally may have rendered this VERY long if statement obsolete...CHECK!
998 if [[ ( "$PID" == "-h" || "$RID" == "-h" || "$BID" == "-h" ) ]]; then
999 #Although this placement may be perfect for romfilter. although it throws the scheme...
1000 display_help
1002 #Begin cycle
1004 for P in ${PID[@]}; do
1005 [ -d patches/$P ] || print_error "$P is not available"
1006 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1007 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1008 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1010 unset FILES
1011 [ -f patches/$P/files.txt ] && FILES=$(cat patches/$P/files.txt)
1012 [ -f patches/$P/$A/files.txt ] && FILES=$(cat patches/$P/$A/files.txt)
1013 [ -f patches/$P/$A/$R/files.txt ] && FILES=$(cat patches/$P/$A/$R/files.txt)
1014 [ -f patches/$P/$A/$R/$B/files.txt ] && FILES=$(cat patches/$P/$A/$R/$B/files.txt)
1015 for FILE in ${FILES[@]}; do
1016 case "$FILE" in
1017 +system/*)
1018 [[ ${CID[@]} =~ ${FILE:1} ]] && print_error "${FILE:1} is already being copied" || CID=(${CID[@]} ${FILE:1})
1020 -system/*)
1021 [[ ${EID[@]} =~ ${FILE:1} ]] || EID=(${EID[@]} ${FILE:1})
1023 system/*.jar)
1024 [[ ${JID[@]} =~ $FILE ]] || JID=(${JID[@]} $FILE)
1025 echo "set_perm(0, 0, 0644, \"/$FILE\");" >> UPDATE.txt
1027 system/*.apk)
1028 [[ ${AID[@]} =~ $FILE ]] || AID=(${AID[@]} $FILE)
1029 echo "set_perm(0, 0, 0644, \"/$FILE\");" >> UPDATE.txt
1031 *.img)
1032 [[ ${IID[@]} =~ $FILE ]] || IID=(${IID[@]} $FILE)
1034 system/*)
1035 [[ ${TID[@]} =~ $FILE ]] || TID=(${TID[@]} $FILE)
1037 esac
1038 done
1039 done
1040 echo "### DELETE FILES= ${EID[@]}" >> "$LOG"
1041 echo "### COPY FILES= ${CID[@]}" >> "$LOG"
1042 echo "### JAR FILES= ${JID[@]}" >> "$LOG"
1043 echo "### APK FILES= ${AID[@]}" >> "$LOG"
1044 echo "### IMG FILES= ${IID[@]}" >> "$LOG"
1045 echo "### TXT FILES= ${TID[@]}" >> "$LOG"
1047 # extract system files
1048 printtask "### unzip rom ###"
1049 jar -xvf "$ROMX" ${JID[@]} ${AID[@]} ${IID[@]} ${TID[@]} 2>> "$LOG" || print_error "failed extracting ${JID[@]} ${AID[@]} ${IID[@]} from $ROMX !!!"
1051 printtask "### create updater script ###"
1052 UPDATER_LOC=META-INF/com/google/android
1054 jar -xvf "$ROMX" $UPDATER_LOC/updater-script $UPDATER_LOC/update-binary
1055 #OSX has no dev/null---change
1056 jar -xvf "$ROMX" $UPDATER_LOC/update-binary-installer 1> /dev/null 2> /dev/null
1058 # Determine Installer- Aroma or ClockworkMod
1059 if [ -f $UPDATER_LOC/update-binary-installer ]; then
1060 printtask "... using Aroma installer ..."
1061 \mv $UPDATER_LOC/update-binary-installer $UPDATER_LOC/update-binary
1062 else
1063 printtask "... using Clockworkmod installer ..."
1066 # Create updater-scripts
1067 cat $UPDATER_LOC/updater-script | grep ^mount | grep "/system" | head -n 1 > updater-script
1068 [ -s updater-script ] || echo "run_program(\"/sbin/busybox\", \"mount\", \"/system\");" > updater-script
1069 for FILE in ${EID[@]}; do
1070 # restore the original
1071 jar -xvf "$ROMX" $FILE 2> /dev/null || printtask "!!! warning $FILE cannot be restored !!!"
1072 done
1073 for FILE in ${CID[@]}; do
1074 # replace with the original or delete it
1075 jar -xvf "$ROMX" $FILE 2> /dev/null || echo "delete(\"/$FILE\");" >> updater-script
1076 done
1077 echo "package_extract_dir(\"system\", \"/system\");" >> updater-script
1078 # permission management for files that need specific perms
1079 cat $UPDATER_LOC/updater-script | grep set_perm | grep "/system" >> updater-script
1080 for P in ${PID[@]}; do
1081 if [ -s patches/$P/$A/set_perm.txt ]; then
1082 echo "...setting permissions..."
1083 cat patches/$P/$A/set_perm.txt >> updater-script
1085 done
1086 cat $UPDATER_LOC/updater-script | grep ^unmount | grep "/system" | head -n 1 >> updater-script
1087 [[ ${IID[@]} =~ boot.img ]] && cat $UPDATER_LOC/updater-script | grep "boot.img" >> updater-script
1088 cat updater-script > $UPDATER_LOC/updater-script
1089 echo "# generated updater-script" >> "$LOG"
1090 cat updater-script >> "$LOG"
1092 printtask "### create restore.zip ###"
1093 jar -cvf tmp.zip ${JID[@]} ${AID[@]} ${IID[@]} META-INF > /dev/null 2>> "$LOG"
1094 java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip signed.zip 2>> "$LOG"
1095 \mv signed.zip restore.zip
1096 \rm -f tmp.zip
1099 # Begin patching process
1101 # decompile system files
1102 printtask "### decompile system files ###"
1103 for FILE in ${JID[@]}; do
1104 JAR=${FILE##*/}
1105 printtask "... decompile $JAR ..."
1106 java -jar baksmali.jar -b -a $API -o tmp/${FILE}.out/smali ${FILE} >> "$LOG" 2>> "$LOG"
1107 if [ $FILE == "system/framework/framework.jar" ]; then
1108 printtask "... extract preloaded-classes ..."
1109 jar -xvf ${FILE} preloaded-classes >> "$LOG" 2>> "$LOG"
1110 \mv preloaded-classes tmp/${FILE}.out/
1112 done
1114 # install framework-files for APK...
1115 if [ ${#AID[@]} -gt 0 ]; then
1116 jar -xvf "$ROMX" system/framework/framework-res.apk >> "$LOG"
1117 printtask "... installing framework files ..."
1118 java -jar apktool.jar if system/framework/framework-res.apk
1119 # Decompile APKs
1120 for FILE in ${AID[@]}; do
1121 APK=${FILE##*/}
1122 if [ -f $FILE ]; then
1123 printtask "... decompile $APK ..."
1124 java -jar apktool.jar d -f $FILE tmp/$FILE.out
1126 done
1129 # Unpack image files {boot.img only so far...}
1130 for FILE in ${IID[@]}; do
1131 printtask "### unpacking $FILE ###"
1132 case "$FILE" in
1133 boot.img)
1134 if [ -f boot.img ]; then
1135 cd boot
1136 ./unpackbootimg$EXE -i ../boot.img >> "$LOG" 2>> "$LOG"
1137 mkdir ramdisk
1138 cd ramdisk
1139 gzip -dc ../boot.img-ramdisk.gz | cpio -i >> "$LOG" 2>> "$LOG"
1140 cd ../../
1141 else
1142 print_error "A mod needs to patch boot.img! This rom does not contains boot.img."
1146 print_error "cannot process $FILE"
1148 esac
1149 done
1151 # apply system modification
1153 for P in ${PID[@]}; do
1154 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1155 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1156 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1157 PAR=patches/$P/$A/$R
1158 PARB=patches/$P/$A/$R/$B
1160 unset FILES COPY DELS JARS APKS IMGS TXTS
1161 [ -f patches/$P/files.txt ] && FILES=$(cat patches/$P/files.txt)
1162 [ -f patches/$P/$A/files.txt ] && FILES=$(cat patches/$P/$A/files.txt)
1163 [ -f patches/$P/$A/$R/files.txt ] && FILES=$(cat patches/$P/$A/$R/files.txt)
1164 [ -f patches/$P/$A/$R/$B/files.txt ] && FILES=$(cat patches/$P/$A/$R/$B/files.txt)
1165 for FILE in ${FILES[@]}; do
1166 case $FILE in
1167 +system/*)
1168 COPY=(${COPY[@]} ${FILE:1})
1170 -system/*)
1171 DELS=(${DELS[@]} ${FILE:1})
1173 system/*.jar)
1174 JARS=(${JARS[@]} $FILE)
1176 system/*.apk)
1177 APKS=(${APKS[@]} $FILE)
1179 *.img)
1180 IMGS=(${IMGS[@]} $FILE)
1182 system/*)
1183 TXTS=(${TXTS[@]} $FILE)
1185 esac
1186 done
1188 [[ -n ${COPY[@]} ]] && printtask "### copy patch $P/$A/$R/$B ###"
1189 for FILE in ${COPY[@]}; do
1190 printtask "... copying $FILE ..."
1191 DEST=${FILE%/*}
1192 mkdir -p ./$DEST
1193 if [ -e patches/$P/$A/$R/$B/$FILE ]; then
1194 [ -e $FILE ] && printtask "... overwriting $FILE from $P ..."
1195 \cp -av patches/$P/$A/$R/$B/$FILE ./$DEST >> "$LOG"
1196 else
1197 print_error "$FILE is missing in the patch. Please upload your logfile to the support thread!"
1199 done
1201 # unconditional smali copying- For particularly troublesome files
1202 [ -f patches/$P/smali.txt ] && SMALI=$(cat patches/$P/smali.txt)
1203 [ -f patches/$P/$A/smali.txt ] && SMALI=$(cat patches/$P/$A/smali.txt)
1204 [ -f patches/$P/$A/$R/smali.txt ] && SMALI=$(cat patches/$P/$A/$R/smali.txt)
1205 [ -f patches/$P/$A/$R/$B/smali.txt ] && SMALI=$(cat patches/$P/$A/$R/$B/smali.txt)
1206 MOVE=${SMALI##*/}
1207 for SMALI in ${SMALI[@]}; do
1208 if [ -f patches/$P/$A/$R/provisionals/$SMALI ]; then
1209 printtask "... overwriting $MOVE ..."
1210 \cp -a patches/$P/$ANDR/$R/provisionals/$SMALI tmp/$SMALI >> "$LOG"
1211 elif [ -f patches/$P/$A/provisionals/$SMALI ]; then
1212 printtask "... overwriting $MOVE ..."
1213 \cp -a patches/$P/$ANDR/provisionals/$SMALI tmp/$SMALI >> "$LOG"
1215 done
1217 [[ -n ${DELS[@]} ]] && printtask "### delete patch $P/$A/$R/$B ###"
1218 for FILE in ${DELS[@]}; do
1219 printtask "... deleting $FILE ..."
1220 \rm -rf ./$FILE
1221 done
1222 [[ -n ${JARS[@]} ]] && printtask "### jar patch $P/$A/$R/$B ###"
1223 for FILE in ${JARS[@]}; do
1224 JAR=${FILE##*/}
1225 NAME=${JAR%.jar}
1226 printtask "... apply $NAME.patch ..."
1227 patch -Nls -p1 -d tmp/${FILE}.out < $PARB/${NAME}.patch 2>&1 > ${JAR}.log
1228 cat ${JAR}.log | tee -a "$LOG"
1229 case "$NAME" in
1230 framework)
1231 # patch preloaded-classes only if a patch exists
1232 if [ -f $PARB/preloaded.patch ]; then
1233 printtask "... apply preloaded.patch ..."
1234 patch -Nls -p1 -d tmp/${FILE}.out < $PARB/preloaded.patch 2>&1 > preloaded.log
1235 cat preloaded.log | tee -a "$LOG"
1236 [[ `grep FAILED preloaded.log` != "" ]] && print_error "failed preloaded.patch"
1240 echo -n "" # do nothing else
1242 esac
1243 # substitute failed smali with provisional (a prepatched smali file)
1244 unset FAILS
1245 FAILS=(`grep FAILED ${JAR}.log | sed -e 's/.*smali\///' | sed -e 's/\.rej//'`)
1246 if [[ -n ${FAILS[@]} ]]; then
1247 printtask "!!! PATCHING FAILED FOR ${FAILS[@]} !!!"
1248 echo "### replace ${FAILS[@]} ###" > ${JAR}.log
1249 for FAIL in ${FAILS[@]}; do
1250 echo "!!! patch error for $FAIL !!!" >> "$LOG"
1251 #cat tmp/$FILE.out/smali/${FAIL}.rej >> "$LOG" # FOR DEBUGGING
1252 [[ ${SID[@]} =~ $FAIL ]] && print_error "$FAIL was already replaced before"
1253 [ -f patches/$P/$ANDR/provisionals/${FILE}.out/smali/${FAIL} ] || print_error "failed $FAIL in $JAR cannot be remedied"
1254 copyfailed || print_error "failed $NAME.patch"
1255 printtask "... replace $FAIL ..."
1256 \rm -rf tmp/${FILE}.out/smali/${FAIL} tmp/${FILE}.out/smali/${FAIL}.orig tmp/${FILE}.out/smali/${FAIL}.rej
1257 \cp -av patches/$P/$ANDR/provisionals/${FILE}.out/smali/${FAIL} tmp/${FILE}.out/smali/${FAIL} >> "$LOG" || echo "FAILED to cp $FAIL" >> ${JAR}.log
1258 SID=(${SID[@]} $FAIL)
1259 done
1261 [[ `grep FAILED ${JAR}.log` != "" ]] && print_error "failed $NAME.patch"
1262 garbage tmp/${FILE}.out
1263 # run special $JAR.sh scripts if any JAR needs special attention
1264 if [ -f patches/$P/$A/$R/$B/${JAR}.sh ]; then
1265 printtask "... apply $JAR.sh ..."
1266 . patches/$P/$A/$R/$B/${JAR}.sh 2>&1 > ${JAR}.log
1267 cat ${JAR}.log | tee -a "$LOG"
1269 done
1271 [[ -n ${APKS[@]} ]] && printtask "### apk patch $P/$A/$R/$B ###"
1272 for FILE in ${APKS[@]}; do
1273 APK=${FILE##*/}
1274 if [ -d "tmp/${FILE}.out" ] ; then
1275 printtask "... apply $APK.patch ..."
1276 patch -Nls -p2 -d tmp/${FILE}.out < $PARB/${APK}.patch 2>&1 >> ${APK}.log
1277 cat ${APK}.log | tee -a "$LOG"
1278 [[ `grep FAILED ${APK}.log` != "" ]] && apk_check
1279 garbage tmp/${FILE}.out
1280 else
1281 echo "No $APK in your ROM. Not able to patch this file."
1282 echo "## No $APK in ROM ###" >> "$LOG"
1284 done
1285 [[ -n ${IMGS[@]} ]] && printtask "### img patch $P/$A/$R/$B ###"
1286 for FILE in ${IMGS[@]}; do
1287 IMG=${FILE##*/}
1288 printtask "... applying $IMG.patch ..."
1289 patch -Nls -p1 -d boot/ramdisk < $PARB/${IMG}.patch >> "$LOG" || print_error "failed patching $FILE"
1290 done
1292 [[ -n ${TXTS[@]} ]] && printtask "### text patch $P/$A/$R/$B ###"
1293 for FILE in ${TXTS[@]}; do
1294 TXT=${FILE##*/}
1295 if [[ -f $PARB/${TXT}.patch ]]; then
1296 printtask "... apply $TXT.patch ..."
1297 patch -Nls -p2 -d system/ < $PARB/${TXT}.patch 2>&1 > ${TXT}.log
1298 #cat ${TXT}.log | tee -a "$LOG"
1299 [[ `grep FAILED ${TXT}.log` != "" ]] && print_error "failed $TXT.patch"
1301 if [[ -f $PAR/${TXT}.awk ]]; then
1302 printtask "... apply $TXT.awk ..."
1303 awk -f $PAR/${TXT}.awk $FILE > text || print_error "failed $TXT.awk"
1304 mv text $FILE
1306 if [[ -f $PAR/${TXT}.sed ]]; then
1307 printtask "... apply $TXT.sed ..."
1308 sed -f $PAR/${TXT}.sed $FILE > text || print_error "failed $TXT.sed"
1309 mv text $FILE
1311 if [[ -f $PAR/${TXT}.sh ]]; then
1312 printtask "... apply $TXT.sh ..."
1313 . $PAR/${TXT}.sh 2>&1 >> ${TXT}.log || print_error "failed $TXT.sh"
1315 garbage system/
1316 done
1317 done
1319 # Device specific scripts- Placement is up-for-review
1320 if [ -f patches/devices/$DID/$DID.sh ]; then
1321 . patches/devices/$DID/$DID.sh
1324 # Replace updater-script for CM7- it formats system -Testing
1325 if [ "$ANDR" == "gingerbread" ]; then
1326 replace_updater
1329 # Rebuilding system files
1331 [[ -n ${JID[@]} ]] && printtask "### rebuild jar ###"
1332 for FILE in ${JID[@]}; do
1333 JAR=${FILE##*/}
1334 printtask "... rebuild $JAR ..."
1335 java -Xmx512M -jar smali.jar -a $API tmp/${FILE}.out/smali -o tmp/${FILE}.out/classes.dex >> "$LOG" 2>> "$LOG"
1336 [ -f tmp/${FILE}.out/classes.dex ] || smali_error "failed compiling $JAR !!!"
1337 jar -ufv ${FILE} -C tmp/${FILE}.out/ classes.dex >> "$LOG" 2>> "$LOG"
1338 if [ $FILE == "system/framework/framework.jar" ]; then
1339 jar -ufv ${FILE} -C tmp/${FILE}.out/ preloaded-classes >> "$LOG" 2>> "$LOG"
1341 done
1343 [[ -n ${AID[@]} ]] && printtask "### rebuild apk ###"
1344 for FILE in ${AID[@]}; do
1345 APK=${FILE##*/}
1346 if [ -d tmp/${FILE}.out ]; then
1347 printtask "... rebuild $APK ..."
1348 java -jar apktool.jar b tmp/${FILE}.out >> "$LOG" 2>> "$LOG" || print_error "failed compiling $FILE !!!"
1349 jar -uvf $FILE -C tmp/${FILE}.out/build/apk/ . > /dev/null 2>> "$LOG"
1351 done
1353 [[ -n ${IID[@]} ]] && printtask "### rebuild img ###"
1354 for FILE in ${IID[@]}; do
1355 printtask "### rebuild $FILE ###"
1356 case $FILE in
1357 boot.img)
1358 # Rebuilding boot.img
1359 cd boot
1360 printtask "... rebuilding ramdisk ..."
1361 ./mkbootfs$EXE ./ramdisk | gzip > ramdisk-new.gz
1363 printtask "... composing boot.img ..."
1364 BASE=$(cat boot.img-base)
1365 # hex to decimal in cygwin prefixing "0x" w/ C arithmetic
1366 PGSIZE=$((${PGFORM}$(cat boot.img-pagesize)))
1367 CMDLINE=$(cat boot.img-cmdline)
1368 echo "cmdline = no_console_suspend=1 console=null $CMDLINE" >> "$LOG"
1369 echo "pagesize = $PGSIZE" >> "$LOG"
1370 echo "base = $BASE" >> "$LOG"
1371 printtask "... rebuilding boot.img ..."
1372 ./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"
1373 cd ..
1376 print_error "cannot process $FILE"
1378 esac
1379 done
1381 printtask "### create update.zip ###"
1382 jar -cfv tmp.zip ${IID[@]} ${JID[@]} ${AID[@]} ${CID[@]} ${TID[@]} META-INF >> "$LOG" 2>> "$LOG"
1383 java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip update.zip 2>> "$LOG"
1385 \mv restore.zip update.zip ..
1386 echo "### finished ###"
1387 echo "flash update.zip to install the modified"
1388 echo "flash restore.zip to restore the original"
1390 # add announcement- optional.
1391 for P in ${PID[@]}; do
1392 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1393 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1394 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1395 if [ -f patches/$P/$A/$R/$B/README.txt ]; then
1396 cat patches/$P/$A/$R/$B/README.txt
1397 elif [ -f patches/$P/$A/$R/README.txt ]; then
1398 cat patches/$P/$A/$R/README.txt
1399 elif [ -f patches/$P/$A/README.txt ]; then
1400 cat patches/$P/$A/README.txt
1402 done
1404 cd ..
1405 \rm -rf "$TEMP"