Versioning to 2.5.2.5
[auto-patcher.git] / auto_patcher
blobbb340e2a3044122168ff84f22f73c68ed0b62bc6
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
101 # 2013.01.13. (v2.5.0) Added 'openpdroid' mod --Open-Source Pdroid framework
102 # BIG Improvements to help and error-catch. Try ./auto_patcher -h
103 # 2013.01.15. (v2.5.1) OpenPDroid support for Evervolv and ParanoidAndroid, hotfix for Mms
104 # 2013.01.15. (v2.5.2) Fix for cygwin temp files (kobik), provisional telephony files added
105 # 2013.01.16. (v2.5.2.5) Added a new provisional as a hotfix
106 # SHELL PROGRAMMING NOTES:
107 # [ -s FILE ]
108 # [[ -n STRING ]] or [[ -z STRING ]]
110 VERSION="v2.5.2.5"
111 CURRENT_ANDROID="4.2.1"
113 # pass variables to children
114 set -a
116 printusage_help () {
117 PID="openpdroid,3gdongle" # default example
118 brief_help
121 brief_help () {
122 echo " usage: ./auto_patcher <ROM> <MODS> <ROMTYPE>"
123 echo " example: ./auto_patcher CM10.zip $PID cm"
124 echo ""
125 echo "Use ./auto_patcher -h for the help menu"
126 echo ""
127 cleanup
128 exit
131 usage_help () {
132 PID=mods
133 mods_display
134 echo "Multiple MODS can be combined by separating them with a comma and NO SPACES!!!"
135 echo ""
136 echo " usage: ./auto_patcher <ROM> <MODS> <ROMTYPE>"
137 echo ""
138 echo " example: ./auto_patcher CM10.zip openpdroid,3gdongle cm"
139 echo ""
140 usage_more_help
143 usage_more_help () {
144 echo "* press 'q' available patches or CTRL-c to quit the help menu *"
147 display_help () {
148 cd patches
149 echo ""
150 echo "AVAILABLE PATCHES"
151 echo ""
152 echo "*******************************************************************"
153 echo "Note: There are ONLY 4 ROMTYPES: [pa, cm, aokp, and aosp]."
154 echo ""
155 #find -H * \( -name aokp -o -name cm -o -name aosp* -o -name pa -o -name all -o -name generic \) -prune | sed -e 's/-.*//' | column -c 85 | more -d -3
156 find -H * \( -name aokp -o -name cm -o -name aosp -o -name pa -o -name all -o -name generic \) -prune | column -c 85 | more -d -7
157 #-path './src/emacs' -prune
158 echo ""
159 echo "!!! Do not put Android Version number on command line !!!!"
160 echo "*****************************************************************"
161 echo "Specific auto_patcher script options"
162 echo " ./auto_patcher -h mods Lists mods"
163 echo " -h <MODNAME> Specific <MOD> info"
164 echo " -h advanced Advanced usage+lists all available patch dates"
165 echo ""
166 cleanup
167 exit
170 romtype_help () {
171 # From rom_error (bad romtype) and date_error (patch date w/o specifying romtype)
172 echo ""
173 echo "!!!There are only four supported ROMTYPES: 1) cm 2) aokp 3) aosp 4) pa"
174 echo ""
175 echo "Find out which of the above ROMTYPES your rom is based on and try again!"
176 echo "**********************************************"
177 echo ""
178 cleanup
179 brief_help
182 advanced_help () {
183 echo ""
184 echo "The Auto-Patcher Advanced Usage"
185 echo "*********************************"
186 echo ""
187 echo "For those of you determined to try everything..."
188 echo ""
189 echo "You can also try adding a patch date as a final argument."
190 echo ""
191 echo " ./auto_patcher <ROM> <MOD> <ROMTYPE> <DATE>"
192 echo ""
193 echo "Please note: There are only four ROMTYPES: {pa, aokp, aosp and cm}"
194 echo " -The various appellations after that are for internal use only!"
195 echo ""
196 echo "The Auto-Patcher has a pretty great rom probe, specifying the date is"
197 echo " deprecated...you don't need to, we promise."
198 echo ""
201 cleanup () {
202 rm -rf $ROOT/tmp*
205 garbage () {
206 unset GARBAGE
207 GARBAGE=($(find $@ -name "*.orig")) && rm -rf ${GARBAGE[@]} && echo "GARBAGE= ${GARBAGE[@]}" >> "$LOG"
208 GARBAGE=($(find $@ -name "*.rej")) && rm -rf ${GARBAGE[@]} && echo "GARBAGE= ${GARBAGE[@]}" >> "$LOG"
212 print_error () {
213 # General purpose error. Used for errors in main, as opposed to probe or set-up.
214 echo ""
215 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
216 printtask "!!! error: $@"
217 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
218 echo ""
219 brief_help
222 smali_error () {
223 # Smali binary error. Problem often goes away on second run.
224 echo ""
225 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
226 printtask "!!! error: $@"
227 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
228 echo ""
229 if [[ `grep 'method index is too large' "$LOG"` != "" ]]; then
230 printtask "!!! Problem with method cap !!!"
231 printtask "... attempting fix ..."
232 . patches/common/framework.jar.sh 2>&1 > ${JAR}.log
233 printtask "... rebuild framework.jar ..."
234 java -Xmx512M -jar smali.jar -a $API tmp/${FILE}.out/smali -o tmp/${FILE}.out/classes.dex >> "$LOG" 2>> "$LOG"
235 [ -f tmp/${FILE}.out/classes.dex ] || print_error "Could not resolve method cap issue- please submit log"
236 else
237 printtask "!!! This error is generally due to an unknown bug in the smali binary!"
238 echo "In our experience, it goes away if you run the patcher a second time."
239 echo " Please run the Auto-Patcher with the same command once again."
240 echo ""
241 echo "If after the third attempt the same thing happens,"
242 echo " please upload your logfile to our support thread!"
243 echo ""
244 cleanup
245 exit
249 mismatch_error () {
250 # Function that exposes attempts to apply a mod to an upsupported Android version
251 echo ""
252 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
253 printtask "!!! error: $@"
254 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
255 echo ""
256 cleanup
257 brief_help
260 date_error () {
261 # Remind users to include a romtype if they are going to specify a patch date
262 echo ""
263 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
264 printtask "!!! error: $@"
265 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
266 echo ""
267 echo "Please put a ROMTYPE before the patch date and run again!!"
268 romtype_help
271 rom_error () {
272 # For when an unsupported romtype is manually entered on the command-line
273 echo ""
274 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
275 printtask "!!! error: $@"
276 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
277 romtype_help
280 conflict_error () {
281 # For conflicting packages
282 echo ""
283 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
284 printtask "!!! error: $@"
285 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
286 cleanup
287 PID=mods
288 mods_info
291 misspatch_error () {
292 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
293 printtask "!! error: $@ "
294 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
295 echo ""
296 printtask "!! The Auto-Patcher could not find its patches and/or tools!"
297 echo ""
298 echo "* Did you run ./batch.sh first?"
299 echo ""
300 echo "The patch_patches.tgz and patch_tools.tgz need to be in this directory,"
301 echo " one way or another..."
302 echo ""
303 cleanup
304 brief_help
307 misstools_error () {
308 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
309 printtask "!! error: $@ "
310 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
311 printtask "Your set-up is missing a dependency."
312 echo "We require JDK, tar, patch and cpio."
313 echo ""
314 echo ""
315 echo "Each distro is different"
316 echo "but ensure you have them all installed and try again."
317 echo ""
318 cleanup
319 brief_help
322 printtask () {
323 echo "" >> "$LOG"
324 echo $@ | tee -a "$LOG"
327 copyfailed () {
328 echo ""
329 printtask "File for which patching failed:"
330 printtask "---------------------------------------------"
331 echo ""
332 printtask "${FAIL##*/}"
333 echo ""
334 echo "---------------------------------------------"
335 echo ""
336 echo "We can try to add a premade copy of those files."
337 echo "This sometimes works."
338 echo ""
339 echo "But IT MAY NOT WORK!!!"
340 echo ""
341 echo ""
342 askconsent && return 0 || return 1
345 askconsent () {
346 sleep 1
347 echo -n "Do you want to proceed ? (YES/no) "
348 read PROCEED
349 echo "askconsent final = ${PROCEED}: for $FAIL" >> "$LOG"
350 case $PROCEED in
351 [Yy] | [Yy][Ee][Ss])
352 return 0; # successful:
353 echo "*** You (or ApG) have elected to use a prepatched copy of $FAIL ***" >> "$LOG"
356 return 1; # error
357 echo "*** You have declined to insert $FAIL by not answering 'yes' at the prompt. ***" >> "$LOG"
359 esac
362 replace_updater () {
364 # Function for devices that use SDcard installs. Also to be tested for CM7
365 # since CM7 seems to use an updater-script that wipes EMMC. Testing
367 \rm $UPDATER_LOC/$UPDS
368 \cp patches/common/$UPDATER_LOC/$UPDS $UPDATER_LOC
369 echo "run_program(\"/sbin/busybox\", \"umount\", \"/system\");" >> UPDATE.txt
370 cat UPDATE.txt >> $UPDATER_LOC/$UPDS
371 echo ""
372 echo "New updater-script being used:" >> "$LOG"
373 echo "-----------------------------" >> "$LOG"
374 cat $UPDATER_LOC/$UPDS >> "$LOG"
377 abspath () {
378 case `uname -s` in
379 CYGWIN*)
380 echo $(cygpath -ua "$1") | sed 's:/$::g' | sed 's: :\\ :g'
382 Darwin)
383 #[[ $(echo $1 | awk '/^\//') == $1 ]] && echo "$1" || echo "$PWD/$1"
384 [[ ${1:0:1} == "/" ]] && echo "$1" || echo "$PWD/$1"
386 Linux)
387 echo $(readlink -f "$1")
390 if [[ ${1:0:1} == "/" ]]; then
391 echo "$1"
392 elif [[ ${1:0:2} == "./" ]]; then
393 echo "$PWD/${1:2}"
394 else
395 echo "$PWD/$1"
398 esac
401 mods_display () {
402 echo ""
403 echo "The Auto-Patcher $VERSION"
404 echo "*******************************"
405 echo ""
406 echo "The available mods are"
407 echo "****************************************************"
408 echo "* pdroid openpdroid voice v6supercharger *"
409 echo "* voice insecure secure external_internal *"
410 echo "* tabletUI 3gdongle pd2.0 *"
411 echo "****************************************************"
412 echo ""
413 echo "To find out more about any mod, simply enter:"
414 echo " ./auto_patcher -h <MODNAME>"
415 echo ""
416 cleanup
419 mods_info () {
420 DEPENDENCY="None" # default
421 DEV="Unknown" # default
422 CEILING=$CURRENT_ANDROID # Default is that everything works...we'll see.
423 case $PID in
424 mods)
425 mods_display
426 exit
428 auto*)
429 echo ""
430 echo "**************************************"
431 echo "The Auto-Patcher ate a kitten once..."
432 echo "**************************************"
433 printusage_help
435 advanced)
436 cd patches/
437 (advanced_help && find -H * -name 2012*) | more -d
438 echo ""
439 brief_help
441 voice)
442 FLOOR=4.0.0
443 DESC="Use on wifi-only tablets to have the software register as 'voice-enabled'. Allows VOIP like Google Voice to function."
444 DESC="bongostl's setup method here: http://forum.xda-developers.com/showthread.php?t=1823701"
445 DEV="bongostl"
448 v6supercharger)
449 FLOOR=4.0.0
450 CEILING=4.2.1
451 DESC="A memory-management tool. It requires smali edits for Android roms 4.0+. The Auto-Patcher applies all 50+ edits recommended by the dev."
452 DEV="Zeppelinrox"
453 DEPENDENCY="The V6 Supercharger Script. Get it at http://forum.xda-developers.com/showthread.php?t=991276/"
455 pdroid)
456 FLOOR=2.3.7
457 CEILING=4.1.2
458 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. (It's the 'openpdroid' mod within the Auto-Patcher)."
459 DEV="Svyat"
460 DEPENDENCY="The Pdroid app. You can get it at http://forum.xda-developers.com/showthread.php?t=1923576"
462 pd2.0)
463 FLOOR=4.1.2
464 CEILING=4.1.2
465 DESC="An expansion of the PDroid application/framework."
466 DEV="CollegeDev"
467 DEPENDENCY="The free PDroid2.0 app available at http://forum.xda-developers.com/showthread.php?t=1923576"
469 openpdroid)
470 FLOOR=4.1.2
471 CEILING=4.2.1
472 DESC="A fork of the open-source PDroid and Pdroid2.0 framework."
473 DEV="FFU5y/wbedard/mateorod/Community"
474 DEPENDENCY="The PDroidManager app freely available from Google Play or http://forum.xda-developers.com/showthread.php?t=1994860"
476 opendroid)
477 echo ""
478 echo "No mod named 'opendroid'. You probably mean 'openpdroid'. Try again."
479 PID="mods"
480 mods_info
482 external_internal)
483 FLOOR=2.3.3
484 DESC="Swap internal and external storage."
486 insecure)
487 FLOOR=2.3.3
488 DESC="Make any boot.img insecure and allow remount as well as adb push/pull of system files. True root."
490 secure)
491 FLOOR=2.3.3
492 DESC="Make any boot.img secure."
494 3gdongle)
495 FLOOR=4.1.0
496 CEILING=4.2.1
497 DESC="Allows 3gdongles to work on wifi tablets w/o 3rd party applications."
498 DEV="trevd"
499 DEPENDENCY="None, but read the troubleshooting guide at http://forum.xda-developers.com/showthread.php?t=1798631"
501 tabletUI)
502 FLOOR=4.1.0
503 CEILING=4.1.2
504 DESC="Changes the user interface of Phones and Phablets to the popular Tablet UI."
505 DEV="barmullio"
508 FLOOR=?????
509 CEILING=?????
510 DESC="??? Unknown modtype ??? Check your spelling or the mod list!"
511 #DESC1="./auto_patcher -h mods"
512 esac
513 # strip decimals from android version (i.e. 2.3.7 becomes 237) so we can do math
514 NVID=${VID//[.]/}
515 COMPATF=${FLOOR//[.]/}
516 COMPATC=${CEILING//[.]/}
519 apk_check () {
520 if [ -f patches/$P/$A/$R/$B/$FILE ]; then
521 echo "... Patching $APK failed, but we will copy over a prepatched file ..."
522 \cp -av patches/$P/$A/$R/$B/$FILE $FILE >> "$LOG"
523 else
524 print_error "failed patching $APK!!!"
527 compat_check () {
528 for P in ${PID[@]}; do
529 mods_info
530 if [[ "$NVID" -lt "$COMPAT" ]]; then
531 mismatch_error "Your Android $VID rom is too old! The minimum for $P is Android $FLOOR!"
533 if [[ "$NVID" -gt "$COMPATC" ]]; then
534 mismatch_error "Sorry, $P has not been made available for Android $VID yet!"
536 done
538 extpath () {
539 case `uname -s` in
540 CYGWIN*)
541 echo $(cygpath -da "$1")
544 echo $(abspath "$1")
546 esac
549 #contains () { for e in "${@:2}"; do [[ "$e" = "$1" ]] && return 0; done; return 1; }
551 parse () { echo "${1%%_*}"; }
553 getbuildprop () {
554 if [ -f system/build.prop ]; then
555 result=(`grep $1 system/build.prop | tr -d '\r' | tr '=' ' '`)
556 echo "${result[1]}"
557 else
558 echo ""
563 aosp_mod_check() {
564 jar -xvf "$ROMX" system/framework/framework2.jar >> $LOG
565 if [ -s system/framework/framework2.jar ]; then
566 ever_check
567 else
568 AOSP=aosp-jb
570 echo $AOSP
573 ever_check() {
574 MID=$(getbuildprop ro.build.romversion)
575 if [[ "$MID" == "Evervolv"* ]]; then
576 AOSP=aosp-ever
577 else
578 MID=$(getbuildprop ro.build.display.id)
579 if [[ "$MID" == "ev"* ]]; then
580 AOSP=aosp-ever
581 else
582 AOSP=aosp
585 echo $AOSP
588 pa_check() {
589 CMID=$(getbuildprop ro.modversion)
590 PAID=$(getbuildprop ro.pa.version)
591 MID=$(getbuildprop ro.build.display.id)
592 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
593 DID=$(getbuildprop ro.product.device)
594 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
595 if [[ -n $PAID ]]; then
596 RID=pa
597 else
598 case $CMID in
599 [Pp][Aa]*)
600 RID=pa;
603 RID=cm;
605 esac
609 proberom () {
610 VID=$(getbuildprop ro.build.version.release)
611 if [ ${#VID} -lt 4 ]; then # in case of non-standard versioning in build.prop (defy!)
612 ANDR=$VID
613 else
614 ANDR="${VID%.*}" # Cut to 1 significant digit to cover specific range or release.
616 if [ "$ANDR" == "2.3" ]; then
617 FLAVR=gingerbread
618 API=10
619 RID=cm;
620 elif [ "$ANDR" == "4.0" ]; then
621 FLAVR=ics
622 API=15
623 MID=$(getbuildprop ro.rommanager.developerid)
624 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.modversion))
625 DID=$(getbuildprop ro.product.device)
626 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
628 case "$MID" in
629 pa|cm9|cm|cyanogenmod*)
630 RID=cm;
632 aokp|teamkang)
633 RID=aokp;
635 aosp*)
636 RID=aosp;
639 echo "!!! $MID is not supported yet, trying generic latest !!!"
641 esac
642 elif [ "$ANDR" == "4.1" ]; then
643 FLAVR=jellybean
644 API=16
645 CMID=$(getbuildprop ro.cm.version)
646 if [[ -n $CMID ]]; then
647 pa_check
648 else
649 MID=$(getbuildprop ro.build.display.id)
650 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
651 DID=$(getbuildprop ro.product.device)
652 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
653 case "$MID" in
654 cm10|cm*|cyanogenmod*)
655 RID=cm;
657 aokp*|teamkang)
658 RID=aokp;
660 pa*)
661 RID=pa;
663 ev*)
664 RID=aosp-ever;
667 RID=`aosp_mod_check`;
669 esac
671 elif [ "$ANDR" == "4.2" ]; then
672 FLAVR=jellybean
673 API=17
674 CMID=$(getbuildprop ro.cm.version)
675 MID=$(getbuildprop ro.build.display.id)
676 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
677 DID=$(getbuildprop ro.product.device)
678 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
680 case "$MID" in
681 cm10|cm*|cyanogenmod*)
682 RID=cm;
684 aokp*|teamkang)
685 RID=aokp;
687 pa*)
688 RID=pa;
690 ev*|Ever*)
691 RID=aosp-ever;
694 RID=`ever_check`;
696 esac
697 else
698 print_error "unknown ROM version $VID"
700 echo "... result of ROM check: version= $VID rom= $RID ..."
704 # Advanced build date query
705 # This should set the patch date automatically.
707 build_query() {
708 UTC=$(getbuildprop ro.build.date.utc)
710 # Difference in how OS X and Linux/Cygwin handles 'date' utility
711 case `uname -s` in
712 [Dd]arwin)
713 BDID=`date -r $UTC +%Y%m%d`
714 echo "#### Darwin Build Query used ####" >> "$LOG"
717 BDID=`date -d "1970-01-01 UTC $UTC seconds" +"%Y%m%d"`
718 echo "#### Standard Build Query ####" >> "$LOG"
720 esac
722 # If patch date is specified on CLI, use that patch date
723 if [ $# -gt 3 ]; then
724 BID=${4//,/ };
725 BDID=$BID
726 else
727 case $ANDR in
728 gingerbread)
729 # CM7 roms do not have UTC time stamp- so no build query.
730 BID=latest;
731 echo "*** CM7 roms default to latest patches. If using an older rom ***"
732 echo "*** specify patch date on command line. Use -h to see available patches ***"
735 for P in ${PID[@]}; do
736 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
737 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
738 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
739 PAR=patches/$P/$A/$R
740 PARB=patches/$P/$A/$R/$B
741 DATES=`ls patches/$P/$A/$R/ | grep '201*'`
742 # Intialize variable - High so as to determine lowest in first loop.
743 BID=20201231
744 # find earliest available patch date
745 for i in $DATES; do
746 if [[ $i -lt $BID ]]; then
747 BID=$i
749 done
750 # Check if earliest patches are from before build date. Else use earliest
752 # If older than earliest patch set, then find best match
753 if [[ $(($BID-$BDID)) -lt 0 ]]; then
754 for g in $DATES; do
755 # use any patch that matches $UTC
756 if [[ $(($BDID-$g)) -eq 0 ]]; then
757 BID=$g
758 break
759 # Set highest $BID w/o going over $UTC
760 elif [[ $(($BDID-$g)) -gt 0 ]] && [[ $g -gt $BID ]]; then
761 BID=$g
763 done
765 echo "... $PID patch date has been set to: $BID ..."
766 B=$BID
767 break
768 done
770 esac
774 proberil () {
775 RIL=$(getbuildprop ro.telephony.ril_class)
776 [[ -n $RIL ]] && printtask "... result of ROM check: RIL= $RIL"
779 rominfo () {
780 echo "# VER= $VERSION" >> "$LOG"
781 echo "# OS= $OSTYPE ${BIT}bit" >> "$LOG"
782 echo "# VID= $VID" >> "$LOG"
783 echo "# PID= ${PID[@]}" >> "$LOG"
784 echo "# MID= $MID" >> "$LOG"
785 echo "# RID= $RID" >> "$LOG"
786 echo "# ANDR= $ANDR" >> "$LOG"
787 echo "# BDID= $BDID" >> "$LOG"
788 echo "# DID= $DID" >> "$LOG"
789 echo "# BID= $BID" >> "$LOG"
793 if [[ $1 == -h ]]; then
794 if [ $# -gt 1 ]; then
795 PID=$2
796 mods_info
797 echo ""
798 echo "The Auto-Patcher $VERSION by Mateorod and Pastime1971"
799 echo "*************************************************"
800 echo ""
801 echo "Mod Name: $PID"
802 echo ""
803 echo " $DESC"
804 if [[ -z $DESC1 ]]; then # test to see is there is a second DESC line
805 echo "$DESC1"
807 if [[ $((DESC2)) -gt 0 ]]; then
808 echo "$DESC2"
810 echo ""
811 echo "Developer: $DEV"
812 echo "Dependancies: $DEPENDENCY"
813 echo ""
814 echo "Works on ROMs from Android $FLOOR -> $CEILING"
815 echo
816 brief_help
817 exit
821 [[ $# -lt 1 || -z $1 ]] && PID="mods" && mods_info
822 [[ $1 == "-h" ]] && usage_help | less && display_help
824 echo ""
825 echo "The Auto-Patcher $VERSION"
826 echo ""
827 # by pastime1971 and mateorod
829 ROOT=$(abspath `dirname "$0"`)
830 TOOL="$ROOT/patch_tools.tgz"
831 PTCH="$ROOT/patch_patches.tgz"
832 cleanup
833 # set temporaray directory
834 DATE=`date +%Y%m%d%H%M%S`
835 TEMP=$ROOT/tmp$DATE
836 TMP=$ROOT/tmp$DATE
837 TMPDIR=$ROOT/tmp$DATE
838 mkdir "$TEMP"
839 ROM=$(abspath "$1")
840 ROMX=$(extpath "$1")
842 if [[ $OSTYPE == "cygwin" ]]; then
843 EXE=".exe"
844 PGFORM="0x"
847 LOG=$(abspath ./log$DATE.txt)
848 #echo $ROOT $TOOL $ROM $TEMP "$LOG"
849 echo "ROOT= $ROOT" >> "$LOG"
850 echo "TOOL= $TOOL" >> "$LOG"
851 echo "ROM= $ROM" >> "$LOG"
852 echo "ROMX= $ROMX" >> "$LOG"
854 \rm -f $RESTORE.zip $UPDATE.zip
856 CHK=$(getconf LONG_BIT)
857 if [[ $CHK = "64" ]]; then
858 BIT=64
859 else [[ $BIT = "32" ]];
860 BIT=32
864 printtask "### verify tools ###"
865 which patch >> "$LOG" || misstools_error "Missing \"patch\" utility."
866 which tar >> "$LOG" || misstools_error "Missing \"tar\" utility"
867 which jar >> "$LOG" || misstools_error "Missing \"Java Development Kit\" (JDK)"
868 which java >> "$LOG" || misstools_error "Missing \"Java Development Kit\" (JDK)"
869 which cpio >> "$LOG" || misstools_error "Missing \"cpio\" utility"
870 [ -f "$TOOL" ] || misspatch_error "patch_tool.tgz is missing"
871 [ -f "$PTCH" ] || misspatch_error "patch_patches.tgz is missing"
872 printtask "### verify ROM ###"
873 [ -f "$ROM" ] || print_error "Cannot find $1!! Make sure you have the location and name right"
874 echo "### running $0 $@" >> "$LOG"
875 cd "$TEMP"
877 PATH="$TEMP:$PATH"
878 export PATH
879 echo "PATH= $PATH" >> "$LOG"
881 printtask "### unzip patch tools ###"
882 tar xzf "$TOOL" > /dev/null || print_error "failed extracting tools !!!"
884 # Get OS specific tools
885 case `uname -s` in
886 CYGWIN*)
887 \mv cygwin/aapt.exe .
888 \mv cygwin/*.exe boot/
889 \rm -rf cygwin # why? If you want to we can keep/add it to mac/linux, though.
891 [Dd]arwin)
892 \mv mac/aapt .
894 [Ll]inux)
895 \mv linux/aapt .
898 \mv linux/aapt .
900 esac
901 # Ensure aapt permissions - possibly to one day be expanded to all tools in a function.
902 chmod a+x aapt$EXE
904 printtask "### unzip patch patches ###"
905 tar xzf "$PTCH" > /dev/null || print_error "failed extracting patches !!!"
907 # we need build.prop for both RIL probing and ROM probing
908 jar -xvf "$ROMX" system/build.prop 2>> "$LOG" || print_error "failed extracting build.prop from $ROMX !!!"
910 # rom + ril type
911 proberil
912 printtask "### probe rom type ###"
913 proberom
915 # rom type
916 if [ $# -gt 1 ]; then
917 PIT=$2
918 if [[ "$PIT" = "-h" ]]; then
919 display_help
922 if [ $# -gt 2 ]; then
923 RID=$3
924 case "$RID" in
925 cm10|cm*|cyanogenmod*)
927 aokp*|teamkang)
928 RID=aokp;
930 pa*)
931 RID=pa;
933 aosp-ever)
934 RID=aosp-ever;
936 aosp*)
937 case "ANDR" in
938 4.1)
939 RID=`aosp_mod_check`;
942 RID=`ever_check`
944 esac
946 201*)
947 date_error "You must specify ROMTYPE if designating a patch date!!"
950 rom_error "$RID is not a valid ROMTYPE!!"
952 esac
953 echo "... Using $RID patches ..."
954 else
955 echo "... Using results of ROM check ..."
958 # patch type
959 if [ $# -gt 1 ]; then
960 PIL=${2//,/ } # If more than one mod, make string separated by spaces
961 else
962 PIL="openpdroid"
963 echo "No mods selected. Defaulting to openpdroid, since that's what you probably want..."
966 PID=(${PIL// / }) # turn string into array
967 COPYPID=("${PID[@]}") # working copy to iterate over
968 MODS_NUMBER=${#COPYPID[@]} # number of elements (mods)
970 if [[ $MODS_NUMBER > 1 ]]; then
971 INDEX=0
972 for p in ${COPYPID[@]}; do
973 if [ "$p" = "pdroid" ] || [ "$p" = "pd2.0" ] ||[ "$p" = "openpdroid" ]; then
974 SPID[0]=$p
975 unset COPYPID["$INDEX"]
976 break
977 else
978 INDEX=$((INDEX + 1))
980 done
981 for p in ${COPYPID[@]}; do
982 if [ "$p" = "pdroid" ] || [ $p = "pd2.0" ] ||[ $p = "openpdroid" ]; then
983 conflict_error "Those mods conflict! Only one pdroid mod at a time!"
984 else
985 i=${#SPID[@]}
986 SPID[i]=$p
987 i+=1
989 done
990 else
991 SPID=${COPYPID[@]}
993 for P in ${PIL[@]}; do
994 [[ ${PID[@]} =~ $P ]] || PID=(${PID[@]} $P)
995 done
997 # Check to make sure selected roms are available for the Android version of patched ROM
998 compat_check
1000 # Build date
1001 if [ $# -gt 3 ]; then # if a date is specified on command line...
1003 # Set date to match argument and ensure that patches with that date exist
1004 BID=$4
1005 [ -d patches/$P/$A/$R/$BID ] || print_error "No $P patches for $RID on $BID!! Try the help menu!!"
1007 # Run build_query- this overrides the above but gets useful info
1008 build_query
1009 # Reset patch date to argument
1010 BID=$4
1011 echo "... $PID patch date set manually to: $BID ..."
1012 else
1013 build_query # if no date specified, use one from build_query
1016 # echo ROM info
1017 rominfo
1019 if [[ ( "$PID" == "-h" || "$RID" == "-h" || "$BID" == "-h" ) ]]; then
1020 #Although this placement may be perfect for romfilter. although it throws the scheme...
1021 display_help
1023 #Begin cycle
1025 for P in ${PID[@]}; do
1026 [ -d patches/$P ] || print_error "$P is not available"
1027 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1028 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1029 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1031 unset FILES
1032 [ -f patches/$P/files.txt ] && FILES=$(cat patches/$P/files.txt)
1033 [ -f patches/$P/$A/files.txt ] && FILES=$(cat patches/$P/$A/files.txt)
1034 [ -f patches/$P/$A/$R/files.txt ] && FILES=$(cat patches/$P/$A/$R/files.txt)
1035 [ -f patches/$P/$A/$R/$B/files.txt ] && FILES=$(cat patches/$P/$A/$R/$B/files.txt)
1036 for FILE in ${FILES[@]}; do
1037 case "$FILE" in
1038 +system/*)
1039 [[ ${CID[@]} =~ ${FILE:1} ]] && print_error "${FILE:1} is already being copied" || CID=(${CID[@]} ${FILE:1})
1041 -system/*)
1042 [[ ${EID[@]} =~ ${FILE:1} ]] || EID=(${EID[@]} ${FILE:1})
1044 system/*.jar)
1045 [[ ${JID[@]} =~ $FILE ]] || JID=(${JID[@]} $FILE)
1046 echo "set_perm(0, 0, 0644, \"/$FILE\");" >> UPDATE.txt
1048 system/*.apk)
1049 [[ ${AID[@]} =~ $FILE ]] || AID=(${AID[@]} $FILE)
1050 echo "set_perm(0, 0, 0644, \"/$FILE\");" >> UPDATE.txt
1052 *.img)
1053 [[ ${IID[@]} =~ $FILE ]] || IID=(${IID[@]} $FILE)
1055 system/*)
1056 [[ ${TID[@]} =~ $FILE ]] || TID=(${TID[@]} $FILE)
1058 esac
1059 done
1060 done
1061 echo "### DELETE FILES= ${EID[@]}" >> "$LOG"
1062 echo "### COPY FILES= ${CID[@]}" >> "$LOG"
1063 echo "### JAR FILES= ${JID[@]}" >> "$LOG"
1064 echo "### APK FILES= ${AID[@]}" >> "$LOG"
1065 echo "### IMG FILES= ${IID[@]}" >> "$LOG"
1066 echo "### TXT FILES= ${TID[@]}" >> "$LOG"
1068 # extract system files
1069 printtask "### unzip rom ###"
1070 jar -xvf "$ROMX" ${JID[@]} ${AID[@]} ${IID[@]} ${TID[@]} 2>> "$LOG" || print_error "failed extracting ${JID[@]} ${AID[@]} ${IID[@]} from $ROMX !!!"
1073 # Update/Restore.zip scripts and prep
1074 printtask "### create updater script ###"
1075 UPDATER_LOC=META-INF/com/google/android
1076 UPDS=updater-script
1077 UPDATE="update-$RID-$DID-$BDID-${PIL// /-}"
1078 RESTORE="restore-$RID-$DID-$BDID"
1080 jar -xvf "$ROMX" $UPDATER_LOC/$UPDS $UPDATER_LOC/update-binary
1081 jar -xvf "$ROMX" $UPDATER_LOC/update-binary-installer 1> /dev/null 2> /dev/null
1083 # Determine Installer- Aroma or ClockworkMod
1084 if [ -f $UPDATER_LOC/update-binary-installer ]; then
1085 printtask "... using Aroma installer ..."
1086 \mv $UPDATER_LOC/update-binary-installer $UPDATER_LOC/update-binary
1087 else
1088 printtask "... using Clockworkmod installer ..."
1091 # Create updater scripts
1092 cat patches/common/updater-message.txt >> $UPDS
1093 cat $UPDATER_LOC/$UPDS | grep ^mount | grep "/system" | head -n 1 >> $UPDS
1094 [ -s $UPDS ] || echo "run_program(\"/sbin/busybox\", \"mount\", \"/system\");" >> $UPDS
1095 # restore the original
1096 for FILE in ${EID[@]}; do
1097 jar -xvf "$ROMX" $FILE 2> /dev/null || printtask "!!! warning $FILE cannot be restored !!!"
1098 done
1099 # replace with the original or delete it
1100 for FILE in ${CID[@]}; do
1101 jar -xvf "$ROMX" $FILE 2> /dev/null || echo "delete(\"/$FILE\");" >> $UPDS
1102 done
1103 echo "package_extract_dir(\"system\", \"/system\");" >> $UPDS
1104 # permission management for files that need specific perms
1105 cat $UPDATER_LOC/$UPDS | grep set_perm | grep "/system" >> $UPDS
1106 for P in ${PID[@]}; do
1107 if [ -s patches/$P/$A/set_perm.txt ]; then
1108 echo "...setting permissions..."
1109 cat patches/$P/$A/set_perm.txt >> $UPDS
1111 done
1112 cat $UPDATER_LOC/$UPDS | grep ^unmount | grep "/system" | head -n 1 >> $UPDS
1113 [[ ${IID[@]} =~ boot.img ]] && cat $UPDATER_LOC/$UPDS | grep "boot.img" >> $UPDS
1114 echo "ui_print(\" .\");" >> $UPDS
1115 echo "ui_print(\" .\");" >> $UPDS
1116 echo "ui_print(\" done!\");" >> $UPDS
1117 cat $UPDS > $UPDATER_LOC/$UPDS
1118 echo "# generated $UPDS" >> "$LOG"
1119 cat $UPDS >> "$LOG"
1121 printtask "### create restore.zip ###"
1122 jar -cvf tmp.zip ${JID[@]} ${AID[@]} ${IID[@]} META-INF > /dev/null 2>> "$LOG"
1123 java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip signed.zip 2>> "$LOG"
1124 \mv signed.zip $RESTORE.zip
1125 \rm -f tmp.zip
1128 # Begin patching process
1130 # decompile system files
1131 printtask "### decompile system files ###"
1132 for FILE in ${JID[@]}; do
1133 JAR=${FILE##*/}
1134 printtask "... decompile $JAR ..."
1135 java -jar baksmali.jar -b -a $API -o tmp/${FILE}.out/smali ${FILE} >> "$LOG" 2>> "$LOG"
1136 if [ $FILE == "system/framework/framework.jar" ]; then
1137 printtask "... extract preloaded-classes ..."
1138 jar -xvf ${FILE} preloaded-classes >> "$LOG" 2>> "$LOG"
1139 \mv preloaded-classes tmp/${FILE}.out/
1141 done
1143 # install framework-files for APK...
1144 if [ ${#AID[@]} -gt 0 ]; then
1145 jar -xvf "$ROMX" system/framework/framework-res.apk >> "$LOG"
1146 printtask "... installing framework files ..."
1147 java -jar apktool.jar if system/framework/framework-res.apk
1148 # Decompile APKs
1149 for FILE in ${AID[@]}; do
1150 APK=${FILE##*/}
1151 if [ -f $FILE ]; then
1152 printtask "... decompile $APK ..."
1153 java -jar apktool.jar d -f $FILE tmp/$FILE.out
1155 done
1158 # Unpack image files {boot.img only so far...}
1159 for FILE in ${IID[@]}; do
1160 printtask "### unpacking $FILE ###"
1161 case "$FILE" in
1162 boot.img)
1163 if [ -f boot.img ]; then
1164 cd boot
1165 ./unpackbootimg$EXE -i ../boot.img >> "$LOG" 2>> "$LOG"
1166 mkdir ramdisk
1167 cd ramdisk
1168 gzip -dc ../boot.img-ramdisk.gz | cpio -i >> "$LOG" 2>> "$LOG"
1169 cd ../../
1170 else
1171 print_error "A mod needs to patch boot.img! This rom does not contains boot.img."
1175 print_error "cannot process $FILE"
1177 esac
1178 done
1180 # apply system modification
1182 for P in ${PID[@]}; do
1183 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1184 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1185 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1186 PAR=patches/$P/$A/$R
1187 PARB=patches/$P/$A/$R/$B
1189 unset FILES COPY DELS JARS APKS IMGS TXTS
1190 [ -f patches/$P/files.txt ] && FILES=$(cat patches/$P/files.txt)
1191 [ -f patches/$P/$A/files.txt ] && FILES=$(cat patches/$P/$A/files.txt)
1192 [ -f patches/$P/$A/$R/files.txt ] && FILES=$(cat patches/$P/$A/$R/files.txt)
1193 [ -f patches/$P/$A/$R/$B/files.txt ] && FILES=$(cat patches/$P/$A/$R/$B/files.txt)
1194 for FILE in ${FILES[@]}; do
1195 case $FILE in
1196 +system/*)
1197 COPY=(${COPY[@]} ${FILE:1})
1199 -system/*)
1200 DELS=(${DELS[@]} ${FILE:1})
1202 system/*.jar)
1203 JARS=(${JARS[@]} $FILE)
1205 system/*.apk)
1206 APKS=(${APKS[@]} $FILE)
1208 *.img)
1209 IMGS=(${IMGS[@]} $FILE)
1211 system/*)
1212 TXTS=(${TXTS[@]} $FILE)
1214 esac
1215 done
1217 [[ -n ${COPY[@]} ]] && printtask "### copy patch $P/$A/$R/$B ###"
1218 for FILE in ${COPY[@]}; do
1219 printtask "... copying $FILE ..."
1220 DEST=${FILE%/*}
1221 mkdir -p ./$DEST
1222 if [ -e patches/$P/$A/$R/$B/$FILE ]; then
1223 [ -e $FILE ] && printtask "... overwriting $FILE from $P ..."
1224 \cp -av patches/$P/$A/$R/$B/$FILE ./$DEST >> "$LOG"
1225 else
1226 print_error "$FILE is missing in the patch. Please upload your logfile to the support thread!"
1228 done
1230 # unconditional smali copying- For particularly troublesome files
1231 [ -f patches/$P/smali.txt ] && SMALI=$(cat patches/$P/smali.txt)
1232 [ -f patches/$P/$A/smali.txt ] && SMALI=$(cat patches/$P/$A/smali.txt)
1233 [ -f patches/$P/$A/$R/smali.txt ] && SMALI=$(cat patches/$P/$A/$R/smali.txt)
1234 [ -f patches/$P/$A/$R/$B/smali.txt ] && SMALI=$(cat patches/$P/$A/$R/$B/smali.txt)
1235 MOVE=${SMALI##*/}
1236 for SMALI in ${SMALI[@]}; do
1237 if [ -f patches/$P/$A/$R/provisionals/$SMALI ]; then
1238 printtask "... overwriting $MOVE ..."
1239 \cp -a patches/$P/$ANDR/$R/provisionals/$SMALI tmp/$SMALI >> "$LOG"
1240 elif [ -f patches/$P/$A/provisionals/$SMALI ]; then
1241 printtask "... overwriting $MOVE ..."
1242 \cp -a patches/$P/$ANDR/provisionals/$SMALI tmp/$SMALI >> "$LOG"
1244 done
1246 [[ -n ${DELS[@]} ]] && printtask "### delete patch $P/$A/$R/$B ###"
1247 for FILE in ${DELS[@]}; do
1248 printtask "... deleting $FILE ..."
1249 \rm -rf ./$FILE
1250 done
1251 [[ -n ${JARS[@]} ]] && printtask "### jar patch $P/$A/$R/$B ###"
1252 for FILE in ${JARS[@]}; do
1253 JAR=${FILE##*/}
1254 NAME=${JAR%.jar}
1255 printtask "... apply $NAME.patch ..."
1256 patch -Nls -p1 -d tmp/${FILE}.out < $PARB/${NAME}.patch 2>&1 > ${JAR}.log
1257 cat ${JAR}.log | tee -a "$LOG"
1258 case "$NAME" in
1259 framework)
1260 # patch preloaded-classes only if a patch exists
1261 if [ -f $PARB/preloaded.patch ]; then
1262 printtask "... apply preloaded.patch ..."
1263 patch -Nls -p1 -d tmp/${FILE}.out < $PARB/preloaded.patch 2>&1 > preloaded.log
1264 cat preloaded.log | tee -a "$LOG"
1265 [[ `grep FAILED preloaded.log` != "" ]] && print_error "failed preloaded.patch"
1269 echo -n "" # do nothing else
1271 esac
1272 # substitute failed smali with provisional (a prepatched smali file)
1273 unset FAILS
1274 FAILS=(`grep FAILED ${JAR}.log | sed -e 's/.*smali\///' | sed -e 's/\.rej//'`)
1275 if [[ -n ${FAILS[@]} ]]; then
1276 printtask "!!! PATCHING FAILED FOR ${FAILS[@]} !!!"
1277 echo "### replace ${FAILS[@]} ###" > ${JAR}.log
1278 for FAIL in ${FAILS[@]}; do
1279 PROVISIONAL="patches/$P/$ANDR/provisionals/${FILE}.out/smali/${FAIL}"
1280 echo "!!! patch error for $FAIL !!!" >> "$LOG"
1281 #cat tmp/$FILE.out/smali/${FAIL}.rej >> "$LOG" # FOR DEBUGGING
1282 [[ ${SID[@]} =~ $FAIL ]] && print_error "$FAIL was already replaced before"
1283 [ -f "$PROVISIONAL" ] || print_error "failed $FAIL in $JAR cannot be remedied"
1284 copyfailed
1285 printtask "... replace $FAIL ..."
1286 \rm -rf tmp/${FILE}.out/smali/${FAIL} tmp/${FILE}.out/smali/${FAIL}.orig tmp/${FILE}.out/smali/${FAIL}.rej
1287 \cp -av "$PROVISIONAL" tmp/${FILE}.out/smali/${FAIL} >> "$LOG"
1288 SID=(${SID[@]} $FAIL)
1289 done
1291 [[ `grep FAILED ${JAR}.log` != "" ]] && print_error "failed $NAME.patch"
1292 garbage tmp/${FILE}.out
1294 # run special $JAR.sh scripts if any JAR needs special attention
1295 if [ -f patches/$P/$A/$R/$B/${JAR}.sh ]; then
1296 printtask "... apply $JAR.sh ..."
1297 . patches/$P/$A/$R/$B/${JAR}.sh 2>&1 > ${JAR}.log
1298 cat ${JAR}.log | tee -a "$LOG"
1300 done
1302 [[ -n ${APKS[@]} ]] && printtask "### apk patch $P/$A/$R/$B ###"
1303 for FILE in ${APKS[@]}; do
1304 APK=${FILE##*/}
1305 if [ -d "tmp/${FILE}.out" ] ; then
1306 printtask "... apply $APK.patch ..."
1307 patch -Nls -p2 -d tmp/${FILE}.out < $PARB/${APK}.patch 2>&1 >> ${APK}.log
1308 cat ${APK}.log | tee -a "$LOG"
1309 [[ `grep FAILED ${APK}.log` != "" ]] && apk_check
1310 garbage tmp/${FILE}.out
1311 else
1312 echo "No $APK in your ROM. Not able to patch this file."
1313 echo "## No $APK in ROM ###" >> "$LOG"
1315 done
1316 [[ -n ${IMGS[@]} ]] && printtask "### img patch $P/$A/$R/$B ###"
1317 for FILE in ${IMGS[@]}; do
1318 IMG=${FILE##*/}
1319 printtask "... applying $IMG.patch ..."
1320 patch -Nls -p1 -d boot/ramdisk < $PARB/${IMG}.patch >> "$LOG" || print_error "failed patching $FILE"
1321 done
1323 # Text Editing Functions --this can really do just about anything. Needs a working restore!
1324 [[ -n ${TXTS[@]} ]] && printtask "### text patch $P/$A/$R/$B ###"
1325 for FILE in ${TXTS[@]}; do
1326 TXT=${FILE##*/}
1327 if [[ -f $PARB/${TXT}.patch ]]; then
1328 printtask "... apply $TXT.patch ..."
1329 patch -Nls -p2 -d system/ < $PARB/${TXT}.patch 2>&1 > ${TXT}.log
1330 #cat ${TXT}.log | tee -a "$LOG"
1331 [[ `grep FAILED ${TXT}.log` != "" ]] && print_error "failed $TXT.patch"
1333 if [[ -f $PAR/${TXT}.awk ]]; then
1334 printtask "... apply $TXT.awk ..."
1335 awk -f $PAR/${TXT}.awk $FILE > text || print_error "failed $TXT.awk"
1336 mv text $FILE
1338 if [[ -f $PAR/${TXT}.sed ]]; then
1339 printtask "... apply $TXT.sed ..."
1340 sed -f $PAR/${TXT}.sed $FILE > text || print_error "failed $TXT.sed"
1341 mv text $FILE
1343 if [[ -f $PAR/${TXT}.sh ]]; then
1344 printtask "... apply $TXT.sh ..."
1345 . $PAR/${TXT}.sh 2>&1 >> ${TXT}.log || print_error "failed $TXT.sh"
1347 garbage system/
1348 done
1349 done
1351 # Device specific scripts- Placement is up-for-review
1352 if [ -f patches/devices/$DID/$DID.sh ]; then
1353 . patches/devices/$DID/$DID.sh
1356 # Replace updater-script for CM7- it formats system -Testing
1357 if [ "$ANDR" == "gingerbread" ]; then
1358 replace_updater
1361 # Rebuilding system files
1363 [[ -n ${JID[@]} ]] && printtask "### rebuild jar ###"
1364 for FILE in ${JID[@]}; do
1365 JAR=${FILE##*/}
1366 printtask "... rebuild $JAR ..."
1367 java -Xmx512M -jar smali.jar -a $API tmp/${FILE}.out/smali -o tmp/${FILE}.out/classes.dex >> "$LOG" 2>> "$LOG"
1368 [ -f tmp/${FILE}.out/classes.dex ] || smali_error "failed compiling $JAR !!!"
1369 jar -ufv ${FILE} -C tmp/${FILE}.out/ classes.dex >> "$LOG" 2>> "$LOG"
1370 if [ $FILE == "system/framework/framework.jar" ]; then
1371 jar -ufv ${FILE} -C tmp/${FILE}.out/ preloaded-classes >> "$LOG" 2>> "$LOG"
1373 done
1375 [[ -n ${AID[@]} ]] && printtask "### rebuild apk ###"
1376 for FILE in ${AID[@]}; do
1377 APK=${FILE##*/}
1378 if [ -d tmp/${FILE}.out ]; then
1379 printtask "... rebuild $APK ..."
1380 java -jar apktool.jar b tmp/${FILE}.out >> "$LOG" 2>> "$LOG" || print_error "failed compiling $FILE !!!"
1381 jar -uvf $FILE -C tmp/${FILE}.out/build/apk/ . > /dev/null 2>> "$LOG"
1383 done
1385 [[ -n ${IID[@]} ]] && printtask "### rebuild img ###"
1386 for FILE in ${IID[@]}; do
1387 printtask "### rebuild $FILE ###"
1388 case $FILE in
1389 boot.img)
1390 # Rebuilding boot.img
1391 cd boot
1392 printtask "... rebuilding ramdisk ..."
1393 ./mkbootfs$EXE ./ramdisk | gzip > ramdisk-new.gz
1395 printtask "... composing boot.img ..."
1396 BASE=$(cat boot.img-base)
1397 # hex to decimal in cygwin prefixing "0x" w/ C arithmetic
1398 PGSIZE=$((${PGFORM}$(cat boot.img-pagesize)))
1399 CMDLINE=$(cat boot.img-cmdline)
1400 echo "cmdline = no_console_suspend=1 console=null $CMDLINE" >> "$LOG"
1401 echo "pagesize = $PGSIZE" >> "$LOG"
1402 echo "base = $BASE" >> "$LOG"
1403 printtask "... rebuilding boot.img ..."
1404 ./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"
1405 cd ..
1408 print_error "cannot process $FILE"
1410 esac
1411 done
1413 printtask "### create $UPDATE.zip ###"
1414 jar -cfv tmp.zip ${IID[@]} ${JID[@]} ${AID[@]} ${CID[@]} ${TID[@]} META-INF >> "$LOG" 2>> "$LOG"
1415 java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip $UPDATE.zip 2>> "$LOG"
1417 \mv $RESTORE.zip $UPDATE.zip ..
1418 echo "### finished ###"
1419 echo "flash $UPDATE.zip to install the patched files"
1420 echo "flash $RESTORE.zip to restore the original system"
1422 # add announcement- optional.
1423 for P in ${PID[@]}; do
1424 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1425 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1426 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1427 if [ -f patches/$P/$A/$R/$B/README.txt ]; then
1428 cat patches/$P/$A/$R/$B/README.txt
1429 elif [ -f patches/$P/$A/$R/README.txt ]; then
1430 cat patches/$P/$A/$R/README.txt
1431 elif [ -f patches/$P/$A/README.txt ]; then
1432 cat patches/$P/$A/README.txt
1434 done
1436 cd ..
1437 \rm -rf "$TEMP"