Add the proper provisional files for telephony
[auto-patcher.git] / auto_patcher
blob6edb7d9a92ab07648d31e096ccf564fcacff172e
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
105 # SHELL PROGRAMMING NOTES:
106 # [ -s FILE ]
107 # [[ -n STRING ]] or [[ -z STRING ]]
109 VERSION="v2.5.1"
110 CURRENT_ANDROID="4.2.1"
112 # pass variables to children
113 set -a
115 printusage_help () {
116 PID="openpdroid,3gdongle" # default example
117 brief_help
120 brief_help () {
121 echo " usage: ./auto_patcher <ROM> <MODS> <ROMTYPE>"
122 echo " example: ./auto_patcher CM10.zip $PID cm"
123 echo ""
124 echo "Use ./auto_patcher -h for the help menu"
125 echo ""
126 cleanup
127 exit
130 usage_help () {
131 PID=mods
132 mods_display
133 echo "Multiple MODS can be combined by separating them with a comma and NO SPACES!!!"
134 echo ""
135 echo " usage: ./auto_patcher <ROM> <MODS> <ROMTYPE>"
136 echo ""
137 echo " example: ./auto_patcher CM10.zip openpdroid,3gdongle cm"
138 echo ""
139 usage_more_help
142 usage_more_help () {
143 echo "* press 'q' available patches or CTRL-c to quit the help menu *"
146 display_help () {
147 cd patches
148 echo ""
149 echo "AVAILABLE PATCHES"
150 echo ""
151 echo "*******************************************************************"
152 echo "Note: There are ONLY 4 ROMTYPES: [pa, cm, aokp, and aosp]."
153 echo ""
154 #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
155 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
156 #-path './src/emacs' -prune
157 echo ""
158 echo "!!! Do not put Android Version number on command line !!!!"
159 echo "*****************************************************************"
160 echo "Specific auto_patcher script options"
161 echo " ./auto_patcher -h mods Lists mods"
162 echo " -h <MODNAME> Specific <MOD> info"
163 echo " -h advanced Advanced usage+lists all available patch dates"
164 echo ""
165 cleanup
166 exit
169 romtype_help () {
170 # From rom_error (bad romtype) and date_error (patch date w/o specifying romtype)
171 echo ""
172 echo "!!!There are only four supported ROMTYPES: 1) cm 2) aokp 3) aosp 4) pa"
173 echo ""
174 echo "Find out which of the above ROMTYPES your rom is based on and try again!"
175 echo "**********************************************"
176 echo ""
177 cleanup
178 brief_help
181 advanced_help () {
182 echo ""
183 echo "The Auto-Patcher Advanced Usage"
184 echo "*********************************"
185 echo ""
186 echo "For those of you determined to try everything..."
187 echo ""
188 echo "You can also try adding a patch date as a final argument."
189 echo ""
190 echo " ./auto_patcher <ROM> <MOD> <ROMTYPE> <DATE>"
191 echo ""
192 echo "Please note: There are only four ROMTYPES: {pa, aokp, aosp and cm}"
193 echo " -The various appellations after that are for internal use only!"
194 echo ""
195 echo "The Auto-Patcher has a pretty great rom probe, specifying the date is"
196 echo " deprecated...you don't need to, we promise."
197 echo ""
200 cleanup () {
201 rm -rf $ROOT/tmp*
204 garbage () {
205 unset GARBAGE
206 GARBAGE=($(find $@ -name "*.orig")) && rm -rf ${GARBAGE[@]} && echo "GARBAGE= ${GARBAGE[@]}" >> "$LOG"
207 GARBAGE=($(find $@ -name "*.rej")) && rm -rf ${GARBAGE[@]} && echo "GARBAGE= ${GARBAGE[@]}" >> "$LOG"
211 print_error () {
212 # General purpose error. Used for errors in main, as opposed to probe or set-up.
213 echo ""
214 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
215 printtask "!!! error: $@"
216 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
217 echo ""
218 brief_help
221 smali_error () {
222 # Smali binary error. Problem often goes away on second run.
223 echo ""
224 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
225 printtask "!!! error: $@"
226 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
227 echo ""
228 if [[ `grep 'method index is too large' "$LOG"` != "" ]]; then
229 printtask "!!! Problem with method cap !!!"
230 printtask "... attempting fix ..."
231 . patches/common/framework.jar.sh 2>&1 > ${JAR}.log
232 printtask "... rebuild framework.jar ..."
233 java -Xmx512M -jar smali.jar -a $API tmp/${FILE}.out/smali -o tmp/${FILE}.out/classes.dex >> "$LOG" 2>> "$LOG"
234 [ -f tmp/${FILE}.out/classes.dex ] || print_error "Could not resolve method cap issue- please submit log"
235 else
236 printtask "!!! This error is generally due to an unknown bug in the smali binary!"
237 echo "In our experience, it goes away if you run the patcher a second time."
238 echo " Please run the Auto-Patcher with the same command once again."
239 echo ""
240 echo "If after the third attempt the same thing happens,"
241 echo " please upload your logfile to our support thread!"
242 echo ""
243 cleanup
244 exit
248 mismatch_error () {
249 # Function that exposes attempts to apply a mod to an upsupported Android version
250 echo ""
251 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
252 printtask "!!! error: $@"
253 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
254 echo ""
255 cleanup
256 brief_help
259 date_error () {
260 # Remind users to include a romtype if they are going to specify a patch date
261 echo ""
262 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
263 printtask "!!! error: $@"
264 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
265 echo ""
266 echo "Please put a ROMTYPE before the patch date and run again!!"
267 romtype_help
270 rom_error () {
271 # For when an unsupported romtype is manually entered on the command-line
272 echo ""
273 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
274 printtask "!!! error: $@"
275 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
276 romtype_help
279 conflict_error () {
280 # For conflicting packages
281 echo ""
282 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
283 printtask "!!! error: $@"
284 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
285 cleanup
286 PID=mods
287 mods_info
290 misspatch_error () {
291 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
292 printtask "!! error: $@ "
293 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
294 echo ""
295 printtask "!! The Auto-Patcher could not find its patches and/or tools!"
296 echo ""
297 echo "* Did you run ./batch.sh first?"
298 echo ""
299 echo "The patch_patches.tgz and patch_tools.tgz need to be in this directory,"
300 echo " one way or another..."
301 echo ""
302 cleanup
303 brief_help
306 misstools_error () {
307 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
308 printtask "!! error: $@ "
309 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
310 printtask "Your set-up is missing a dependency."
311 echo "We require JDK, tar, patch and cpio."
312 echo ""
313 echo ""
314 echo "Each distro is different"
315 echo "but ensure you have them all installed and try again."
316 echo ""
317 cleanup
318 brief_help
321 printtask () {
322 echo "" >> "$LOG"
323 echo $@ | tee -a "$LOG"
326 copyfailed () {
327 echo ""
328 printtask "File for which patching failed:"
329 printtask "---------------------------------------------"
330 echo ""
331 printtask "${FAIL##*/}"
332 echo ""
333 echo "---------------------------------------------"
334 echo ""
335 echo "We can try to add a premade copy of those files."
336 echo "This sometimes works."
337 echo ""
338 echo "But IT MAY NOT WORK!!!"
339 echo ""
340 echo ""
341 askconsent && return 0 || return 1
344 askconsent () {
345 sleep 1
346 echo -n "Do you want to proceed ? (YES/no) "
347 read PROCEED
348 echo "askconsent final = ${PROCEED}: for $FAIL" >> "$LOG"
349 case $PROCEED in
350 [Yy] | [Yy][Ee][Ss])
351 return 0; # successful:
352 echo "*** You (or ApG) have elected to use a prepatched copy of $FAIL ***" >> "$LOG"
355 return 1; # error
356 echo "*** You have declined to insert $FAIL by not answering 'yes' at the prompt. ***" >> "$LOG"
358 esac
361 replace_updater () {
363 # Function for devices that use SDcard installs. Also to be tested for CM7
364 # since CM7 seems to use an updater-script that wipes EMMC. Testing
366 \rm $UPDATER_LOC/$UPDS
367 \cp patches/common/$UPDATER_LOC/$UPDS $UPDATER_LOC
368 echo "run_program(\"/sbin/busybox\", \"umount\", \"/system\");" >> UPDATE.txt
369 cat UPDATE.txt >> $UPDATER_LOC/$UPDS
370 echo ""
371 echo "New updater-script being used:" >> "$LOG"
372 echo "-----------------------------" >> "$LOG"
373 cat $UPDATER_LOC/$UPDS >> "$LOG"
376 abspath () {
377 case `uname -s` in
378 CYGWIN*)
379 echo $(cygpath -ua "$1") | sed 's:/$::g' | sed 's: :\\ :g'
381 Darwin)
382 #[[ $(echo $1 | awk '/^\//') == $1 ]] && echo "$1" || echo "$PWD/$1"
383 [[ ${1:0:1} == "/" ]] && echo "$1" || echo "$PWD/$1"
385 Linux)
386 echo $(readlink -f "$1")
389 if [[ ${1:0:1} == "/" ]]; then
390 echo "$1"
391 elif [[ ${1:0:2} == "./" ]]; then
392 echo "$PWD/${1:2}"
393 else
394 echo "$PWD/$1"
397 esac
400 mods_display () {
401 echo ""
402 echo "The Auto-Patcher $VERSION"
403 echo "*******************************"
404 echo ""
405 echo "The available mods are"
406 echo "****************************************************"
407 echo "* pdroid openpdroid voice v6supercharger *"
408 echo "* voice insecure secure external_internal *"
409 echo "* tabletUI 3gdongle pd2.0 *"
410 echo "****************************************************"
411 echo ""
412 echo "To find out more about any mod, simply enter:"
413 echo " ./auto_patcher -h <MODNAME>"
414 echo ""
415 cleanup
418 mods_info () {
419 DEPENDENCY="None" # default
420 DEV="Unknown" # default
421 CEILING=$CURRENT_ANDROID # Default is that everything works...we'll see.
422 case $PID in
423 mods)
424 mods_display
425 exit
427 auto*)
428 echo ""
429 echo "**************************************"
430 echo "The Auto-Patcher ate a kitten once..."
431 echo "**************************************"
432 printusage_help
434 advanced)
435 cd patches/
436 (advanced_help && find -H * -name 2012*) | more -d
437 echo ""
438 brief_help
440 voice)
441 FLOOR=4.0.0
442 DESC="Use on wifi-only tablets to have the software register as 'voice-enabled'. Allows VOIP like Google Voice to function."
443 DESC="bongostl's setup method here: http://forum.xda-developers.com/showthread.php?t=1823701"
444 DEV="bongostl"
447 v6supercharger)
448 FLOOR=4.0.0
449 CEILING=4.2.1
450 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."
451 DEV="Zeppelinrox"
452 DEPENDENCY="The V6 Supercharger Script. Get it at http://forum.xda-developers.com/showthread.php?t=991276/"
454 pdroid)
455 FLOOR=2.3.7
456 CEILING=4.1.2
457 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)."
458 DEV="Svyat"
459 DEPENDENCY="The Pdroid app. You can get it at http://forum.xda-developers.com/showthread.php?t=1923576"
461 pd2.0)
462 FLOOR=4.1.2
463 CEILING=4.1.2
464 DESC="An expansion of the PDroid application/framework."
465 DEV="CollegeDev"
466 DEPENDENCY="The free PDroid2.0 app available at http://forum.xda-developers.com/showthread.php?t=1923576"
468 openpdroid)
469 FLOOR=4.1.2
470 CEILING=4.2.1
471 DESC="A fork of the open-source PDroid and Pdroid2.0 framework."
472 DEV="FFU5y/wbedard/mateorod/Community"
473 DEPENDENCY="The PDroidManager app freely available from Google Play or http://forum.xda-developers.com/showthread.php?t=1994860"
475 opendroid)
476 echo ""
477 echo "No mod named 'opendroid'. You probably mean 'openpdroid'. Try again."
478 PID="mods"
479 mods_info
481 external_internal)
482 FLOOR=2.3.3
483 DESC="Swap internal and external storage."
485 insecure)
486 FLOOR=2.3.3
487 DESC="Make any boot.img insecure and allow remount as well as adb push/pull of system files. True root."
489 secure)
490 FLOOR=2.3.3
491 DESC="Make any boot.img secure."
493 3gdongle)
494 FLOOR=4.1.0
495 CEILING=4.2.1
496 DESC="Allows 3gdongles to work on wifi tablets w/o 3rd party applications."
497 DEV="trevd"
498 DEPENDENCY="None, but read the troubleshooting guide at http://forum.xda-developers.com/showthread.php?t=1798631"
500 tabletUI)
501 FLOOR=4.1.0
502 CEILING=4.1.2
503 DESC="Changes the user interface of Phones and Phablets to the popular Tablet UI."
504 DEV="barmullio"
507 FLOOR=?????
508 CEILING=?????
509 DESC="??? Unknown modtype ??? Check your spelling or the mod list!"
510 #DESC1="./auto_patcher -h mods"
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
569 echo $AOSP
572 ever_check() {
573 MID=$(getbuildprop ro.build.romversion)
574 if [[ "$MID" == "Evervolv"* ]]; then
575 AOSP=aosp-ever
576 else
577 MID=$(getbuildprop ro.build.display.id)
578 if [[ "$MID" == "ev"* ]]; then
579 AOSP=aosp-ever
580 else
581 AOSP=aosp
584 echo $AOSP
587 pa_check() {
588 CMID=$(getbuildprop ro.modversion)
589 PAID=$(getbuildprop ro.pa.version)
590 MID=$(getbuildprop ro.build.display.id)
591 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
592 DID=$(getbuildprop ro.product.device)
593 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
594 if [[ -n $PAID ]]; then
595 RID=pa
596 else
597 case $CMID in
598 [Pp][Aa]*)
599 RID=pa;
602 RID=cm;
604 esac
608 proberom () {
609 VID=$(getbuildprop ro.build.version.release)
610 if [ ${#VID} -lt 4 ]; then # in case of non-standard versioning in build.prop (defy!)
611 ANDR=$VID
612 else
613 ANDR="${VID%.*}" # Cut to 1 significant digit to cover specific range or release.
615 if [ "$ANDR" == "2.3" ]; then
616 FLAVR=gingerbread
617 API=10
618 RID=cm;
619 elif [ "$ANDR" == "4.0" ]; then
620 FLAVR=ics
621 API=15
622 MID=$(getbuildprop ro.rommanager.developerid)
623 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.modversion))
624 DID=$(getbuildprop ro.product.device)
625 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
627 case "$MID" in
628 pa|cm9|cm|cyanogenmod*)
629 RID=cm;
631 aokp|teamkang)
632 RID=aokp;
634 aosp*)
635 RID=aosp;
638 echo "!!! $MID is not supported yet, trying generic latest !!!"
640 esac
641 elif [ "$ANDR" == "4.1" ]; then
642 FLAVR=jellybean
643 API=16
644 CMID=$(getbuildprop ro.cm.version)
645 if [[ -n $CMID ]]; then
646 pa_check
647 else
648 MID=$(getbuildprop ro.build.display.id)
649 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
650 DID=$(getbuildprop ro.product.device)
651 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
652 case "$MID" in
653 cm10|cm*|cyanogenmod*)
654 RID=cm;
656 aokp*|teamkang)
657 RID=aokp;
659 pa*)
660 RID=pa;
662 ev*)
663 RID=aosp-ever;
666 RID=`aosp_mod_check`;
668 esac
670 elif [ "$ANDR" == "4.2" ]; then
671 FLAVR=jellybean
672 API=17
673 CMID=$(getbuildprop ro.cm.version)
674 MID=$(getbuildprop ro.build.display.id)
675 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
676 DID=$(getbuildprop ro.product.device)
677 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
679 case "$MID" in
680 cm10|cm*|cyanogenmod*)
681 RID=cm;
683 aokp*|teamkang)
684 RID=aokp;
686 pa*)
687 RID=pa;
689 ev*|Ever*)
690 RID=aosp-ever;
693 RID=`ever_check`;
695 esac
696 else
697 print_error "unknown ROM version $VID"
699 echo "... result of ROM check: version= $VID rom= $RID ..."
703 # Advanced build date query
704 # This should set the patch date automatically.
706 build_query() {
707 UTC=$(getbuildprop ro.build.date.utc)
709 # Difference in how OS X and Linux/Cygwin handles 'date' utility
710 case `uname -s` in
711 [Dd]arwin)
712 BDID=`date -r $UTC +%Y%m%d`
713 echo "#### Darwin Build Query used ####" >> "$LOG"
716 BDID=`date -d "1970-01-01 UTC $UTC seconds" +"%Y%m%d"`
717 echo "#### Standard Build Query ####" >> "$LOG"
719 esac
721 # If patch date is specified on CLI, use that patch date
722 if [ $# -gt 3 ]; then
723 BID=${4//,/ };
724 BDID=$BID
725 else
726 case $ANDR in
727 gingerbread)
728 # CM7 roms do not have UTC time stamp- so no build query.
729 BID=latest;
730 echo "*** CM7 roms default to latest patches. If using an older rom ***"
731 echo "*** specify patch date on command line. Use -h to see available patches ***"
734 for P in ${PID[@]}; do
735 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
736 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
737 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
738 PAR=patches/$P/$A/$R
739 PARB=patches/$P/$A/$R/$B
740 DATES=`ls patches/$P/$A/$R/ | grep '201*'`
741 # Intialize variable - High so as to determine lowest in first loop.
742 BID=20201231
743 # find earliest available patch date
744 for i in $DATES; do
745 if [[ $i -lt $BID ]]; then
746 BID=$i
748 done
749 # Check if earliest patches are from before build date. Else use earliest
751 # If older than earliest patch set, then find best match
752 if [[ $(($BID-$BDID)) -lt 0 ]]; then
753 for g in $DATES; do
754 # use any patch that matches $UTC
755 if [[ $(($BDID-$g)) -eq 0 ]]; then
756 BID=$g
757 break
758 # Set highest $BID w/o going over $UTC
759 elif [[ $(($BDID-$g)) -gt 0 ]] && [[ $g -gt $BID ]]; then
760 BID=$g
762 done
764 echo "... $PID patch date has been set to: $BID ..."
765 B=$BID
766 break
767 done
769 esac
773 proberil () {
774 RIL=$(getbuildprop ro.telephony.ril_class)
775 [[ -n $RIL ]] && printtask "... result of ROM check: RIL= $RIL"
778 rominfo () {
779 echo "# VER= $VERSION" >> "$LOG"
780 echo "# OS= $OSTYPE ${BIT}bit" >> "$LOG"
781 echo "# VID= $VID" >> "$LOG"
782 echo "# PID= ${PID[@]}" >> "$LOG"
783 echo "# MID= $MID" >> "$LOG"
784 echo "# RID= $RID" >> "$LOG"
785 echo "# ANDR= $ANDR" >> "$LOG"
786 echo "# BDID= $BDID" >> "$LOG"
787 echo "# DID= $DID" >> "$LOG"
788 echo "# BID= $BID" >> "$LOG"
792 if [[ $1 == -h ]]; then
793 if [ $# -gt 1 ]; then
794 PID=$2
795 mods_info
796 echo ""
797 echo "The Auto-Patcher $VERSION by Mateorod and Pastime1971"
798 echo "*************************************************"
799 echo ""
800 echo "Mod Name: $PID"
801 echo ""
802 echo " $DESC"
803 if [[ -z $DESC1 ]]; then # test to see is there is a second DESC line
804 echo "$DESC1"
806 if [[ $((DESC2)) -gt 0 ]]; then
807 echo "$DESC2"
809 echo ""
810 echo "Developer: $DEV"
811 echo "Dependancies: $DEPENDENCY"
812 echo ""
813 echo "Works on ROMs from Android $FLOOR -> $CEILING"
814 echo
815 brief_help
816 exit
820 [[ $# -lt 1 || -z $1 ]] && PID="mods" && mods_info
821 [[ $1 == "-h" ]] && usage_help | less && display_help
823 echo ""
824 echo "The Auto-Patcher $VERSION"
825 echo ""
826 # by pastime1971 and mateorod
828 ROOT=$(abspath `dirname "$0"`)
829 TOOL="$ROOT/patch_tools.tgz"
830 PTCH="$ROOT/patch_patches.tgz"
831 cleanup
832 # set temporaray directory
833 DATE=`date +%Y%m%d%H%M%S`
834 TEMP=$ROOT/tmp$DATE
835 TMP=$ROOT/tmp$DATE
836 TMPDIR=$ROOT/tmp$DATE
837 mkdir "$TEMP"
838 ROM=$(abspath "$1")
839 ROMX=$(extpath "$1")
841 if [[ $OSTYPE == "cygwin" ]]; then
842 EXE=".exe"
843 PGFORM="0x"
846 LOG=$(abspath ./log$DATE.txt)
847 #echo $ROOT $TOOL $ROM $TEMP "$LOG"
848 echo "ROOT= $ROOT" >> "$LOG"
849 echo "TOOL= $TOOL" >> "$LOG"
850 echo "ROM= $ROM" >> "$LOG"
851 echo "ROMX= $ROMX" >> "$LOG"
853 \rm -f $RESTORE.zip $UPDATE.zip
855 CHK=$(getconf LONG_BIT)
856 if [[ $CHK = "64" ]]; then
857 BIT=64
858 else [[ $BIT = "32" ]];
859 BIT=32
863 printtask "### verify tools ###"
864 which patch >> "$LOG" || misstools_error "Missing \"patch\" utility."
865 which tar >> "$LOG" || misstools_error "Missing \"tar\" utility"
866 which jar >> "$LOG" || misstools_error "Missing \"Java Development Kit\" (JDK)"
867 which java >> "$LOG" || misstools_error "Missing \"Java Development Kit\" (JDK)"
868 which cpio >> "$LOG" || misstools_error "Missing \"cpio\" utility"
869 [ -f "$TOOL" ] || misspatch_error "patch_tool.tgz is missing"
870 [ -f "$PTCH" ] || misspatch_error "patch_patches.tgz is missing"
871 printtask "### verify ROM ###"
872 [ -f "$ROM" ] || print_error "Cannot find $1!! Make sure you have the location and name right"
873 echo "### running $0 $@" >> "$LOG"
874 cd "$TEMP"
876 PATH="$TEMP:$PATH"
877 export PATH
878 echo "PATH= $PATH" >> "$LOG"
880 printtask "### unzip patch tools ###"
881 tar xzf "$TOOL" > /dev/null || print_error "failed extracting tools !!!"
883 # Get OS specific tools
884 case `uname -s` in
885 CYGWIN*)
886 \mv cygwin/aapt.exe .
887 \mv cygwin/*.exe boot/
888 \rm -rf cygwin # why? If you want to we can keep/add it to mac/linux, though.
890 [Dd]arwin)
891 \mv mac/aapt .
893 [Ll]inux)
894 \mv linux/aapt .
897 \mv linux/aapt .
899 esac
900 # Ensure aapt permissions - possibly to one day be expanded to all tools in a function.
901 chmod a+x aapt$EXE
903 printtask "### unzip patch patches ###"
904 tar xzf "$PTCH" > /dev/null || print_error "failed extracting patches !!!"
906 # we need build.prop for both RIL probing and ROM probing
907 jar -xvf "$ROMX" system/build.prop 2>> "$LOG" || print_error "failed extracting build.prop from $ROMX !!!"
909 # rom + ril type
910 proberil
911 printtask "### probe rom type ###"
912 proberom
914 # rom type
915 if [ $# -gt 1 ]; then
916 PIT=$2
917 if [[ "$PIT" = "-h" ]]; then
918 display_help
921 if [ $# -gt 2 ]; then
922 RID=$3
923 case "$RID" in
924 cm10|cm*|cyanogenmod*)
926 aokp*|teamkang)
927 RID=aokp;
929 pa*)
930 RID=pa;
932 aosp-ever)
933 RID=aosp-ever;
935 aosp*)
936 case "ANDR" in
937 4.1)
938 RID=`aosp_mod_check`;
941 RID=`ever_check`
943 esac
945 201*)
946 date_error "You must specify ROMTYPE if designating a patch date!!"
949 rom_error "$RID is not a valid ROMTYPE!!"
951 esac
952 echo "... Using $RID patches ..."
953 else
954 echo "... Using results of ROM check ..."
957 # patch type
958 if [ $# -gt 1 ]; then
959 PIL=${2//,/ } # If more than one mod, make string separated by spaces
960 else
961 PIL="openpdroid"
962 echo "No mods selected. Defaulting to openpdroid, since that's what you probably want..."
965 PID=(${PIL// / }) # turn string into array
966 COPYPID=("${PID[@]}") # working copy to iterate over
967 MODS_NUMBER=${#COPYPID[@]} # number of elements (mods)
969 if [[ $MODS_NUMBER > 1 ]]; then
970 INDEX=0
971 for p in ${COPYPID[@]}; do
972 if [ "$p" = "pdroid" ] || [ "$p" = "pd2.0" ] ||[ "$p" = "openpdroid" ]; then
973 SPID[0]=$p
974 unset COPYPID["$INDEX"]
975 break
976 else
977 INDEX=$((INDEX + 1))
979 done
980 for p in ${COPYPID[@]}; do
981 if [ "$p" = "pdroid" ] || [ $p = "pd2.0" ] ||[ $p = "openpdroid" ]; then
982 conflict_error "Those mods conflict! Only one pdroid mod at a time!"
983 else
984 i=${#SPID[@]}
985 SPID[i]=$p
986 i+=1
988 done
989 else
990 SPID=${COPYPID[@]}
992 for P in ${PIL[@]}; do
993 [[ ${PID[@]} =~ $P ]] || PID=(${PID[@]} $P)
994 done
996 # Check to make sure selected roms are available for the Android version of patched ROM
997 compat_check
999 # Build date
1000 if [ $# -gt 3 ]; then # if a date is specified on command line...
1002 # Set date to match argument and ensure that patches with that date exist
1003 BID=$4
1004 [ -d patches/$P/$A/$R/$BID ] || print_error "No $P patches for $RID on $BID!! Try the help menu!!"
1006 # Run build_query- this overrides the above but gets useful info
1007 build_query
1008 # Reset patch date to argument
1009 BID=$4
1010 echo "... $PID patch date set manually to: $BID ..."
1011 else
1012 build_query # if no date specified, use one from build_query
1015 # echo ROM info
1016 rominfo
1018 if [[ ( "$PID" == "-h" || "$RID" == "-h" || "$BID" == "-h" ) ]]; then
1019 #Although this placement may be perfect for romfilter. although it throws the scheme...
1020 display_help
1022 #Begin cycle
1024 for P in ${PID[@]}; do
1025 [ -d patches/$P ] || print_error "$P is not available"
1026 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1027 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1028 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1030 unset FILES
1031 [ -f patches/$P/files.txt ] && FILES=$(cat patches/$P/files.txt)
1032 [ -f patches/$P/$A/files.txt ] && FILES=$(cat patches/$P/$A/files.txt)
1033 [ -f patches/$P/$A/$R/files.txt ] && FILES=$(cat patches/$P/$A/$R/files.txt)
1034 [ -f patches/$P/$A/$R/$B/files.txt ] && FILES=$(cat patches/$P/$A/$R/$B/files.txt)
1035 for FILE in ${FILES[@]}; do
1036 case "$FILE" in
1037 +system/*)
1038 [[ ${CID[@]} =~ ${FILE:1} ]] && print_error "${FILE:1} is already being copied" || CID=(${CID[@]} ${FILE:1})
1040 -system/*)
1041 [[ ${EID[@]} =~ ${FILE:1} ]] || EID=(${EID[@]} ${FILE:1})
1043 system/*.jar)
1044 [[ ${JID[@]} =~ $FILE ]] || JID=(${JID[@]} $FILE)
1045 echo "set_perm(0, 0, 0644, \"/$FILE\");" >> UPDATE.txt
1047 system/*.apk)
1048 [[ ${AID[@]} =~ $FILE ]] || AID=(${AID[@]} $FILE)
1049 echo "set_perm(0, 0, 0644, \"/$FILE\");" >> UPDATE.txt
1051 *.img)
1052 [[ ${IID[@]} =~ $FILE ]] || IID=(${IID[@]} $FILE)
1054 system/*)
1055 [[ ${TID[@]} =~ $FILE ]] || TID=(${TID[@]} $FILE)
1057 esac
1058 done
1059 done
1060 echo "### DELETE FILES= ${EID[@]}" >> "$LOG"
1061 echo "### COPY FILES= ${CID[@]}" >> "$LOG"
1062 echo "### JAR FILES= ${JID[@]}" >> "$LOG"
1063 echo "### APK FILES= ${AID[@]}" >> "$LOG"
1064 echo "### IMG FILES= ${IID[@]}" >> "$LOG"
1065 echo "### TXT FILES= ${TID[@]}" >> "$LOG"
1067 # extract system files
1068 printtask "### unzip rom ###"
1069 jar -xvf "$ROMX" ${JID[@]} ${AID[@]} ${IID[@]} ${TID[@]} 2>> "$LOG" || print_error "failed extracting ${JID[@]} ${AID[@]} ${IID[@]} from $ROMX !!!"
1072 # Update/Restore.zip scripts and prep
1073 printtask "### create updater script ###"
1074 UPDATER_LOC=META-INF/com/google/android
1075 UPDS=updater-script
1076 UPDATE="update-$RID-$DID-$BDID-${PIL// /-}"
1077 RESTORE="restore-$RID-$DID-$BDID"
1079 jar -xvf "$ROMX" $UPDATER_LOC/$UPDS $UPDATER_LOC/update-binary
1080 jar -xvf "$ROMX" $UPDATER_LOC/update-binary-installer 1> /dev/null 2> /dev/null
1082 # Determine Installer- Aroma or ClockworkMod
1083 if [ -f $UPDATER_LOC/update-binary-installer ]; then
1084 printtask "... using Aroma installer ..."
1085 \mv $UPDATER_LOC/update-binary-installer $UPDATER_LOC/update-binary
1086 else
1087 printtask "... using Clockworkmod installer ..."
1090 # Create updater scripts
1091 cat patches/common/updater-message.txt >> $UPDS
1092 cat $UPDATER_LOC/$UPDS | grep ^mount | grep "/system" | head -n 1 >> $UPDS
1093 [ -s $UPDS ] || echo "run_program(\"/sbin/busybox\", \"mount\", \"/system\");" >> $UPDS
1094 # restore the original
1095 for FILE in ${EID[@]}; do
1096 jar -xvf "$ROMX" $FILE 2> /dev/null || printtask "!!! warning $FILE cannot be restored !!!"
1097 done
1098 # replace with the original or delete it
1099 for FILE in ${CID[@]}; do
1100 jar -xvf "$ROMX" $FILE 2> /dev/null || echo "delete(\"/$FILE\");" >> $UPDS
1101 done
1102 echo "package_extract_dir(\"system\", \"/system\");" >> $UPDS
1103 # permission management for files that need specific perms
1104 cat $UPDATER_LOC/$UPDS | grep set_perm | grep "/system" >> $UPDS
1105 for P in ${PID[@]}; do
1106 if [ -s patches/$P/$A/set_perm.txt ]; then
1107 echo "...setting permissions..."
1108 cat patches/$P/$A/set_perm.txt >> $UPDS
1110 done
1111 cat $UPDATER_LOC/$UPDS | grep ^unmount | grep "/system" | head -n 1 >> $UPDS
1112 [[ ${IID[@]} =~ boot.img ]] && cat $UPDATER_LOC/$UPDS | grep "boot.img" >> $UPDS
1113 echo "ui_print(\" .\");" >> $UPDS
1114 echo "ui_print(\" .\");" >> $UPDS
1115 echo "ui_print(\" done!\");" >> $UPDS
1116 cat $UPDS > $UPDATER_LOC/$UPDS
1117 echo "# generated $UPDS" >> "$LOG"
1118 cat $UPDS >> "$LOG"
1120 printtask "### create restore.zip ###"
1121 jar -cvf tmp.zip ${JID[@]} ${AID[@]} ${IID[@]} META-INF > /dev/null 2>> "$LOG"
1122 java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip signed.zip 2>> "$LOG"
1123 \mv signed.zip $RESTORE.zip
1124 \rm -f tmp.zip
1127 # Begin patching process
1129 # decompile system files
1130 printtask "### decompile system files ###"
1131 for FILE in ${JID[@]}; do
1132 JAR=${FILE##*/}
1133 printtask "... decompile $JAR ..."
1134 java -jar baksmali.jar -b -a $API -o tmp/${FILE}.out/smali ${FILE} >> "$LOG" 2>> "$LOG"
1135 if [ $FILE == "system/framework/framework.jar" ]; then
1136 printtask "... extract preloaded-classes ..."
1137 jar -xvf ${FILE} preloaded-classes >> "$LOG" 2>> "$LOG"
1138 \mv preloaded-classes tmp/${FILE}.out/
1140 done
1142 # install framework-files for APK...
1143 if [ ${#AID[@]} -gt 0 ]; then
1144 jar -xvf "$ROMX" system/framework/framework-res.apk >> "$LOG"
1145 printtask "... installing framework files ..."
1146 java -jar apktool.jar if system/framework/framework-res.apk
1147 # Decompile APKs
1148 for FILE in ${AID[@]}; do
1149 APK=${FILE##*/}
1150 if [ -f $FILE ]; then
1151 printtask "... decompile $APK ..."
1152 java -jar apktool.jar d -f $FILE tmp/$FILE.out
1154 done
1157 # Unpack image files {boot.img only so far...}
1158 for FILE in ${IID[@]}; do
1159 printtask "### unpacking $FILE ###"
1160 case "$FILE" in
1161 boot.img)
1162 if [ -f boot.img ]; then
1163 cd boot
1164 ./unpackbootimg$EXE -i ../boot.img >> "$LOG" 2>> "$LOG"
1165 mkdir ramdisk
1166 cd ramdisk
1167 gzip -dc ../boot.img-ramdisk.gz | cpio -i >> "$LOG" 2>> "$LOG"
1168 cd ../../
1169 else
1170 print_error "A mod needs to patch boot.img! This rom does not contains boot.img."
1174 print_error "cannot process $FILE"
1176 esac
1177 done
1179 # apply system modification
1181 for P in ${PID[@]}; do
1182 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1183 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1184 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1185 PAR=patches/$P/$A/$R
1186 PARB=patches/$P/$A/$R/$B
1188 unset FILES COPY DELS JARS APKS IMGS TXTS
1189 [ -f patches/$P/files.txt ] && FILES=$(cat patches/$P/files.txt)
1190 [ -f patches/$P/$A/files.txt ] && FILES=$(cat patches/$P/$A/files.txt)
1191 [ -f patches/$P/$A/$R/files.txt ] && FILES=$(cat patches/$P/$A/$R/files.txt)
1192 [ -f patches/$P/$A/$R/$B/files.txt ] && FILES=$(cat patches/$P/$A/$R/$B/files.txt)
1193 for FILE in ${FILES[@]}; do
1194 case $FILE in
1195 +system/*)
1196 COPY=(${COPY[@]} ${FILE:1})
1198 -system/*)
1199 DELS=(${DELS[@]} ${FILE:1})
1201 system/*.jar)
1202 JARS=(${JARS[@]} $FILE)
1204 system/*.apk)
1205 APKS=(${APKS[@]} $FILE)
1207 *.img)
1208 IMGS=(${IMGS[@]} $FILE)
1210 system/*)
1211 TXTS=(${TXTS[@]} $FILE)
1213 esac
1214 done
1216 [[ -n ${COPY[@]} ]] && printtask "### copy patch $P/$A/$R/$B ###"
1217 for FILE in ${COPY[@]}; do
1218 printtask "... copying $FILE ..."
1219 DEST=${FILE%/*}
1220 mkdir -p ./$DEST
1221 if [ -e patches/$P/$A/$R/$B/$FILE ]; then
1222 [ -e $FILE ] && printtask "... overwriting $FILE from $P ..."
1223 \cp -av patches/$P/$A/$R/$B/$FILE ./$DEST >> "$LOG"
1224 else
1225 print_error "$FILE is missing in the patch. Please upload your logfile to the support thread!"
1227 done
1229 # unconditional smali copying- For particularly troublesome files
1230 [ -f patches/$P/smali.txt ] && SMALI=$(cat patches/$P/smali.txt)
1231 [ -f patches/$P/$A/smali.txt ] && SMALI=$(cat patches/$P/$A/smali.txt)
1232 [ -f patches/$P/$A/$R/smali.txt ] && SMALI=$(cat patches/$P/$A/$R/smali.txt)
1233 [ -f patches/$P/$A/$R/$B/smali.txt ] && SMALI=$(cat patches/$P/$A/$R/$B/smali.txt)
1234 MOVE=${SMALI##*/}
1235 for SMALI in ${SMALI[@]}; do
1236 if [ -f patches/$P/$A/$R/provisionals/$SMALI ]; then
1237 printtask "... overwriting $MOVE ..."
1238 \cp -a patches/$P/$ANDR/$R/provisionals/$SMALI tmp/$SMALI >> "$LOG"
1239 elif [ -f patches/$P/$A/provisionals/$SMALI ]; then
1240 printtask "... overwriting $MOVE ..."
1241 \cp -a patches/$P/$ANDR/provisionals/$SMALI tmp/$SMALI >> "$LOG"
1243 done
1245 [[ -n ${DELS[@]} ]] && printtask "### delete patch $P/$A/$R/$B ###"
1246 for FILE in ${DELS[@]}; do
1247 printtask "... deleting $FILE ..."
1248 \rm -rf ./$FILE
1249 done
1250 [[ -n ${JARS[@]} ]] && printtask "### jar patch $P/$A/$R/$B ###"
1251 for FILE in ${JARS[@]}; do
1252 JAR=${FILE##*/}
1253 NAME=${JAR%.jar}
1254 printtask "... apply $NAME.patch ..."
1255 patch -Nls -p1 -d tmp/${FILE}.out < $PARB/${NAME}.patch 2>&1 > ${JAR}.log
1256 cat ${JAR}.log | tee -a "$LOG"
1257 case "$NAME" in
1258 framework)
1259 # patch preloaded-classes only if a patch exists
1260 if [ -f $PARB/preloaded.patch ]; then
1261 printtask "... apply preloaded.patch ..."
1262 patch -Nls -p1 -d tmp/${FILE}.out < $PARB/preloaded.patch 2>&1 > preloaded.log
1263 cat preloaded.log | tee -a "$LOG"
1264 [[ `grep FAILED preloaded.log` != "" ]] && print_error "failed preloaded.patch"
1268 echo -n "" # do nothing else
1270 esac
1271 # substitute failed smali with provisional (a prepatched smali file)
1272 unset FAILS
1273 FAILS=(`grep FAILED ${JAR}.log | sed -e 's/.*smali\///' | sed -e 's/\.rej//'`)
1274 if [[ -n ${FAILS[@]} ]]; then
1275 printtask "!!! PATCHING FAILED FOR ${FAILS[@]} !!!"
1276 echo "### replace ${FAILS[@]} ###" > ${JAR}.log
1277 for FAIL in ${FAILS[@]}; do
1278 PROVISIONAL="patches/$P/$ANDR/provisionals/${FILE}.out/smali/${FAIL}"
1279 echo "!!! patch error for $FAIL !!!" >> "$LOG"
1280 #cat tmp/$FILE.out/smali/${FAIL}.rej >> "$LOG" # FOR DEBUGGING
1281 [[ ${SID[@]} =~ $FAIL ]] && print_error "$FAIL was already replaced before"
1282 [ -f "$PROVISIONAL" ] || print_error "failed $FAIL in $JAR cannot be remedied"
1283 copyfailed
1284 printtask "... replace $FAIL ..."
1285 \rm -rf tmp/${FILE}.out/smali/${FAIL} tmp/${FILE}.out/smali/${FAIL}.orig tmp/${FILE}.out/smali/${FAIL}.rej
1286 \cp -av "$PROVISIONAL" tmp/${FILE}.out/smali/${FAIL} >> "$LOG"
1287 SID=(${SID[@]} $FAIL)
1288 done
1290 [[ `grep FAILED ${JAR}.log` != "" ]] && print_error "failed $NAME.patch"
1291 garbage tmp/${FILE}.out
1293 # run special $JAR.sh scripts if any JAR needs special attention
1294 if [ -f patches/$P/$A/$R/$B/${JAR}.sh ]; then
1295 printtask "... apply $JAR.sh ..."
1296 . patches/$P/$A/$R/$B/${JAR}.sh 2>&1 > ${JAR}.log
1297 cat ${JAR}.log | tee -a "$LOG"
1299 done
1301 [[ -n ${APKS[@]} ]] && printtask "### apk patch $P/$A/$R/$B ###"
1302 for FILE in ${APKS[@]}; do
1303 APK=${FILE##*/}
1304 if [ -d "tmp/${FILE}.out" ] ; then
1305 printtask "... apply $APK.patch ..."
1306 patch -Nls -p2 -d tmp/${FILE}.out < $PARB/${APK}.patch 2>&1 >> ${APK}.log
1307 cat ${APK}.log | tee -a "$LOG"
1308 [[ `grep FAILED ${APK}.log` != "" ]] && apk_check
1309 garbage tmp/${FILE}.out
1310 else
1311 echo "No $APK in your ROM. Not able to patch this file."
1312 echo "## No $APK in ROM ###" >> "$LOG"
1314 done
1315 [[ -n ${IMGS[@]} ]] && printtask "### img patch $P/$A/$R/$B ###"
1316 for FILE in ${IMGS[@]}; do
1317 IMG=${FILE##*/}
1318 printtask "... applying $IMG.patch ..."
1319 patch -Nls -p1 -d boot/ramdisk < $PARB/${IMG}.patch >> "$LOG" || print_error "failed patching $FILE"
1320 done
1322 # Text Editing Functions --this can really do just about anything. Needs a working restore!
1323 [[ -n ${TXTS[@]} ]] && printtask "### text patch $P/$A/$R/$B ###"
1324 for FILE in ${TXTS[@]}; do
1325 TXT=${FILE##*/}
1326 if [[ -f $PARB/${TXT}.patch ]]; then
1327 printtask "... apply $TXT.patch ..."
1328 patch -Nls -p2 -d system/ < $PARB/${TXT}.patch 2>&1 > ${TXT}.log
1329 #cat ${TXT}.log | tee -a "$LOG"
1330 [[ `grep FAILED ${TXT}.log` != "" ]] && print_error "failed $TXT.patch"
1332 if [[ -f $PAR/${TXT}.awk ]]; then
1333 printtask "... apply $TXT.awk ..."
1334 awk -f $PAR/${TXT}.awk $FILE > text || print_error "failed $TXT.awk"
1335 mv text $FILE
1337 if [[ -f $PAR/${TXT}.sed ]]; then
1338 printtask "... apply $TXT.sed ..."
1339 sed -f $PAR/${TXT}.sed $FILE > text || print_error "failed $TXT.sed"
1340 mv text $FILE
1342 if [[ -f $PAR/${TXT}.sh ]]; then
1343 printtask "... apply $TXT.sh ..."
1344 . $PAR/${TXT}.sh 2>&1 >> ${TXT}.log || print_error "failed $TXT.sh"
1346 garbage system/
1347 done
1348 done
1350 # Device specific scripts- Placement is up-for-review
1351 if [ -f patches/devices/$DID/$DID.sh ]; then
1352 . patches/devices/$DID/$DID.sh
1355 # Replace updater-script for CM7- it formats system -Testing
1356 if [ "$ANDR" == "gingerbread" ]; then
1357 replace_updater
1360 # Rebuilding system files
1362 [[ -n ${JID[@]} ]] && printtask "### rebuild jar ###"
1363 for FILE in ${JID[@]}; do
1364 JAR=${FILE##*/}
1365 printtask "... rebuild $JAR ..."
1366 java -Xmx512M -jar smali.jar -a $API tmp/${FILE}.out/smali -o tmp/${FILE}.out/classes.dex >> "$LOG" 2>> "$LOG"
1367 [ -f tmp/${FILE}.out/classes.dex ] || smali_error "failed compiling $JAR !!!"
1368 jar -ufv ${FILE} -C tmp/${FILE}.out/ classes.dex >> "$LOG" 2>> "$LOG"
1369 if [ $FILE == "system/framework/framework.jar" ]; then
1370 jar -ufv ${FILE} -C tmp/${FILE}.out/ preloaded-classes >> "$LOG" 2>> "$LOG"
1372 done
1374 [[ -n ${AID[@]} ]] && printtask "### rebuild apk ###"
1375 for FILE in ${AID[@]}; do
1376 APK=${FILE##*/}
1377 if [ -d tmp/${FILE}.out ]; then
1378 printtask "... rebuild $APK ..."
1379 java -jar apktool.jar b tmp/${FILE}.out >> "$LOG" 2>> "$LOG" || print_error "failed compiling $FILE !!!"
1380 jar -uvf $FILE -C tmp/${FILE}.out/build/apk/ . > /dev/null 2>> "$LOG"
1382 done
1384 [[ -n ${IID[@]} ]] && printtask "### rebuild img ###"
1385 for FILE in ${IID[@]}; do
1386 printtask "### rebuild $FILE ###"
1387 case $FILE in
1388 boot.img)
1389 # Rebuilding boot.img
1390 cd boot
1391 printtask "... rebuilding ramdisk ..."
1392 ./mkbootfs$EXE ./ramdisk | gzip > ramdisk-new.gz
1394 printtask "... composing boot.img ..."
1395 BASE=$(cat boot.img-base)
1396 # hex to decimal in cygwin prefixing "0x" w/ C arithmetic
1397 PGSIZE=$((${PGFORM}$(cat boot.img-pagesize)))
1398 CMDLINE=$(cat boot.img-cmdline)
1399 echo "cmdline = no_console_suspend=1 console=null $CMDLINE" >> "$LOG"
1400 echo "pagesize = $PGSIZE" >> "$LOG"
1401 echo "base = $BASE" >> "$LOG"
1402 printtask "... rebuilding boot.img ..."
1403 ./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"
1404 cd ..
1407 print_error "cannot process $FILE"
1409 esac
1410 done
1412 printtask "### create $UPDATE.zip ###"
1413 jar -cfv tmp.zip ${IID[@]} ${JID[@]} ${AID[@]} ${CID[@]} ${TID[@]} META-INF >> "$LOG" 2>> "$LOG"
1414 java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip $UPDATE.zip 2>> "$LOG"
1416 \mv $RESTORE.zip $UPDATE.zip ..
1417 echo "### finished ###"
1418 echo "flash $UPDATE.zip to install the patched files"
1419 echo "flash $RESTORE.zip to restore the original system"
1421 # add announcement- optional.
1422 for P in ${PID[@]}; do
1423 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1424 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1425 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1426 if [ -f patches/$P/$A/$R/$B/README.txt ]; then
1427 cat patches/$P/$A/$R/$B/README.txt
1428 elif [ -f patches/$P/$A/$R/README.txt ]; then
1429 cat patches/$P/$A/$R/README.txt
1430 elif [ -f patches/$P/$A/README.txt ]; then
1431 cat patches/$P/$A/README.txt
1433 done
1435 cd ..
1436 \rm -rf "$TEMP"