Add SlimRom OpenPdroid; Hide folders+rearrange for ApG
[auto-patcher.git] / auto_patcher
blobcf4ac646268443c64addc54521ede64e291409c6
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.27) Added a new provisional as a hotfix, fix error-catching functions
107 # SHELL PROGRAMMING NOTES:
108 # [ -s FILE ]
109 # [[ -n STRING ]] or [[ -z STRING ]]
111 VERSION="v2.5.2.7"
112 CURRENT_ANDROID="4.2.1"
114 # pass variables to children
115 set -a
117 printusage_help () {
118 PID="openpdroid,3gdongle" # default example
119 brief_help
122 brief_help () {
123 echo " usage: ./auto_patcher <ROM> <MODS> <ROMTYPE>"
124 echo " example: ./auto_patcher CM10.zip $PID cm"
125 echo ""
126 echo "Use ./auto_patcher -h for the help menu"
127 echo ""
128 cleanup
129 exit
132 usage_help () {
133 PID=mods
134 mods_display
135 echo "Multiple MODS can be combined by separating them with a comma and NO SPACES!!!"
136 echo ""
137 echo " usage: ./auto_patcher <ROM> <MODS> <ROMTYPE>"
138 echo ""
139 echo " example: ./auto_patcher CM10.zip openpdroid,3gdongle cm"
140 echo ""
141 usage_more_help
144 usage_more_help () {
145 echo "* press 'q' available patches or CTRL-c to quit the help menu *"
148 display_help () {
149 cd patches
150 echo ""
151 echo "AVAILABLE PATCHES"
152 echo ""
153 echo "*******************************************************************"
154 echo "Note: There are ONLY 4 ROMTYPES: [pa, cm, aokp, and aosp]."
155 echo ""
156 #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
157 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
158 #-path './src/emacs' -prune
159 echo ""
160 echo "!!! Do not put Android Version number on command line !!!!"
161 echo "*****************************************************************"
162 echo "Specific auto_patcher script options"
163 echo " ./auto_patcher -h mods Lists mods"
164 echo " -h <MODNAME> Specific <MOD> info"
165 echo " -h advanced Advanced usage+lists all available patch dates"
166 echo ""
167 cleanup
168 exit
171 romtype_help () {
172 # From rom_error (bad romtype) and date_error (patch date w/o specifying romtype)
173 echo ""
174 echo "!!!There are only four supported ROMTYPES: 1) cm 2) aokp 3) aosp 4) pa"
175 echo ""
176 echo "Find out which of the above ROMTYPES your rom is based on and try again!"
177 echo "**********************************************"
178 echo ""
179 cleanup
180 brief_help
183 advanced_help () {
184 echo ""
185 echo "The Auto-Patcher Advanced Usage"
186 echo "*********************************"
187 echo ""
188 echo "For those of you determined to try everything..."
189 echo ""
190 echo "You can also try adding a patch date as a final argument."
191 echo ""
192 echo " ./auto_patcher <ROM> <MOD> <ROMTYPE> <DATE>"
193 echo ""
194 echo "Please note: There are only four ROMTYPES: {pa, aokp, aosp and cm}"
195 echo " -The various appellations after that are for internal use only!"
196 echo ""
197 echo "The Auto-Patcher has a pretty great rom probe, specifying the date is"
198 echo " deprecated...you don't need to, we promise."
199 echo ""
202 cleanup () {
203 [[ -n $ROOT ]] && \rm -rf "$ROOT"/tmp*
206 garbage () {
207 unset GARBAGE
208 GARBAGE=($(find $@ -name "*.orig")) && rm -rf ${GARBAGE[@]} && echo "GARBAGE= ${GARBAGE[@]}" >> "$LOG"
209 GARBAGE=($(find $@ -name "*.rej")) && rm -rf ${GARBAGE[@]} && echo "GARBAGE= ${GARBAGE[@]}" >> "$LOG"
213 print_error () {
214 # General purpose error. Used for errors in main, as opposed to probe or set-up.
215 echo ""
216 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
217 printtask "!!! error: $@"
218 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
219 echo ""
220 brief_help
223 smali_error () {
224 # Smali binary error. Problem often goes away on second run.
225 echo ""
226 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
227 printtask "!!! error: $@"
228 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
229 echo ""
230 if [[ `grep 'method index is too large' "$LOG"` != "" ]]; then
231 printtask "!!! Problem with method cap !!!"
232 printtask "... attempting fix ..."
233 . patches/.common/framework.jar.sh 2>&1 > ${JAR}.log
234 printtask "... rebuild framework.jar ..."
235 java -Xmx512M -jar smali.jar -a $API tmp/${FILE}.out/smali -o tmp/${FILE}.out/classes.dex >> "$LOG" 2>> "$LOG"
236 [ -f tmp/${FILE}.out/classes.dex ] || print_error "Could not resolve method cap issue- please submit log"
237 else
238 printtask "!!! This error is generally due to an unknown bug in the smali binary!"
239 echo "In our experience, it goes away if you run the patcher a second time."
240 echo " Please run the Auto-Patcher with the same command once again."
241 echo ""
242 echo "If after the third attempt the same thing happens,"
243 echo " please upload your logfile to our support thread!"
244 echo ""
245 cleanup
246 exit
250 mismatch_error () {
251 # Function that exposes attempts to apply a mod to an upsupported Android version
252 echo ""
253 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
254 printtask "!!! error: $@"
255 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
256 echo ""
257 cleanup
258 brief_help
261 date_error () {
262 # Remind users to include a romtype if they are going to specify a patch date
263 echo ""
264 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
265 printtask "!!! error: $@"
266 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
267 echo ""
268 echo "Please put a ROMTYPE before the patch date and run again!!"
269 romtype_help
272 rom_error () {
273 # For when an unsupported romtype is manually entered on the command-line
274 echo ""
275 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
276 printtask "!!! error: $@"
277 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
278 romtype_help
281 conflict_error () {
282 # For conflicting packages
283 echo ""
284 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
285 printtask "!!! error: $@"
286 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
287 cleanup
288 PID=mods
289 mods_info
292 misspatch_error () {
293 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
294 printtask "!! error: $@ "
295 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
296 echo ""
297 printtask "!! The Auto-Patcher could not find its patches and/or tools!"
298 echo ""
299 echo "* Did you run ./batch.sh first?"
300 echo ""
301 echo "The patch_patches.tgz and patch_tools.tgz need to be in this directory,"
302 echo " one way or another..."
303 echo ""
304 cleanup
305 brief_help
308 misstools_error () {
309 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
310 printtask "!! error: $@ "
311 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
312 printtask "Your set-up is missing a dependency."
313 echo "We require JDK, tar, patch and cpio."
314 echo ""
315 echo ""
316 echo "Each distro is different"
317 echo "but ensure you have them all installed and try again."
318 echo ""
319 cleanup
320 brief_help
323 printtask () {
324 echo "" >> "$LOG"
325 echo -e $@ | tee -a "$LOG"
328 copyfailed () {
329 echo ""
330 printtask "File for which patching failed:"
331 printtask "---------------------------------------------"
332 echo ""
333 printtask "${FAIL##*/}"
334 echo ""
335 echo "---------------------------------------------"
336 echo ""
337 echo "We can try to add a premade copy of those files."
338 echo "This sometimes works."
339 echo ""
340 printtask "You only need to report this if running the program gives you problems!!!"
341 echo ""
342 echo ""
343 askconsent && return 0 || return 1
346 askconsent () {
347 sleep 1
348 echo -n "Do you want to proceed ? (YES/no) "
349 read PROCEED
350 echo "askconsent final = ${PROCEED}: for $FAIL" >> "$LOG"
351 case $PROCEED in
352 [Yy] | [Yy][Ee][Ss])
353 return 0; # successful:
354 echo "*** You (or ApG) have elected to use a prepatched copy of $FAIL ***" >> "$LOG"
357 return 1; # error
358 echo "*** You have declined to insert $FAIL by not answering 'yes' at the prompt. ***" >> "$LOG"
360 esac
363 replace_updater () {
365 # Function for devices that use SDcard installs. Also to be tested for CM7
366 # since CM7 seems to use an updater-script that wipes EMMC. Testing
368 \rm $UPDATER_LOC/$UPDS
369 \cp patches/.common/$UPDATER_LOC/$UPDS $UPDATER_LOC
370 echo "run_program(\"/sbin/busybox\", \"umount\", \"/system\");" >> UPDATE.txt
371 cat UPDATE.txt >> $UPDATER_LOC/$UPDS
372 echo ""
373 echo "New updater-script being used:" >> "$LOG"
374 echo "-----------------------------" >> "$LOG"
375 cat $UPDATER_LOC/$UPDS >> "$LOG"
378 abspath () {
379 case `uname -s` in
380 CYGWIN*)
381 echo $(cygpath -ua "$1") | sed 's:/$::g'
383 Darwin)
384 #[[ $(echo $1 | awk '/^\//') == $1 ]] && echo "$1" || echo "$PWD/$1"
385 [[ ${1:0:1} == "/" ]] && echo "$1" || echo "$PWD/$1"
387 Linux)
388 echo $(readlink -f "$1")
391 if [[ ${1:0:1} == "/" ]]; then
392 echo "$1"
393 elif [[ ${1:0:2} == "./" ]]; then
394 echo "$PWD/${1:2}"
395 else
396 echo "$PWD/$1"
399 esac
402 mods_display () {
403 echo ""
404 echo "The Auto-Patcher $VERSION"
405 echo "*******************************"
406 echo ""
407 echo "The available mods are"
408 echo "****************************************************"
409 echo "* pdroid openpdroid voice v6supercharger *"
410 echo "* voice insecure secure external_internal *"
411 echo "* tabletUI 3gdongle pd2.0 *"
412 echo "****************************************************"
413 echo ""
414 echo "To find out more about any mod, simply enter:"
415 echo " ./auto_patcher -h <MODNAME>"
416 echo ""
417 cleanup
420 mods_info () {
421 DEPENDENCY="None" # default
422 DEV="Unknown" # default
423 CEILING=$CURRENT_ANDROID # Default is that everything works...we'll see.
424 case $PID in
425 mods)
426 mods_display
427 exit
429 auto*)
430 echo ""
431 echo "**************************************"
432 echo "The Auto-Patcher ate a kitten once..."
433 echo "**************************************"
434 printusage_help
436 advanced)
437 cd patches/
438 (advanced_help && find -H * -name 2012*) | more -d
439 echo ""
440 brief_help
442 voice)
443 FLOOR=4.0.0
444 DESC="Use on wifi-only tablets to have the software register as 'voice-enabled'. Allows VOIP like Google Voice to function."
445 DESC="bongostl's setup method here: http://forum.xda-developers.com/showthread.php?t=1823701"
446 DEV="bongostl"
449 v6supercharger)
450 FLOOR=4.0.0
451 CEILING=4.2.1
452 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."
453 DEV="Zeppelinrox"
454 DEPENDENCY="The V6 Supercharger Script. Get it at http://forum.xda-developers.com/showthread.php?t=991276/"
456 pdroid)
457 FLOOR=2.3.7
458 CEILING=4.1.2
459 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)."
460 DEV="Svyat"
461 DEPENDENCY="The Pdroid app. You can get it at http://forum.xda-developers.com/showthread.php?t=1923576"
463 pd2.0)
464 FLOOR=4.1.2
465 CEILING=4.1.2
466 DESC="An expansion of the PDroid application/framework."
467 DEV="CollegeDev"
468 DEPENDENCY="The free PDroid2.0 app available at http://forum.xda-developers.com/showthread.php?t=1923576"
470 openpdroid)
471 FLOOR=4.1.2
472 CEILING=4.2.1
473 DESC="A fork of the open-source PDroid and Pdroid2.0 framework."
474 DEV="FFU5y/wbedard/mateorod/Community"
475 DEPENDENCY="The PDroidManager app freely available from Google Play or http://forum.xda-developers.com/showthread.php?t=1994860"
477 opendroid)
478 echo ""
479 echo "No mod named 'opendroid'. You probably mean 'openpdroid'. Try again."
480 PID="mods"
481 mods_info
483 external_internal)
484 FLOOR=2.3.3
485 DESC="Swap internal and external storage."
487 insecure)
488 FLOOR=2.3.3
489 DESC="Make any boot.img insecure and allow remount as well as adb push/pull of system files. True root."
491 secure)
492 FLOOR=2.3.3
493 DESC="Make any boot.img secure."
495 3gdongle)
496 FLOOR=4.1.0
497 CEILING=4.2.1
498 DESC="Allows 3gdongles to work on wifi tablets w/o 3rd party applications."
499 DEV="trevd"
500 DEPENDENCY="None, but read the troubleshooting guide at http://forum.xda-developers.com/showthread.php?t=1798631"
502 tabletUI)
503 FLOOR=4.1.0
504 CEILING=4.1.2
505 DESC="Changes the user interface of Phones and Phablets to the popular Tablet UI."
506 DEV="barmullio"
509 FLOOR=?????
510 CEILING=?????
511 DESC="??? Unknown modtype ??? Check your spelling or the mod list!"
512 #DESC1="./auto_patcher -h mods"
513 esac
514 # strip decimals from android version (i.e. 2.3.7 becomes 237) so we can do math
515 NVID=${VID//[.]/}
516 COMPATF=${FLOOR//[.]/}
517 COMPATC=${CEILING//[.]/}
520 apk_check () {
521 if [ -f patches/$P/$A/$R/$B/$FILE ]; then
522 echo "... Patching $APK failed, but we will copy over a prepatched file ..."
523 \cp -av patches/$P/$A/$R/$B/$FILE $FILE >> "$LOG"
524 else
525 print_error "failed patching $APK!!!"
528 compat_check () {
529 for P in ${PID[@]}; do
530 mods_info
531 if [[ "$NVID" -lt "$COMPATF" ]]; then
532 mismatch_error "Your Android $VID rom is too old! The minimum for $P is \n !!! Android $FLOOR!"
534 if [[ "$NVID" -gt "$COMPATC" ]]; then
535 mismatch_error "Sorry, $P has not been made available for Android $VID yet!"
537 done
539 extpath () {
540 case `uname -s` in
541 CYGWIN*)
542 echo $(cygpath -da "$1")
545 echo $(abspath "$1")
547 esac
550 #contains () { for e in "${@:2}"; do [[ "$e" = "$1" ]] && return 0; done; return 1; }
552 parse () { echo "${1%%_*}"; }
554 getbuildprop () {
555 if [ -f system/build.prop ]; then
556 result=(`grep $1 system/build.prop | tr -d '\r' | tr '=' ' '`)
557 echo "${result[1]}"
558 else
559 echo ""
564 aosp_mod_check() {
565 jar -xvf "$ROMX" system/framework/framework2.jar >> $LOG
566 if [ -s system/framework/framework2.jar ]; then
567 ever_check
568 else
569 AOSP=aosp
571 echo $AOSP
574 ever_check() {
575 MID=$(getbuildprop ro.build.romversion)
576 if [[ $MID == "Evervolv"* ]]; then
577 AOSP=".aosp-ever"
578 else
579 MID=$(getbuildprop ro.build.display.id)
580 if [[ "$MID" == "ev"* ]]; then
581 AOSP=".aosp-ever"
582 else
583 slim_check
586 echo $AOSP
589 slim_check() {
590 SLMID=$(getbuildprop ro.modversion)
591 SLMMID=$(getbuildprop updateme.name)
592 if [[ "$SLMMID" == "Slim"* ]] || [[ $SLMMID == "slim"* ]]; then
593 AOSP=".aosp-slim"
594 elif [[ "$SLMID" == "Slim"* ]] || [[ $SLMID == "slim"* ]]; then
595 AOSP=".aosp-slim"
596 else
597 if [[ "$ANDR" == "4.1" ]]; then
598 AOSP=.aosp-mod
599 else
600 AOSP="aosp"
605 pa_check() {
606 CMID=$(getbuildprop ro.modversion)
607 PAID=$(getbuildprop ro.pa.version)
608 MID=$(getbuildprop ro.build.display.id)
609 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
610 DID=$(getbuildprop ro.product.device)
611 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
612 if [[ -n $PAID ]]; then
613 RID=pa
614 else
615 case $CMID in
616 [Pp][Aa]*)
617 RID=pa;
620 RID=cm;
622 esac
626 romtype_set () {
627 case $RID in
629 ROMTYPE="cm"
631 aokp*)
632 ROMTYPE="aokp"
635 ROMTYPE="pa"
638 ROMTYPE="aosp"
640 esac
643 proberom () {
644 VID=$(getbuildprop ro.build.version.release)
645 if [ ${#VID} -lt 4 ]; then # in case of non-standard versioning in build.prop (defy!)
646 ANDR=$VID
647 else
648 ANDR="${VID%.*}" # Cut to 1 significant digit to cover specific range or release.
650 if [ "$ANDR" == "2.3" ]; then
651 FLAVR=gingerbread
652 API=10
653 RID=cm;
654 elif [ "$ANDR" == "4.0" ]; then
655 FLAVR=ics
656 API=15
657 MID=$(getbuildprop ro.rommanager.developerid)
658 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.modversion))
659 DID=$(getbuildprop ro.product.device)
660 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
662 case "$MID" in
663 pa|cm9|cm|cyanogenmod*)
664 RID=cm;
666 aokp|teamkang)
667 RID=aokp;
669 aosp*)
670 RID=aosp;
673 echo "!!! $MID is not supported yet, trying generic latest !!!"
675 esac
676 elif [ "$ANDR" == "4.1" ]; then
677 FLAVR=jellybean
678 API=16
679 CMID=$(getbuildprop ro.cm.version)
680 if [[ -n $CMID ]]; then
681 pa_check
682 else
683 MID=$(getbuildprop ro.build.display.id)
684 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
685 DID=$(getbuildprop ro.product.device)
686 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
687 case "$MID" in
688 cm10|cm*|cyanogenmod*)
689 RID=cm;
691 aokp*|teamkang)
692 RID=aokp;
694 pa*)
695 RID=pa;
697 ev*)
698 RID=".aosp-ever";
701 RID=`aosp_mod_check`;
703 esac
705 elif [ "$ANDR" == "4.2" ]; then
706 FLAVR=jellybean
707 API=17
708 CMID=$(getbuildprop ro.cm.version)
709 MID=$(getbuildprop ro.build.display.id)
710 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
711 DID=$(getbuildprop ro.product.device)
712 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
714 case "$MID" in
715 cm10|cm*|cyanogenmod*)
716 RID=cm;
718 aokp*|teamkang)
719 RID=aokp;
721 pa*)
722 RID=pa;
724 ev*|Ever*)
725 RID=".aosp-ever";
728 RID=`ever_check`;
730 esac
731 else
732 print_error "unknown ROM version $VID"
734 romtype_set
735 echo "... result of ROM check: version= $VID rom= $ROMTYPE ..."
739 # Advanced build date query
740 # This should set the patch date automatically.
742 build_query() {
743 UTC=$(getbuildprop ro.build.date.utc)
745 # Difference in how OS X and Linux/Cygwin handles 'date' utility
746 case `uname -s` in
747 [Dd]arwin)
748 BDID=`date -r $UTC +%Y%m%d`
749 echo "#### Darwin Build Query used ####" >> "$LOG"
752 BDID=`date -d "1970-01-01 UTC $UTC seconds" +"%Y%m%d"`
753 echo "#### Standard Build Query ####" >> "$LOG"
755 esac
757 # If patch date is specified on CLI, use that patch date
758 if [ $# -gt 3 ]; then
759 BID=${4//,/ };
760 BDID=$BID
761 else
762 case $ANDR in
763 2.3)
764 # CM7 roms do not have UTC time stamp- so no build query.
765 BID=latest;
766 echo "*** CM7 roms default to latest patches. If using an older rom ***"
767 echo "*** specify patch date on command line. Use -h to see available patches ***"
770 for P in ${PID[@]}; do
771 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
772 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
773 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
774 PAR=patches/$P/$A/$R
775 PARB=patches/$P/$A/$R/$B
776 DATES=`ls patches/$P/$A/$R/ | grep '201*'`
777 # Intialize variable - High so as to determine lowest in first loop.
778 BID=20201231
779 # find earliest available patch date
780 for i in $DATES; do
781 if [[ $i -lt $BID ]]; then
782 BID=$i
784 done
785 # Check if earliest patches are from before build date. Else use earliest
787 # If older than earliest patch set, then find best match
788 if [[ $(($BID-$BDID)) -lt 0 ]]; then
789 for g in $DATES; do
790 # use any patch that matches $UTC
791 if [[ $(($BDID-$g)) -eq 0 ]]; then
792 BID=$g
793 break
794 # Set highest $BID w/o going over $UTC
795 elif [[ $(($BDID-$g)) -gt 0 ]] && [[ $g -gt $BID ]]; then
796 BID=$g
798 done
800 echo "... $PID patch date has been set to: $BID ..."
801 B=$BID
802 break
803 done
805 esac
809 proberil () {
810 RIL=$(getbuildprop ro.telephony.ril_class)
811 [[ -n $RIL ]] && printtask "... result of ROM check: RIL= $RIL"
814 rominfo () {
815 echo "# VER= $VERSION" >> "$LOG"
816 echo "# OS= $OSTYPE ${BIT}bit" >> "$LOG"
817 echo "# VID= $VID" >> "$LOG"
818 echo "# PID= ${PID[@]}" >> "$LOG"
819 echo "# MID= $MID" >> "$LOG"
820 echo "# RID= $RID" >> "$LOG"
821 echo "# ANDR= $ANDR" >> "$LOG"
822 echo "# BDID= $BDID" >> "$LOG"
823 echo "# DID= $DID" >> "$LOG"
824 echo "# BID= $BID" >> "$LOG"
825 echo "Patches are $PID/$ANDR/$RID/$BID" >> "$LOG"
829 if [[ $1 == -h ]]; then
830 if [ $# -gt 1 ]; then
831 PID=$2
832 mods_info
833 echo ""
834 echo "The Auto-Patcher $VERSION by Mateorod and Pastime1971"
835 echo "*************************************************"
836 echo ""
837 echo "Mod Name: $PID"
838 echo ""
839 echo " $DESC"
840 if [[ -z $DESC1 ]]; then # test to see is there is a second DESC line
841 echo "$DESC1"
843 if [[ $((DESC2)) -gt 0 ]]; then
844 echo "$DESC2"
846 echo ""
847 echo "Developer: $DEV"
848 echo "Dependancies: $DEPENDENCY"
849 echo ""
850 echo "Works on ROMs from Android $FLOOR -> $CEILING"
851 echo
852 brief_help
853 exit
857 [[ $# -lt 1 || -z $1 ]] && PID="mods" && mods_info
858 [[ $1 == "-h" ]] && usage_help | less && display_help
860 echo ""
861 echo "The Auto-Patcher $VERSION"
862 echo ""
863 # by pastime1971 and mateorod
865 ROOT=$(abspath `dirname "$0"`)
866 TOOL="$ROOT/patch_tools.tgz"
867 PTCH="$ROOT/patch_patches.tgz"
868 cleanup
869 # set temporaray directory
870 DATE=`date +%Y%m%d%H%M%S`
871 TEMP=$ROOT/tmp$DATE
872 TMP=$ROOT/tmp$DATE
873 TMPDIR=$ROOT/tmp$DATE
874 mkdir "$TEMP"
875 ROM=$(abspath "$1")
876 ROMX=$(extpath "$1")
878 if [[ $OSTYPE == "cygwin" ]]; then
879 EXE=".exe"
880 PGFORM="0x"
883 LOG=$(abspath ./log$DATE.txt)
884 #echo $ROOT $TOOL $ROM $TEMP "$LOG"
885 echo "ROOT= $ROOT" >> "$LOG"
886 echo "TOOL= $TOOL" >> "$LOG"
887 echo "ROM= $ROM" >> "$LOG"
888 echo "ROMX= $ROMX" >> "$LOG"
890 \rm -f $RESTORE.zip $UPDATE.zip
892 CHK=$(getconf LONG_BIT)
893 if [[ $CHK = "64" ]]; then
894 BIT=64
895 else [[ $BIT = "32" ]];
896 BIT=32
900 printtask "### verify tools ###"
901 which patch >> "$LOG" || misstools_error "Missing \"patch\" utility."
902 which tar >> "$LOG" || misstools_error "Missing \"tar\" utility"
903 which jar >> "$LOG" || misstools_error "Missing \"Java Development Kit\" (JDK)"
904 which java >> "$LOG" || misstools_error "Missing \"Java Development Kit\" (JDK)"
905 which cpio >> "$LOG" || misstools_error "Missing \"cpio\" utility"
906 [ -f "$TOOL" ] || misspatch_error "patch_tool.tgz is missing"
907 [ -f "$PTCH" ] || misspatch_error "patch_patches.tgz is missing"
908 printtask "### verify ROM ###"
909 [ -f "$ROM" ] || print_error "Cannot find $1!! Make sure you have the location and name right"
910 echo "### running $0 $@" >> "$LOG"
911 cd "$TEMP"
913 PATH="$TEMP:$PATH"
914 export PATH
915 echo "PATH= $PATH" >> "$LOG"
917 printtask "### unzip patch tools ###"
918 tar xzf "$TOOL" > /dev/null || print_error "failed extracting tools !!!"
920 # Get OS specific tools
921 case `uname -s` in
922 CYGWIN*)
923 \mv cygwin/aapt.exe .
924 \mv cygwin/*.exe boot/
925 \rm -rf cygwin # why? If you want to we can keep/add it to mac/linux, though.
927 [Dd]arwin)
928 \mv mac/aapt .
930 [Ll]inux)
931 \mv linux/aapt .
934 \mv linux/aapt .
936 esac
937 # Ensure aapt permissions - possibly to one day be expanded to all tools in a function.
938 chmod a+x aapt$EXE
940 printtask "### unzip patch patches ###"
941 tar xzf "$PTCH" > /dev/null || print_error "failed extracting patches !!!"
943 # we need build.prop for both RIL probing and ROM probing
944 jar -xvf "$ROMX" system/build.prop 2>> "$LOG" || print_error "failed extracting build.prop from $ROMX !!!"
946 # rom + ril type
947 proberil
948 printtask "### probe rom type ###"
949 proberom
951 # rom type
952 if [ $# -gt 1 ]; then
953 PIT=$2
954 if [[ "$PIT" = "-h" ]]; then
955 display_help
958 if [ $# -gt 2 ]; then
959 RID=$3
960 case "$RID" in
961 cm10|cm*|cyanogenmod*)
963 aokp*|teamkang)
964 RID=aokp;
966 pa*)
967 RID=pa;
969 aosp-ever)
970 RID=".aosp-ever";
972 aosp*)
973 case "ANDR" in
974 4.1)
975 RID=`aosp_mod_check`;
978 RID=`ever_check`
980 esac
982 201*)
983 date_error "You must specify ROMTYPE if designating a patch date!!"
986 rom_error "$RID is not a valid ROMTYPE!!"
988 esac
989 romtype_set
990 echo "... Using $ROMTYPE patches ..."
991 else
992 echo "... Using results of ROM check ..."
995 # patch type
996 if [ $# -gt 1 ]; then
997 PIL=${2//,/ } # If more than one mod, make string separated by spaces
998 else
999 PIL="openpdroid"
1000 echo "No mods selected. Defaulting to openpdroid, since that's what you probably want..."
1003 PID=(${PIL// / }) # turn string into array
1004 COPYPID=("${PID[@]}") # working copy to iterate over
1005 MODS_NUMBER=${#COPYPID[@]} # number of elements (mods)
1007 if [[ $MODS_NUMBER > 1 ]]; then
1008 INDEX=0
1009 for p in ${COPYPID[@]}; do
1010 if [ "$p" = "pdroid" ] || [ "$p" = "pd2.0" ] ||[ "$p" = "openpdroid" ]; then
1011 SPID[0]=$p
1012 unset COPYPID["$INDEX"]
1013 break
1014 else
1015 INDEX=$((INDEX + 1))
1017 done
1018 for p in ${COPYPID[@]}; do
1019 if [ "$p" = "pdroid" ] || [ $p = "pd2.0" ] ||[ $p = "openpdroid" ]; then
1020 conflict_error "Those mods conflict! Only one pdroid mod at a time!"
1021 else
1022 i=${#SPID[@]}
1023 SPID[i]=$p
1024 i+=1
1026 done
1027 else
1028 SPID=${COPYPID[@]}
1030 for P in ${PIL[@]}; do
1031 [[ ${PID[@]} =~ $P ]] || PID=(${PID[@]} $P)
1032 done
1034 # Check to make sure selected roms are available for the Android version of patched ROM
1035 compat_check
1037 # Build date
1038 if [ $# -gt 3 ]; then # if a date is specified on command line...
1040 # Set date to match argument and ensure that patches with that date exist
1041 BID=$4
1042 [ -d patches/$P/$ANDR/$RID/$BID ] || print_error "No $P patches for $RID on $BID!! Try the help menu!!"
1044 # Run build_query- this overrides the above but gets useful info
1045 build_query
1046 # Reset patch date to argument
1047 BID=$4
1048 echo "... $PID patch date set manually to: $BID ..."
1049 else
1050 build_query # if no date specified, use one from build_query
1053 # echo ROM info
1054 rominfo
1056 if [[ ( "$PID" == "-h" || "$RID" == "-h" || "$BID" == "-h" ) ]]; then
1057 #Although this placement may be perfect for romfilter. although it throws the scheme...
1058 display_help
1060 #Begin cycle
1062 for P in ${PID[@]}; do
1063 [ -d patches/$P ] || print_error "$P is not available"
1064 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1065 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1066 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1068 unset FILES
1069 [ -f patches/$P/files.txt ] && FILES=$(cat patches/$P/files.txt)
1070 [ -f patches/$P/$A/files.txt ] && FILES=$(cat patches/$P/$A/files.txt)
1071 [ -f patches/$P/$A/$R/files.txt ] && FILES=$(cat patches/$P/$A/$R/files.txt)
1072 [ -f patches/$P/$A/$R/$B/files.txt ] && FILES=$(cat patches/$P/$A/$R/$B/files.txt)
1073 for FILE in ${FILES[@]}; do
1074 case "$FILE" in
1075 +system/*)
1076 [[ ${CID[@]} =~ ${FILE:1} ]] && print_error "${FILE:1} is already being copied" || CID=(${CID[@]} ${FILE:1})
1078 -system/*)
1079 [[ ${EID[@]} =~ ${FILE:1} ]] || EID=(${EID[@]} ${FILE:1})
1081 system/*.jar)
1082 [[ ${JID[@]} =~ $FILE ]] || JID=(${JID[@]} $FILE)
1083 echo "set_perm(0, 0, 0644, \"/$FILE\");" >> UPDATE.txt
1085 system/*.apk)
1086 [[ ${AID[@]} =~ $FILE ]] || AID=(${AID[@]} $FILE)
1087 echo "set_perm(0, 0, 0644, \"/$FILE\");" >> UPDATE.txt
1089 *.img)
1090 [[ ${IID[@]} =~ $FILE ]] || IID=(${IID[@]} $FILE)
1092 system/*)
1093 [[ ${TID[@]} =~ $FILE ]] || TID=(${TID[@]} $FILE)
1095 esac
1096 done
1097 done
1098 echo "### DELETE FILES= ${EID[@]}" >> "$LOG"
1099 echo "### COPY FILES= ${CID[@]}" >> "$LOG"
1100 echo "### JAR FILES= ${JID[@]}" >> "$LOG"
1101 echo "### APK FILES= ${AID[@]}" >> "$LOG"
1102 echo "### IMG FILES= ${IID[@]}" >> "$LOG"
1103 echo "### TXT FILES= ${TID[@]}" >> "$LOG"
1105 # extract system files
1106 printtask "### unzip rom ###"
1107 jar -xvf "$ROMX" ${JID[@]} ${AID[@]} ${IID[@]} ${TID[@]} 2>> "$LOG" || print_error "failed extracting ${JID[@]} ${AID[@]} ${IID[@]} from $ROMX !!!"
1110 # Update/Restore.zip scripts and prep
1111 printtask "### create updater script ###"
1112 UPDATER_LOC=META-INF/com/google/android
1113 UPDS=updater-script
1114 UPDATE="update-$ROMTYPE-$DID-$BDID-${PIL// /-}"
1115 RESTORE="restore-$ROMTYPE-$DID-$BDID"
1117 jar -xvf "$ROMX" $UPDATER_LOC/$UPDS $UPDATER_LOC/update-binary
1118 jar -xvf "$ROMX" $UPDATER_LOC/update-binary-installer 1> /dev/null 2> /dev/null
1120 # Determine Installer- Aroma or ClockworkMod
1121 if [ -f $UPDATER_LOC/update-binary-installer ]; then
1122 printtask "... using Aroma installer ..."
1123 \mv $UPDATER_LOC/update-binary-installer $UPDATER_LOC/update-binary
1124 else
1125 printtask "... using Clockworkmod installer ..."
1128 # Create updater scripts
1129 cat patches/.common/updater-message.txt >> $UPDS
1130 cat $UPDATER_LOC/$UPDS | grep ^mount | grep "/system" | head -n 1 >> $UPDS
1131 [ -s $UPDS ] || echo "run_program(\"/sbin/busybox\", \"mount\", \"/system\");" >> $UPDS
1132 # restore the original
1133 for FILE in ${EID[@]}; do
1134 jar -xvf "$ROMX" $FILE 2> /dev/null || printtask "!!! warning $FILE cannot be restored !!!"
1135 done
1136 # replace with the original or delete it
1137 for FILE in ${CID[@]}; do
1138 jar -xvf "$ROMX" $FILE 2> /dev/null || echo "delete(\"/$FILE\");" >> $UPDS
1139 done
1140 echo "package_extract_dir(\"system\", \"/system\");" >> $UPDS
1141 # permission management for files that need specific perms
1142 cat $UPDATER_LOC/$UPDS | grep set_perm | grep "/system" >> $UPDS
1143 for P in ${PID[@]}; do
1144 if [ -s patches/$P/$A/set_perm.txt ]; then
1145 echo "...setting permissions..."
1146 cat patches/$P/$A/set_perm.txt >> $UPDS
1148 done
1149 cat $UPDATER_LOC/$UPDS | grep ^unmount | grep "/system" | head -n 1 >> $UPDS
1150 [[ ${IID[@]} =~ boot.img ]] && cat $UPDATER_LOC/$UPDS | grep "boot.img" >> $UPDS
1151 echo "ui_print(\" .\");" >> $UPDS
1152 echo "ui_print(\" .\");" >> $UPDS
1153 echo "ui_print(\" done!\");" >> $UPDS
1154 cat $UPDS > $UPDATER_LOC/$UPDS
1155 echo "# generated $UPDS" >> "$LOG"
1156 cat $UPDS >> "$LOG"
1158 printtask "### create restore.zip ###"
1159 jar -cvf tmp.zip ${JID[@]} ${AID[@]} ${IID[@]} META-INF > /dev/null 2>> "$LOG"
1160 java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip signed.zip 2>> "$LOG"
1161 \mv signed.zip $RESTORE.zip
1162 \rm -f tmp.zip
1165 # Begin patching process
1167 # decompile system files
1168 printtask "### decompile system files ###"
1169 for FILE in ${JID[@]}; do
1170 JAR=${FILE##*/}
1171 printtask "... decompile $JAR ..."
1172 java -jar baksmali.jar -b -a $API -o tmp/${FILE}.out/smali ${FILE} >> "$LOG" 2>> "$LOG"
1173 if [ $FILE == "system/framework/framework.jar" ]; then
1174 printtask "... extract preloaded-classes ..."
1175 jar -xvf ${FILE} preloaded-classes >> "$LOG" 2>> "$LOG"
1176 \mv preloaded-classes tmp/${FILE}.out/
1178 done
1180 # install framework-files for APK...
1181 if [ ${#AID[@]} -gt 0 ]; then
1182 jar -xvf "$ROMX" system/framework/framework-res.apk >> "$LOG"
1183 printtask "... installing framework files ..."
1184 java -jar apktool.jar if system/framework/framework-res.apk
1185 # Decompile APKs
1186 for FILE in ${AID[@]}; do
1187 APK=${FILE##*/}
1188 if [ -f $FILE ]; then
1189 printtask "... decompile $APK ..."
1190 java -jar apktool.jar d -f $FILE tmp/$FILE.out
1192 done
1195 # Unpack image files {boot.img only so far...}
1196 for FILE in ${IID[@]}; do
1197 printtask "### unpacking $FILE ###"
1198 case "$FILE" in
1199 boot.img)
1200 if [ -f boot.img ]; then
1201 cd boot
1202 ./unpackbootimg$EXE -i ../boot.img >> "$LOG" 2>> "$LOG"
1203 mkdir ramdisk
1204 cd ramdisk
1205 gzip -dc ../boot.img-ramdisk.gz | cpio -i >> "$LOG" 2>> "$LOG"
1206 cd ../../
1207 else
1208 print_error "A mod needs to patch boot.img! This rom does not contains boot.img."
1212 print_error "cannot process $FILE"
1214 esac
1215 done
1217 # apply system modification
1219 for P in ${PID[@]}; do
1220 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1221 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1222 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1223 PAR=patches/$P/$A/$R
1224 PARB=patches/$P/$A/$R/$B
1226 unset FILES COPY DELS JARS APKS IMGS TXTS
1227 [ -f patches/$P/files.txt ] && FILES=$(cat patches/$P/files.txt)
1228 [ -f patches/$P/$A/files.txt ] && FILES=$(cat patches/$P/$A/files.txt)
1229 [ -f patches/$P/$A/$R/files.txt ] && FILES=$(cat patches/$P/$A/$R/files.txt)
1230 [ -f patches/$P/$A/$R/$B/files.txt ] && FILES=$(cat patches/$P/$A/$R/$B/files.txt)
1231 for FILE in ${FILES[@]}; do
1232 case $FILE in
1233 +system/*)
1234 COPY=(${COPY[@]} ${FILE:1})
1236 -system/*)
1237 DELS=(${DELS[@]} ${FILE:1})
1239 system/*.jar)
1240 JARS=(${JARS[@]} $FILE)
1242 system/*.apk)
1243 APKS=(${APKS[@]} $FILE)
1245 *.img)
1246 IMGS=(${IMGS[@]} $FILE)
1248 system/*)
1249 TXTS=(${TXTS[@]} $FILE)
1251 esac
1252 done
1254 [[ -n ${COPY[@]} ]] && echo "### copy patch $P/$A/$ROMTYPE/$B ###"
1255 echo "### copy patch $P/$A/$R/$B ###" >> "$LOG"
1256 for FILE in ${COPY[@]}; do
1257 printtask "... copying $FILE ..."
1258 DEST=${FILE%/*}
1259 mkdir -p ./$DEST
1260 if [ -e patches/$P/$A/$R/$B/$FILE ]; then
1261 [ -e $FILE ] && printtask "... overwriting $FILE from $P ..."
1262 \cp -av patches/$P/$A/$R/$B/$FILE ./$DEST >> "$LOG"
1263 else
1264 print_error "$FILE is missing in the patch. Please upload your logfile to the support thread!"
1266 done
1268 # unconditional smali copying- For particularly troublesome files
1269 [ -f patches/$P/smali.txt ] && SMALI=$(cat patches/$P/smali.txt)
1270 [ -f patches/$P/$A/smali.txt ] && SMALI=$(cat patches/$P/$A/smali.txt)
1271 [ -f patches/$P/$A/$R/smali.txt ] && SMALI=$(cat patches/$P/$A/$R/smali.txt)
1272 [ -f patches/$P/$A/$R/$B/smali.txt ] && SMALI=$(cat patches/$P/$A/$R/$B/smali.txt)
1273 MOVE=${SMALI##*/}
1274 for SMALI in ${SMALI[@]}; do
1275 if [ -f patches/$P/$A/$R/.provisionals/$SMALI ]; then
1276 printtask "... overwriting $MOVE ..."
1277 \cp -a patches/$P/$ANDR/$R/.provisionals/$SMALI tmp/$SMALI >> "$LOG"
1278 elif [ -f patches/$P/$A/.provisionals/$SMALI ]; then
1279 printtask "... overwriting $MOVE ..."
1280 \cp -a patches/$P/$ANDR/.provisionals/$SMALI tmp/$SMALI >> "$LOG"
1282 done
1284 [[ -n ${DELS[@]} ]] && echo "### delete patch $P/$A/$ROMTYPE/$B ###"
1285 echo "### delete patch $P/$A/$R/$B ###" >> "$LOG"
1286 for FILE in ${DELS[@]}; do
1287 printtask "... deleting $FILE ..."
1288 \rm -rf ./$FILE
1289 done
1290 [[ -n ${JARS[@]} ]] && echo "### jar patch $P/$A/$ROMTYPE/$B ###"
1291 echo "### jar patch $P/$A/$R/$B ###" >> "$LOG"
1292 for FILE in ${JARS[@]}; do
1293 JAR=${FILE##*/}
1294 NAME=${JAR%.jar}
1295 printtask "... apply $NAME.patch ..."
1296 patch -Nls -p1 -d tmp/${FILE}.out < $PARB/${NAME}.patch 2>&1 > ${JAR}.log
1297 cat ${JAR}.log | tee -a "$LOG"
1298 case "$NAME" in
1299 framework)
1300 # patch preloaded-classes only if a patch exists
1301 if [ -f $PARB/preloaded.patch ]; then
1302 printtask "... apply preloaded.patch ..."
1303 patch -Nls -p1 -d tmp/${FILE}.out < $PARB/preloaded.patch 2>&1 > preloaded.log
1304 cat preloaded.log | tee -a "$LOG"
1305 [[ `grep FAILED preloaded.log` != "" ]] && print_error "failed preloaded.patch"
1309 echo -n "" # do nothing else
1311 esac
1312 # substitute failed smali with provisional (a prepatched smali file)
1313 unset FAILS
1314 FAILS=(`grep FAILED ${JAR}.log | sed -e 's/.*smali\///' | sed -e 's/\.rej//'`)
1315 if [[ -n ${FAILS[@]} ]]; then
1316 printtask "!!! PATCHING FAILED FOR ${FAILS[@]} !!!"
1317 echo "### replace ${FAILS[@]} ###" > ${JAR}.log
1318 for FAIL in ${FAILS[@]}; do
1319 PROVISIONAL="patches/$P/$ANDR/.provisionals/${FILE}.out/smali/${FAIL}"
1320 echo "!!! patch error for $FAIL !!!" >> "$LOG"
1321 #cat tmp/$FILE.out/smali/${FAIL}.rej >> "$LOG" # FOR DEBUGGING
1322 [[ ${SID[@]} =~ $FAIL ]] && print_error "$FAIL was already replaced before"
1323 [ -f "$PROVISIONAL" ] || print_error "failed $FAIL in $JAR cannot be remedied"
1324 copyfailed
1325 printtask "... replace $FAIL ..."
1326 \rm -rf tmp/${FILE}.out/smali/${FAIL} tmp/${FILE}.out/smali/${FAIL}.orig tmp/${FILE}.out/smali/${FAIL}.rej
1327 \cp -av "$PROVISIONAL" tmp/${FILE}.out/smali/${FAIL} >> "$LOG"
1328 SID=(${SID[@]} $FAIL)
1329 done
1331 [[ `grep FAILED ${JAR}.log` != "" ]] && print_error "failed $NAME.patch"
1332 garbage tmp/${FILE}.out
1334 # run special $JAR.sh scripts if any JAR needs special attention
1335 if [ -f patches/$P/$A/$R/$B/${JAR}.sh ]; then
1336 printtask "... apply $JAR.sh ..."
1337 . patches/$P/$A/$R/$B/${JAR}.sh 2>&1 > ${JAR}.log
1338 cat ${JAR}.log | tee -a "$LOG"
1340 done
1342 [[ -n ${APKS[@]} ]] && echo "### apk patch $P/$A/$ROMTYPE/$B ###"
1343 echo "### apk patch $P/$A/$R/$B ###" >> "$LOG"
1344 for FILE in ${APKS[@]}; do
1345 APK=${FILE##*/}
1346 if [ -d "tmp/${FILE}.out" ] ; then
1347 printtask "... apply $APK.patch ..."
1348 patch -Nls -p2 -d tmp/${FILE}.out < $PARB/${APK}.patch 2>&1 >> ${APK}.log
1349 cat ${APK}.log | tee -a "$LOG"
1350 [[ `grep FAILED ${APK}.log` != "" ]] && apk_check
1351 garbage tmp/${FILE}.out
1352 else
1353 echo "No $APK in your ROM. Not able to patch this file."
1354 echo "## No $APK in ROM ###" >> "$LOG"
1356 done
1357 [[ -n ${IMGS[@]} ]] && echo "### img patch $P/$A/$ROMTYPE/$B ###"
1358 echo "### img patch $P/$A/$R/$B ###" >> "$LOG"
1359 for FILE in ${IMGS[@]}; do
1360 IMG=${FILE##*/}
1361 printtask "... applying $IMG.patch ..."
1362 patch -Nls -p1 -d boot/ramdisk < $PARB/${IMG}.patch >> "$LOG" || print_error "failed patching $FILE"
1363 done
1365 # Text Editing Functions --this can really do just about anything. Needs a working restore!
1366 [[ -n ${TXTS[@]} ]] && echo "### text patch $P/$A/$ROMTYPE/$B ###"
1367 echo "### text patch $P/$A/$R/$B ###" >> "$LOG"
1368 for FILE in ${TXTS[@]}; do
1369 TXT=${FILE##*/}
1370 if [[ -f $PARB/${TXT}.patch ]]; then
1371 printtask "... apply $TXT.patch ..."
1372 patch -Nls -p2 -d system/ < $PARB/${TXT}.patch 2>&1 > ${TXT}.log
1373 #cat ${TXT}.log | tee -a "$LOG"
1374 [[ `grep FAILED ${TXT}.log` != "" ]] && print_error "failed $TXT.patch"
1376 if [[ -f $PAR/${TXT}.awk ]]; then
1377 printtask "... apply $TXT.awk ..."
1378 awk -f $PAR/${TXT}.awk $FILE > text || print_error "failed $TXT.awk"
1379 mv text $FILE
1381 if [[ -f $PAR/${TXT}.sed ]]; then
1382 printtask "... apply $TXT.sed ..."
1383 sed -f $PAR/${TXT}.sed $FILE > text || print_error "failed $TXT.sed"
1384 mv text $FILE
1386 if [[ -f $PAR/${TXT}.sh ]]; then
1387 printtask "... apply $TXT.sh ..."
1388 . $PAR/${TXT}.sh 2>&1 >> ${TXT}.log || print_error "failed $TXT.sh"
1390 garbage system/
1391 done
1392 done
1394 # Device specific scripts- Placement is up-for-review
1395 if [ -f patches/.devices/$DID/$DID.sh ]; then
1396 . patches/.devices/$DID/$DID.sh
1399 # Replace updater-script for CM7- it formats system -Testing
1400 if [ "$ANDR" == "gingerbread" ]; then
1401 replace_updater
1404 # Rebuilding system files
1406 [[ -n ${JID[@]} ]] && printtask "### rebuild jar ###"
1407 for FILE in ${JID[@]}; do
1408 JAR=${FILE##*/}
1409 printtask "... rebuild $JAR ..."
1410 java -Xmx512M -jar smali.jar -a $API tmp/${FILE}.out/smali -o tmp/${FILE}.out/classes.dex >> "$LOG" 2>> "$LOG"
1411 [ -f tmp/${FILE}.out/classes.dex ] || smali_error "failed compiling $JAR !!!"
1412 jar -ufv ${FILE} -C tmp/${FILE}.out/ classes.dex >> "$LOG" 2>> "$LOG"
1413 if [ $FILE == "system/framework/framework.jar" ]; then
1414 jar -ufv ${FILE} -C tmp/${FILE}.out/ preloaded-classes >> "$LOG" 2>> "$LOG"
1416 done
1418 [[ -n ${AID[@]} ]] && printtask "### rebuild apk ###"
1419 for FILE in ${AID[@]}; do
1420 APK=${FILE##*/}
1421 if [ -d tmp/${FILE}.out ]; then
1422 printtask "... rebuild $APK ..."
1423 java -jar apktool.jar b tmp/${FILE}.out >> "$LOG" 2>> "$LOG" || print_error "failed compiling $FILE !!!"
1424 jar -uvf $FILE -C tmp/${FILE}.out/build/apk/ . > /dev/null 2>> "$LOG"
1426 done
1428 [[ -n ${IID[@]} ]] && printtask "### rebuild img ###"
1429 for FILE in ${IID[@]}; do
1430 printtask "### rebuild $FILE ###"
1431 case $FILE in
1432 boot.img)
1433 # Rebuilding boot.img
1434 cd boot
1435 printtask "... rebuilding ramdisk ..."
1436 ./mkbootfs$EXE ./ramdisk | gzip > ramdisk-new.gz
1438 printtask "... composing boot.img ..."
1439 BASE=$(cat boot.img-base)
1440 # hex to decimal in cygwin prefixing "0x" w/ C arithmetic
1441 PGSIZE=$((${PGFORM}$(cat boot.img-pagesize)))
1442 CMDLINE=$(cat boot.img-cmdline)
1443 echo "cmdline = no_console_suspend=1 console=null $CMDLINE" >> "$LOG"
1444 echo "pagesize = $PGSIZE" >> "$LOG"
1445 echo "base = $BASE" >> "$LOG"
1446 printtask "... rebuilding boot.img ..."
1447 ./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"
1448 cd ..
1451 print_error "cannot process $FILE"
1453 esac
1454 done
1456 printtask "### create $UPDATE.zip ###"
1457 jar -cfv tmp.zip ${IID[@]} ${JID[@]} ${AID[@]} ${CID[@]} ${TID[@]} META-INF >> "$LOG" 2>> "$LOG"
1458 java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip $UPDATE.zip 2>> "$LOG"
1460 \mv $RESTORE.zip $UPDATE.zip ..
1461 echo "### finished ###"
1462 echo "flash $UPDATE.zip to install the patched files"
1463 echo "flash $RESTORE.zip to restore the original system"
1465 # add announcement- optional.
1466 for P in ${PID[@]}; do
1467 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1468 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1469 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1470 if [ -f patches/$P/$A/$R/$B/README.txt ]; then
1471 cat patches/$P/$A/$R/$B/README.txt
1472 elif [ -f patches/$P/$A/$R/README.txt ]; then
1473 cat patches/$P/$A/$R/README.txt
1474 elif [ -f patches/$P/$A/README.txt ]; then
1475 cat patches/$P/$A/README.txt
1477 done
1479 cd ..
1480 \rm -rf "$TEMP"