Versioning to 2.6.0
[auto-patcher.git] / auto_patcher
blob42786b343ecd24d33bf28a4f0dce9124e3ab0ae9
1 #!/bin/bash
3 # version: beta v2.6.0, patches 2013.02.01.
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.3) SlimRom support. Rearrange structure for ApG.
106 # 2013.01.23. (v2.5.4) Fix small bugs related to rearrange
107 # 2013.01.25. (v2.5.7) 4.2 TabletUI support [cm,aokp,aosp,Evervolv]
108 # 2013.01.28. (v2.5.8) Fix for ICS PDroid; small fixes/expansions
109 # 2013.02.01. (v2.6.0) OpenPdroid 1.0.1 patches (cm, aokp, aosp, evervolv and slimrom. no pa.
110 # Fixed TabletUI for Cm10.1- aosp to come. Removed most old patches.
112 # SHELL PROGRAMMING NOTES:
113 # [ -s FILE ]
114 # [[ -n STRING ]] or [[ -z STRING ]]
116 VERSION="v2.6.0"
117 CURRENT_ANDROID="4.2.1"
119 # pass variables to children
120 set -a
122 printusage_help () {
123 PID="openpdroid,3gdongle" # default example
124 brief_help
127 brief_help () {
128 echo " usage: ./auto_patcher <ROM> <MODS> <ROMTYPE>"
129 echo " example: ./auto_patcher CM10.zip $PID cm"
130 echo ""
131 echo "Use ./auto_patcher -h for the help menu"
132 echo ""
133 cleanup
134 exit
137 usage_help () {
138 PID=mods
139 mods_display
140 echo "Multiple MODS can be combined by separating them with a comma and NO SPACES!!!"
141 echo ""
142 echo " usage: ./auto_patcher <ROM> <MODS> <ROMTYPE>"
143 echo ""
144 echo " example: ./auto_patcher CM10.zip openpdroid,3gdongle cm"
145 echo ""
146 usage_more_help
149 usage_more_help () {
150 echo "* press 'q' available patches or CTRL-c to quit the help menu *"
153 display_help () {
154 cd patches
155 echo ""
156 echo "AVAILABLE PATCHES"
157 echo ""
158 echo "*******************************************************************"
159 echo "Note: There are ONLY 4 ROMTYPES: [pa, cm, aokp, and aosp]."
160 echo ""
161 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
162 echo ""
163 echo "!!! Do not put Android Version number on command line !!!!"
164 echo "*****************************************************************"
165 echo "Specific auto_patcher script options"
166 echo " ./auto_patcher -h mods Lists mods"
167 echo " -h <MODNAME> Specific <MOD> info"
168 echo " -h advanced Advanced usage+lists all available patch dates"
169 echo ""
170 cleanup
171 exit
174 romtype_help () {
175 # From rom_error (bad romtype) and date_error (patch date w/o specifying romtype)
176 echo ""
177 echo "!!!There are only four supported ROMTYPES: 1) cm 2) aokp 3) aosp 4) pa"
178 echo ""
179 echo "Find out which of the above ROMTYPES your rom is based on and try again!"
180 echo "**********************************************"
181 echo ""
182 cleanup
183 brief_help
186 advanced_help () {
187 echo ""
188 echo "The Auto-Patcher Advanced Usage"
189 echo "*********************************"
190 echo ""
191 echo "For those of you determined to try everything..."
192 echo ""
193 echo "You can also try adding a patch date as a final argument."
194 echo ""
195 echo " ./auto_patcher <ROM> <MOD> <ROMTYPE> <DATE>"
196 echo ""
197 echo "Please note: There are only four ROMTYPES: {pa, aokp, aosp and cm}"
198 echo " -The various appellations after that are for internal use only!"
199 echo ""
200 echo "The Auto-Patcher has a pretty great rom probe, specifying the date is"
201 echo " deprecated...you don't need to, we promise."
202 echo ""
205 cleanup () {
206 [[ -n $ROOT ]] && \rm -rf "$ROOT"/tmp*
209 garbage () {
210 unset GARBAGE
211 GARBAGE=($(find $@ -name "*.orig")) && rm -rf ${GARBAGE[@]} && echo "GARBAGE= ${GARBAGE[@]}" >> "$LOG"
212 GARBAGE=($(find $@ -name "*.rej")) && rm -rf ${GARBAGE[@]} && echo "GARBAGE= ${GARBAGE[@]}" >> "$LOG"
216 print_error () {
217 # General purpose error. Used for errors in main, as opposed to probe or set-up.
218 echo ""
219 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
220 printtask "!!! error: $@"
221 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
222 echo ""
223 brief_help
226 smali_error () {
227 # Smali binary error. Problem often goes away on second run.
228 echo ""
229 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
230 printtask "!!! error: $@"
231 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
232 echo ""
233 if [[ `grep 'method index is too large' "$LOG"` != "" ]]; then
234 printtask "!!! Problem with method cap !!!"
235 printtask "... attempting fix ..."
236 . patches/.common/framework.jar.sh 2>&1 > ${JAR}.log
237 printtask "... rebuild framework.jar ..."
238 java -Xmx512M -jar smali.jar -a $API tmp/${FILE}.out/smali -o tmp/${FILE}.out/classes.dex >> "$LOG" 2>> "$LOG"
239 [ -f tmp/${FILE}.out/classes.dex ] || print_error "Could not resolve method cap issue- please submit log"
240 else
241 printtask "!!! This error is generally due to an unknown bug in the smali binary!"
242 echo "In our experience, it goes away if you run the patcher a second time."
243 echo " Please run the Auto-Patcher with the same command once again."
244 echo ""
245 echo "If after the third attempt the same thing happens,"
246 echo " please upload your logfile to our support thread!"
247 echo ""
248 cleanup
249 exit
253 mismatch_error () {
254 # Function that exposes attempts to apply a mod to an upsupported Android version
255 echo ""
256 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
257 printtask "!!! error: $@"
258 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
259 echo ""
260 cleanup
261 brief_help
264 date_error () {
265 # Remind users to include a romtype if they are going to specify a patch date
266 echo ""
267 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
268 printtask "!!! error: $@"
269 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
270 echo ""
271 echo "Please put a ROMTYPE before the patch date and run again!!"
272 romtype_help
275 rom_error () {
276 # For when an unsupported romtype is manually entered on the command-line
277 echo ""
278 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
279 printtask "!!! error: $@"
280 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
281 romtype_help
284 conflict_error () {
285 # For conflicting packages
286 echo ""
287 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
288 printtask "!!! error: $@"
289 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
290 cleanup
291 PID=mods
292 mods_info
295 misspatch_error () {
296 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
297 printtask "!! error: $@ "
298 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
299 echo ""
300 printtask "!! The Auto-Patcher could not find its patches and/or tools!"
301 echo ""
302 echo "* Did you run ./batch.sh first?"
303 echo ""
304 echo "The patch_patches.tgz and patch_tools.tgz need to be in this directory,"
305 echo " one way or another..."
306 echo ""
307 cleanup
308 brief_help
311 misstools_error () {
312 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
313 printtask "!! error: $@ "
314 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
315 printtask "Your set-up is missing a dependency."
316 echo "We require JDK, tar, patch and cpio."
317 echo ""
318 echo ""
319 echo "Each distro is different"
320 echo "but ensure you have them all installed and try again."
321 echo ""
322 cleanup
323 brief_help
326 printtask () {
327 echo "" >> "$LOG"
328 echo -e $@ | tee -a "$LOG"
331 copyfailed () {
332 echo ""
333 printtask "File for which patching failed:"
334 printtask "---------------------------------------------"
335 echo ""
336 printtask "${FAIL##*/}"
337 echo ""
338 echo "---------------------------------------------"
339 echo ""
340 echo "We can try to add a premade copy of those files."
341 echo "This sometimes works."
342 echo ""
343 printtask "You only need to report this if running the program gives you problems!!!"
344 echo ""
345 echo ""
346 askconsent && return 0 || return 1
349 askconsent () {
350 sleep 1
351 echo -n "Do you want to proceed ? (YES/no) "
352 read PROCEED
353 echo "askconsent final = ${PROCEED}: for $FAIL" >> "$LOG"
354 case $PROCEED in
355 [Yy] | [Yy][Ee][Ss])
356 return 0; # successful:
357 echo "*** You (or ApG) have elected to use a prepatched copy of $FAIL ***" >> "$LOG"
360 return 1; # error
361 echo "*** You have declined to insert $FAIL by not answering 'yes' at the prompt. ***" >> "$LOG"
363 esac
366 replace_updater () {
368 # Function for devices that use SDcard installs. Also to be tested for CM7
369 # since CM7 seems to use an updater-script that wipes EMMC. Testing
371 \rm $UPDATER_LOC/$UPDS
372 \cp patches/.common/$UPDATER_LOC/$UPDS $UPDATER_LOC
373 echo "run_program(\"/sbin/busybox\", \"umount\", \"/system\");" >> UPDATE.txt
374 cat UPDATE.txt >> $UPDATER_LOC/$UPDS
375 echo ""
376 echo "New updater-script being used:" >> "$LOG"
377 echo "-----------------------------" >> "$LOG"
378 cat $UPDATER_LOC/$UPDS >> "$LOG"
381 abspath () {
382 case `uname -s` in
383 CYGWIN*)
384 echo $(cygpath -ua "$1") | sed 's:/$::g'
386 Darwin)
387 #[[ $(echo $1 | awk '/^\//') == $1 ]] && echo "$1" || echo "$PWD/$1"
388 [[ ${1:0:1} == "/" ]] && echo "$1" || echo "$PWD/$1"
390 Linux)
391 echo $(readlink -f "$1")
394 if [[ ${1:0:1} == "/" ]]; then
395 echo "$1"
396 elif [[ ${1:0:2} == "./" ]]; then
397 echo "$PWD/${1:2}"
398 else
399 echo "$PWD/$1"
402 esac
405 mods_display () {
406 echo ""
407 echo "The Auto-Patcher $VERSION"
408 echo "*******************************"
409 echo ""
410 echo "The available mods are"
411 echo "****************************************************"
412 echo "* pdroid openpdroid voice v6supercharger *"
413 echo "* voice insecure secure external_internal *"
414 echo "* tabletUI 3gdongle pd2.0 *"
415 echo "****************************************************"
416 echo ""
417 echo "To find out more about any mod, simply enter:"
418 echo " ./auto_patcher -h <MODNAME>"
419 echo ""
420 cleanup
423 mods_info () {
424 # Defaults
425 DEPENDENCY="None"
426 DEV="Unknown"
427 CEILING=$CURRENT_ANDROID
428 ROM_CONFLICTS="None"
429 case $PID in
430 mods)
431 mods_display
432 exit
434 auto*)
435 echo ""
436 echo "**************************************"
437 echo "The Auto-Patcher ate a kitten once..."
438 echo "**************************************"
439 echo ""
440 printusage_help
442 advanced)
443 cd patches/
444 (advanced_help && find -H * -name 201*) | more -d
445 echo ""
446 brief_help
448 voice)
449 FLOOR=4.0.0
450 DESC="Use on wifi-only tablets to have the software register as 'voice-enabled'. Allows VOIP like Google Voice to function."
451 DESC="bongostl's setup method here: http://forum.xda-developers.com/showthread.php?t=1823701"
452 DEV="bongostl"
455 v6supercharger)
456 FLOOR=4.0.0
457 CEILING=4.2.1
458 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."
459 DEV="Zeppelinrox"
460 DEPENDENCY="The V6 Supercharger Script. Get it at http://forum.xda-developers.com/showthread.php?t=991276/"
462 pdroid)
463 FLOOR=2.3.7
464 CEILING=4.1.2
465 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)."
466 DEV="Svyat"
467 DEPENDENCY="The Pdroid app. You can get it at http://forum.xda-developers.com/showthread.php?t=1923576"
469 pd2.0)
470 FLOOR=4.1.2
471 CEILING=4.1.2
472 DESC="An expansion of the PDroid application/framework."
473 DEV="CollegeDev"
474 DEPENDENCY="The free PDroid2.0 app available at http://forum.xda-developers.com/showthread.php?t=1923576"
476 openpdroid)
477 FLOOR=4.1.2
478 CEILING=4.2.1
479 DESC="A fork of the open-source PDroid and Pdroid2.0 framework."
480 DEV="FFU5y/wbedard/mateorod/Community"
481 DEPENDENCY="The PDroidManager app freely available from Google Play or http://forum.xda-developers.com/showthread.php?t=1994860"
483 opendroid)
484 echo ""
485 echo "No mod named 'opendroid'. You probably mean 'openpdroid'. Try again."
486 PID="mods"
487 mods_info
489 external_internal)
490 FLOOR=2.3.3
491 DESC="Swap internal and external storage."
493 insecure)
494 FLOOR=2.3.3
495 DESC="Make any boot.img insecure and allow remount as well as adb push/pull of system files. True root."
497 secure)
498 FLOOR=2.3.3
499 DESC="Make any boot.img secure."
501 3gdongle)
502 FLOOR=4.1.0
503 CEILING=4.2.1
504 DESC="Allows 3gdongles to work on wifi tablets w/o 3rd party applications."
505 DEV="trevd"
506 DEPENDENCY="None, but read the troubleshooting guide at http://forum.xda-developers.com/showthread.php?t=1798631"
508 tabletUI)
509 FLOOR=4.1.0
510 CEILING=4.2.1
511 ROM_CONFLICTS=(pa .aosp-slim)
512 DESC="Changes the user interface of Phones and Phablets to the popular Tablet UI."
513 DEV="barmullio"
516 FLOOR=?????
517 CEILING=?????
518 DESC="??? Unknown modtype ??? Check your spelling or the mod list!"
519 #DESC1="./auto_patcher -h mods"
520 esac
521 # strip decimals from android version (i.e. 2.3.7 becomes 237) so we can do math
522 NVID=${VID//[.]/}
523 COMPATF=${FLOOR//[.]/}
524 COMPATC=${CEILING//[.]/}
527 apk_check () {
528 if [ -f patches/$P/$A/$R/$B/$FILE ]; then
529 echo "... Patching $APK failed, but we will copy over a prepatched file ..."
530 \cp -av patches/$P/$A/$R/$B/$FILE $FILE >> "$LOG"
531 else
532 print_error "failed patching $APK!!!"
536 compat_check () {
537 for P in ${PID[@]}; do
538 mods_info
539 if [[ "$NVID" -lt "$COMPATF" ]]; then
540 mismatch_error "Your Android $VID rom is too old! The minimum for $P is \n !!! Android $FLOOR!"
542 if [[ "$NVID" -gt "$COMPATC" ]]; then
543 mismatch_error "Sorry, $P has not been made available for Android $VID yet!"
545 done
548 rom_compat_check () {
549 for P in ${PID[@]}; do
550 N=${#ROM_CONFLICTS[@]}
551 for ((i=0; i < $N; i++)); do
552 if [[ $RID == ${ROM_CONFLICTS[$i]} ]]; then
553 rom_compat_error
555 done
556 done
559 rom_compat_error () {
560 print_error "$RID is incompatible with $PID!!!"
563 extpath () {
564 case `uname -s` in
565 CYGWIN*)
566 echo $(cygpath -da "$1")
569 echo $(abspath "$1")
571 esac
574 #contains () { for e in "${@:2}"; do [[ "$e" = "$1" ]] && return 0; done; return 1; }
576 parse () { echo "${1%%_*}"; }
578 getbuildprop () {
579 if [ -f system/build.prop ]; then
580 result=(`grep $1 system/build.prop | tr -d '\r' | tr '=' ' '`)
581 echo "${result[1]}"
582 else
583 echo ""
588 aosp_mod_check() {
589 jar -xvf "$ROMX" system/framework/framework2.jar >> $LOG
590 if [ -s system/framework/framework2.jar ]; then
591 ever_check
592 else
593 AOSP=aosp
595 echo $AOSP
598 ever_check() {
599 MID=$(getbuildprop ro.build.romversion)
600 if [[ $MID == "Evervolv"* ]]; then
601 AOSP=".aosp-ever"
602 else
603 MID=$(getbuildprop ro.build.display.id)
604 if [[ "$MID" == "ev"* ]]; then
605 AOSP=".aosp-ever"
606 else
607 slim_check
610 echo $AOSP
613 slim_check() {
614 SLMID=$(getbuildprop ro.modversion)
615 SLMMID=$(getbuildprop updateme.name)
616 if [[ "$SLMMID" == "Slim"* ]] || [[ $SLMMID == "slim"* ]]; then
617 AOSP=".aosp-slim"
618 elif [[ "$SLMID" == "Slim"* ]] || [[ $SLMID == "slim"* ]]; then
619 AOSP=".aosp-slim"
620 else
621 if [[ "$ANDR" == "4.1" ]]; then
622 AOSP=.aosp-mod
623 else
624 AOSP="aosp"
629 pa_check() {
630 CMID=$(getbuildprop ro.modversion)
631 PAID=$(getbuildprop ro.pa.version)
632 MID=$(getbuildprop ro.build.display.id)
633 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
634 DID=$(getbuildprop ro.product.device)
635 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
636 if [[ -n $PAID ]]; then
637 RID=pa
638 else
639 case $CMID in
640 [Pp][Aa]*)
641 RID=pa;
644 RID=cm;
646 esac
650 romtype_set () {
651 case $RID in
653 ROMTYPE="cm"
655 aokp*)
656 ROMTYPE="aokp"
659 ROMTYPE="pa"
662 ROMTYPE="aosp"
664 esac
667 proberom () {
668 VID=$(getbuildprop ro.build.version.release)
669 if [ ${#VID} -lt 4 ]; then # in case of non-standard versioning in build.prop (defy!)
670 ANDR=$VID
671 else
672 ANDR="${VID%.*}" # Cut to 1 significant digit to cover specific range or release.
674 if [ "$ANDR" == "2.3" ]; then
675 FLAVR=gingerbread
676 API=10
677 RID=cm;
678 elif [ "$ANDR" == "4.0" ]; then
679 FLAVR=ics
680 API=15
681 MID=$(getbuildprop ro.rommanager.developerid)
682 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.modversion))
683 DID=$(getbuildprop ro.product.device)
684 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
686 case "$MID" in
687 pa|cm9|cm|cyanogenmod*)
688 RID=cm;
690 aokp|teamkang)
691 RID=aokp;
693 aosp*)
694 RID=aosp;
697 echo "!!! $MID is not supported yet, trying aosp !!!"
698 RID=aosp
700 esac
701 elif [ "$ANDR" == "4.1" ]; then
702 FLAVR=jellybean
703 API=16
704 CMID=$(getbuildprop ro.cm.version)
705 if [[ -n $CMID ]]; then
706 pa_check
707 else
708 MID=$(getbuildprop ro.build.display.id)
709 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
710 DID=$(getbuildprop ro.product.device)
711 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
712 case "$MID" in
713 cm10|cm*|cyanogenmod*)
714 RID=cm;
716 aokp*|teamkang)
717 RID=aokp;
719 pa*)
720 RID=pa;
722 ev*)
723 RID=".aosp-ever";
726 RID=`aosp_mod_check`;
728 esac
730 elif [ "$ANDR" == "4.2" ]; then
731 FLAVR=jellybean
732 API=17
733 CMID=$(getbuildprop ro.cm.version)
734 MID=$(getbuildprop ro.build.display.id)
735 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
736 DID=$(getbuildprop ro.product.device)
737 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
739 case "$MID" in
740 cm10|cm*|cyanogenmod*)
741 RID=cm;
743 aokp*|teamkang)
744 RID=aokp;
746 pa*)
747 RID=pa;
749 ev*|Ever*)
750 RID=".aosp-ever";
753 RID=`ever_check`;
755 esac
756 else
757 print_error "unknown ROM version $VID"
759 romtype_set
760 echo "... result of ROM check: version= $VID rom= $ROMTYPE ..."
764 # Advanced build date query
765 # This should set the patch date automatically.
767 build_query() {
768 UTC=$(getbuildprop ro.build.date.utc)
770 # Difference in how OS X and Linux/Cygwin handles 'date' utility
771 case `uname -s` in
772 [Dd]arwin)
773 BDID=`date -r $UTC +%Y%m%d`
774 echo "#### Darwin Build Query used ####" >> "$LOG"
777 BDID=`date -d "1970-01-01 UTC $UTC seconds" +"%Y%m%d"`
778 echo "#### Standard Build Query ####" >> "$LOG"
780 esac
782 # If patch date is specified on CLI, use that patch date
783 if [ $# -gt 3 ]; then
784 BID=${4//,/ };
785 BDID=$BID
786 else
787 case $ANDR in
788 2.3)
789 # CM7 roms do not have UTC time stamp- so no build query.
790 BID=latest;
791 echo "*** CM7 roms default to latest patches. If using an older rom ***"
792 echo "*** specify patch date on command line. Use -h to see available patches ***"
795 for P in ${PID[@]}; do
796 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
797 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
798 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
799 PAR=patches/$P/$A/$R
800 PARB=patches/$P/$A/$R/$B
801 DATES=`ls patches/$P/$A/$R/ | grep '201*'`
802 # Intialize variable - High so as to determine lowest in first loop.
803 BID=20201231
804 # find earliest available patch date
805 for i in $DATES; do
806 if [[ $i -lt $BID ]]; then
807 BID=$i
809 done
810 # Check if earliest patches are from before build date. Else use earliest
812 # If older than earliest patch set, then find best match
813 if [[ $(($BID-$BDID)) -lt 0 ]]; then
814 for g in $DATES; do
815 # use any patch that matches $UTC
816 if [[ $(($BDID-$g)) -eq 0 ]]; then
817 BID=$g
818 break
819 # Set highest $BID w/o going over $UTC
820 elif [[ $(($BDID-$g)) -gt 0 ]] && [[ $g -gt $BID ]]; then
821 BID=$g
823 done
825 echo "... $PID patch date has been set to: $BID ..."
826 B=$BID
827 break
828 done
830 esac
834 proberil () {
835 RIL=$(getbuildprop ro.telephony.ril_class)
836 [[ -n $RIL ]] && printtask "... result of ROM check: RIL= $RIL"
839 rominfo () {
840 echo "# VER= $VERSION" >> "$LOG"
841 echo "# OS= $OSTYPE ${BIT}bit" >> "$LOG"
842 echo "# VID= $VID" >> "$LOG"
843 echo "# PID= ${PID[@]}" >> "$LOG"
844 echo "# MID= $MID" >> "$LOG"
845 echo "# RID= $RID" >> "$LOG"
846 echo "# ANDR= $ANDR" >> "$LOG"
847 echo "# BDID= $BDID" >> "$LOG"
848 echo "# DID= $DID" >> "$LOG"
849 echo "# BID= $BID" >> "$LOG"
850 echo "Patches are $PID/$ANDR/$RID/$BID" >> "$LOG"
854 if [[ $1 == -h ]]; then
855 if [ $# -gt 1 ]; then
856 PID=$2
857 mods_info
858 echo ""
859 echo "The Auto-Patcher $VERSION by Mateorod and Pastime1971"
860 echo "*************************************************"
861 echo ""
862 echo "Mod Name: $PID"
863 echo ""
864 echo " $DESC"
865 if [[ -z $DESC1 ]]; then # test to see is there is a second DESC line
866 echo "$DESC1"
868 if [[ $((DESC2)) -gt 0 ]]; then
869 echo "$DESC2"
871 echo ""
872 echo "Developer: $DEV"
873 echo "Dependancies: $DEPENDENCY"
874 echo ""
875 echo "Works on ROMs from Android $FLOOR -> $CEILING"
876 echo
877 brief_help
878 exit
882 [[ $# -lt 1 || -z $1 ]] && PID="mods" && mods_info
883 [[ $1 == "-h" ]] && usage_help | less && display_help
885 echo ""
886 echo "The Auto-Patcher $VERSION"
887 echo ""
888 # by pastime1971 and mateorod
890 ROOT=$(abspath `dirname "$0"`)
891 TOOL="$ROOT/patch_tools.tgz"
892 PTCH="$ROOT/patch_patches.tgz"
893 cleanup
894 # set temporaray directory
895 DATE=`date +%Y%m%d%H%M%S`
896 TEMP=$ROOT/tmp$DATE
897 TMP=$ROOT/tmp$DATE
898 TMPDIR=$ROOT/tmp$DATE
899 mkdir "$TEMP"
900 ROM=$(abspath "$1")
901 ROMX=$(extpath "$1")
903 if [[ $OSTYPE == "cygwin" ]]; then
904 EXE=".exe"
905 PGFORM="0x"
908 LOG=$(abspath ./log$DATE.txt)
909 #echo $ROOT $TOOL $ROM $TEMP "$LOG"
910 echo "ROOT= $ROOT" >> "$LOG"
911 echo "TOOL= $TOOL" >> "$LOG"
912 echo "ROM= $ROM" >> "$LOG"
913 echo "ROMX= $ROMX" >> "$LOG"
915 \rm -f $RESTORE.zip $UPDATE.zip
917 CHK=$(getconf LONG_BIT)
918 if [[ $CHK = "64" ]]; then
919 BIT=64
920 else [[ $BIT = "32" ]];
921 BIT=32
925 printtask "### verify tools ###"
926 which patch >> "$LOG" || misstools_error "Missing \"patch\" utility."
927 which tar >> "$LOG" || misstools_error "Missing \"tar\" utility"
928 which jar >> "$LOG" || misstools_error "Missing \"Java Development Kit\" (JDK)"
929 which java >> "$LOG" || misstools_error "Missing \"Java Development Kit\" (JDK)"
930 which cpio >> "$LOG" || misstools_error "Missing \"cpio\" utility"
931 [ -f "$TOOL" ] || misspatch_error "patch_tool.tgz is missing"
932 [ -f "$PTCH" ] || misspatch_error "patch_patches.tgz is missing"
933 printtask "### verify ROM ###"
934 [ -f "$ROM" ] || print_error "Cannot find $1!! Make sure you have the location and name right"
935 echo "### running $0 $@" >> "$LOG"
936 cd "$TEMP"
938 PATH="$TEMP:$PATH"
939 export PATH
940 echo "PATH= $PATH" >> "$LOG"
942 printtask "### unzip patch tools ###"
943 tar xzf "$TOOL" > /dev/null || print_error "failed extracting tools !!!"
945 # Get OS specific tools
946 case `uname -s` in
947 CYGWIN*)
948 \mv cygwin/aapt.exe .
949 \mv cygwin/*.exe boot/
950 \rm -rf cygwin # why? If you want to we can keep/add it to mac/linux, though.
952 [Dd]arwin)
953 \mv mac/aapt .
955 [Ll]inux)
956 \mv linux/aapt .
959 \mv linux/aapt .
961 esac
962 # Ensure aapt permissions - possibly to one day be expanded to all tools in a function.
963 chmod a+x aapt$EXE
965 printtask "### unzip patch patches ###"
966 tar xzf "$PTCH" > /dev/null || print_error "failed extracting patches !!!"
968 # we need build.prop for both RIL probing and ROM probing
969 jar -xvf "$ROMX" system/build.prop 2>> "$LOG" || print_error "failed extracting build.prop from $ROMX !!!"
971 # rom + ril type
972 proberil
973 printtask "### probe rom type ###"
974 proberom
976 # rom type
977 if [ $# -gt 1 ]; then
978 PIT=$2
979 if [[ "$PIT" = "-h" ]]; then
980 display_help
983 if [ $# -gt 2 ]; then
984 RID=$3
985 case "$RID" in
986 cm10|cm*|cyanogenmod*)
988 aokp*|teamkang)
989 RID=aokp;
991 pa*)
992 RID=pa;
994 .aosp-ever)
995 RID=".aosp-ever";
997 .aosp-slim)
998 RID=".aosp-slim"
1000 aosp*)
1001 case "ANDR" in
1002 4.1)
1003 RID=`aosp_mod_check`;
1006 RID=`ever_check`
1008 esac
1010 201*)
1011 date_error "You must specify ROMTYPE if designating a patch date!!"
1014 rom_error "$RID is not a valid ROMTYPE!!"
1016 esac
1017 romtype_set
1018 echo "... Using $ROMTYPE patches ..."
1019 else
1020 echo "... Using results of ROM check ..."
1023 # patch type
1024 if [ $# -gt 1 ]; then
1025 PIL=${2//,/ } # If more than one mod, make string separated by spaces
1026 else
1027 PIL="openpdroid"
1028 echo "No mods selected. Defaulting to openpdroid, since that's what you probably want..."
1031 # Ensure only 1 Pdroid mod at a time; PDroid first, so provisional use
1032 # does not overwrite other mods...
1034 PID=(${PIL// / }) # turn string of requested mods into array
1035 COPYPID=("${PID[@]}") # working copy to iterate over
1036 MODS_NUMBER=${#COPYPID[@]} # number of elements (mods)
1038 if [[ $MODS_NUMBER > 1 ]]; then # cause if only one mod, no point
1039 INDEX=0 # 'pd2.0' didn't work with unset; regex barred multiple 'pdroid'
1040 for p in ${COPYPID[@]}; do
1041 if [ "$p" = "pdroid" ] || [ "$p" = "pd2.0" ] ||[ "$p" = "openpdroid" ]; then
1042 SPID[0]=$p #set pdroid first
1043 unset COPYPID["$INDEX"]
1044 break
1045 else
1046 INDEX=$((INDEX + 1)) # if !pdroid, set as 1, 2...
1048 done
1049 for p in ${COPYPID[@]}; do
1050 if [ "$p" = "pdroid" ] || [ $p = "pd2.0" ] ||[ $p = "openpdroid" ]; then
1051 conflict_error "Those mods conflict! Only one pdroid mod at a time!"
1052 else
1053 i=${#SPID[@]}
1054 SPID[i]=$p
1055 i+=1
1057 done
1058 else
1059 SPID=${COPYPID[@]}
1061 for P in ${PIL[@]}; do
1062 [[ ${PID[@]} =~ $P ]] || PID=(${PID[@]} $P)
1063 done
1065 # Check if selected mods are available for rom's Android version.
1066 compat_check
1068 # Make sure mod and rom don't conflict (e.g. pa and tabletUI)
1069 if [[ $ROM_CONFLICTS != "None" ]]; then
1070 rom_compat_check
1073 # Build date
1074 if [ $# -gt 3 ]; then # if a date is specified on command line...
1076 # Set date to match argument and ensure that patches with that date exist
1077 BID=$4
1078 [ -d patches/$P/$ANDR/$RID/$BID ] || print_error "No $P patches for $RID on $BID!! Try the help menu!!"
1080 # Run build_query- this overrides the above but gets useful info
1081 build_query
1082 # Reset patch date to argument
1083 BID=$4
1084 echo "... $PID patch date set manually to: $BID ..."
1085 else
1086 build_query # if no date specified, use one from build_query
1089 # echo ROM info
1090 rominfo
1092 if [[ ( "$PID" == "-h" || "$RID" == "-h" || "$BID" == "-h" ) ]]; then
1093 #Although this placement may be perfect for romfilter. although it throws the scheme...
1094 display_help
1096 #Begin cycle
1098 for P in ${PID[@]}; do
1099 [ -d patches/$P ] || print_error "$P is not available"
1100 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1101 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1102 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1104 unset FILES
1105 [ -f patches/$P/files.txt ] && FILES=$(cat patches/$P/files.txt)
1106 [ -f patches/$P/$A/files.txt ] && FILES=$(cat patches/$P/$A/files.txt)
1107 [ -f patches/$P/$A/$R/files.txt ] && FILES=$(cat patches/$P/$A/$R/files.txt)
1108 [ -f patches/$P/$A/$R/$B/files.txt ] && FILES=$(cat patches/$P/$A/$R/$B/files.txt)
1109 for FILE in ${FILES[@]}; do
1110 case "$FILE" in
1111 +system/*)
1112 [[ ${CID[@]} =~ ${FILE:1} ]] && print_error "${FILE:1} is already being copied" || CID=(${CID[@]} ${FILE:1})
1114 -system/*)
1115 [[ ${EID[@]} =~ ${FILE:1} ]] || EID=(${EID[@]} ${FILE:1})
1117 system/*.jar)
1118 [[ ${JID[@]} =~ $FILE ]] || JID=(${JID[@]} $FILE)
1119 echo "set_perm(0, 0, 0644, \"/$FILE\");" >> UPDATE.txt
1121 ~system/*apk) # apps to decompile with smali instead of apktool
1122 [[ ${JID[@]} =~ ${FILE:1} ]] || JID=(${JID[@]} ${FILE:1})
1123 echo "set_perm(0, 0, 0644, \"/$FILE\");" >> UPDATE.txt
1125 system/*.apk)
1126 [[ ${AID[@]} =~ $FILE ]] || AID=(${AID[@]} $FILE)
1127 echo "set_perm(0, 0, 0644, \"/$FILE\");" >> UPDATE.txt
1129 *.img)
1130 [[ ${IID[@]} =~ $FILE ]] || IID=(${IID[@]} $FILE)
1132 system/*)
1133 [[ ${TID[@]} =~ $FILE ]] || TID=(${TID[@]} $FILE)
1135 esac
1136 done
1137 done
1138 echo "### DELETE FILES= ${EID[@]}" >> "$LOG"
1139 echo "### COPY FILES= ${CID[@]}" >> "$LOG"
1140 echo "### JAR FILES= ${JID[@]}" >> "$LOG"
1141 echo "### APK FILES= ${AID[@]}" >> "$LOG"
1142 echo "### IMG FILES= ${IID[@]}" >> "$LOG"
1143 echo "### TXT FILES= ${TID[@]}" >> "$LOG"
1145 # extract system files
1146 printtask "### unzip rom ###"
1147 jar -xvf "$ROMX" ${JID[@]} ${AID[@]} ${IID[@]} ${TID[@]} 2>> "$LOG" || print_error "failed extracting ${JID[@]} ${AID[@]} ${IID[@]} from $ROMX !!!"
1150 # Update/Restore.zip scripts and prep
1151 printtask "### create updater script ###"
1152 UPDATER_LOC=META-INF/com/google/android
1153 UPDS=updater-script
1154 UPDATE="update-$ROMTYPE-$DID-$BDID-${PIL// /-}"
1155 RESTORE="restore-$ROMTYPE-$DID-$BDID"
1157 jar -xvf "$ROMX" $UPDATER_LOC/$UPDS $UPDATER_LOC/update-binary
1158 jar -xvf "$ROMX" $UPDATER_LOC/update-binary-installer 1> /dev/null 2> /dev/null
1160 # Determine Installer- Aroma or ClockworkMod
1161 if [ -f $UPDATER_LOC/update-binary-installer ]; then
1162 printtask "... using Aroma installer ..."
1163 \mv $UPDATER_LOC/update-binary-installer $UPDATER_LOC/update-binary
1164 else
1165 printtask "... using Clockworkmod installer ..."
1168 # Create updater scripts
1169 cat patches/.common/updater-message.txt >> $UPDS
1170 cat $UPDATER_LOC/$UPDS | grep ^mount | grep "/system" | head -n 1 >> $UPDS
1171 [ -s $UPDS ] || echo "run_program(\"/sbin/busybox\", \"mount\", \"/system\");" >> $UPDS
1172 # restore the original
1173 for FILE in ${EID[@]}; do
1174 jar -xvf "$ROMX" $FILE 2> /dev/null || printtask "!!! warning $FILE cannot be restored !!!"
1175 done
1176 # replace with the original or delete it
1177 for FILE in ${CID[@]}; do
1178 jar -xvf "$ROMX" $FILE 2> /dev/null || echo "delete(\"/$FILE\");" >> $UPDS
1179 done
1180 echo "package_extract_dir(\"system\", \"/system\");" >> $UPDS
1181 # permission management for files that need specific perms
1182 cat $UPDATER_LOC/$UPDS | grep set_perm | grep "/system" >> $UPDS
1183 for P in ${PID[@]}; do
1184 if [ -s patches/$P/$A/set_perm.txt ]; then
1185 echo "...setting permissions..."
1186 cat patches/$P/$A/set_perm.txt >> $UPDS
1188 done
1189 cat $UPDATER_LOC/$UPDS | grep ^unmount | grep "/system" | head -n 1 >> $UPDS
1190 [[ ${IID[@]} =~ boot.img ]] && cat $UPDATER_LOC/$UPDS | grep "boot.img" >> $UPDS
1191 echo "ui_print(\" .\");" >> $UPDS
1192 echo "ui_print(\" .\");" >> $UPDS
1193 echo "ui_print(\" done!\");" >> $UPDS
1194 cat $UPDS > $UPDATER_LOC/$UPDS
1195 echo "# generated $UPDS" >> "$LOG"
1196 cat $UPDS >> "$LOG"
1198 printtask "### create restore.zip ###"
1199 jar -cvf tmp.zip ${JID[@]} ${AID[@]} ${IID[@]} META-INF > /dev/null 2>> "$LOG"
1200 java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip signed.zip 2>> "$LOG"
1201 \mv signed.zip $RESTORE.zip
1202 \rm -f tmp.zip
1205 # Begin patching process
1207 # decompile system files
1208 printtask "### decompile system files ###"
1209 for FILE in ${JID[@]}; do
1210 JAR=${FILE##*/}
1211 printtask "... decompile $JAR ..."
1212 java -jar baksmali.jar -b -a $API -o tmp/${FILE}.out/smali ${FILE} >> "$LOG" 2>> "$LOG"
1213 if [ $FILE == "system/framework/framework.jar" ]; then
1214 printtask "... extract preloaded-classes ..."
1215 jar -xvf ${FILE} preloaded-classes >> "$LOG" 2>> "$LOG"
1216 \mv preloaded-classes tmp/${FILE}.out/
1218 done
1220 # install framework-files for APK...
1221 if [ ${#AID[@]} -gt 0 ]; then
1222 jar -xvf "$ROMX" system/framework/framework-res.apk >> "$LOG"
1223 printtask "... installing framework files ..."
1224 java -jar apktool.jar if system/framework/framework-res.apk
1225 # Decompile APKs
1226 for FILE in ${AID[@]}; do
1227 APK=${FILE##*/}
1228 if [ -f $FILE ]; then
1229 printtask "... decompile $APK ..."
1230 java -jar apktool.jar d -f $FILE tmp/$FILE.out
1232 done
1235 # Unpack image files {boot.img only so far...}
1236 for FILE in ${IID[@]}; do
1237 printtask "### unpacking $FILE ###"
1238 case "$FILE" in
1239 boot.img)
1240 if [ -f boot.img ]; then
1241 cd boot
1242 ./unpackbootimg$EXE -i ../boot.img >> "$LOG" 2>> "$LOG"
1243 mkdir ramdisk
1244 cd ramdisk
1245 gzip -dc ../boot.img-ramdisk.gz | cpio -i >> "$LOG" 2>> "$LOG"
1246 cd ../../
1247 else
1248 print_error "A mod needs to patch boot.img! This rom does not contains boot.img."
1252 print_error "cannot process $FILE"
1254 esac
1255 done
1257 # apply system modification
1259 for P in ${PID[@]}; do
1260 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1261 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1262 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1263 PAR=patches/$P/$A/$R
1264 PARB=patches/$P/$A/$R/$B
1266 unset FILES COPY DELS JARS APKS IMGS TXTS
1267 [ -f patches/$P/files.txt ] && FILES=$(cat patches/$P/files.txt)
1268 [ -f patches/$P/$A/files.txt ] && FILES=$(cat patches/$P/$A/files.txt)
1269 [ -f patches/$P/$A/$R/files.txt ] && FILES=$(cat patches/$P/$A/$R/files.txt)
1270 [ -f patches/$P/$A/$R/$B/files.txt ] && FILES=$(cat patches/$P/$A/$R/$B/files.txt)
1271 for FILE in ${FILES[@]}; do
1272 case $FILE in
1273 +system/*)
1274 COPY=(${COPY[@]} ${FILE:1})
1276 -system/*)
1277 DELS=(${DELS[@]} ${FILE:1})
1279 system/*.jar)
1280 JARS=(${JARS[@]} $FILE)
1282 ~system/*)
1283 JARS=(${JARS[@]} ${FILE:1})
1285 system/*.apk)
1286 APKS=(${APKS[@]} $FILE)
1288 *.img)
1289 IMGS=(${IMGS[@]} $FILE)
1291 system/*)
1292 TXTS=(${TXTS[@]} $FILE)
1294 esac
1295 done
1297 [[ -n ${COPY[@]} ]] && echo "### copy patch $P/$A/$ROMTYPE/$B ###"
1298 echo "### copy patch $P/$A/$R/$B ###" >> "$LOG"
1299 for FILE in ${COPY[@]}; do
1300 printtask "... copying $FILE ..."
1301 DEST=${FILE%/*}
1302 mkdir -p ./$DEST
1303 if [ -e patches/$P/$A/$R/$B/$FILE ]; then
1304 [ -e $FILE ] && printtask "... overwriting $FILE from $P ..."
1305 \cp -av patches/$P/$A/$R/$B/$FILE ./$DEST >> "$LOG"
1306 else
1307 print_error "$FILE is missing in the patch. Please upload your logfile to the support thread!"
1309 done
1311 # unconditional smali copying- For particularly troublesome files
1312 [ -f patches/$P/smali.txt ] && SMALI=$(cat patches/$P/smali.txt)
1313 [ -f patches/$P/$A/smali.txt ] && SMALI=$(cat patches/$P/$A/smali.txt)
1314 [ -f patches/$P/$A/$R/smali.txt ] && SMALI=$(cat patches/$P/$A/$R/smali.txt)
1315 [ -f patches/$P/$A/$R/$B/smali.txt ] && SMALI=$(cat patches/$P/$A/$R/$B/smali.txt)
1316 MOVE=${SMALI##*/}
1317 for SMALI in ${SMALI[@]}; do
1318 if [ -f patches/$P/$A/$R/.provisionals/$SMALI ]; then
1319 printtask "... overwriting $MOVE ..."
1320 \cp -a patches/$P/$ANDR/$R/.provisionals/$SMALI tmp/$SMALI >> "$LOG"
1321 elif [ -f patches/$P/$A/.provisionals/$SMALI ]; then
1322 printtask "... overwriting $MOVE ..."
1323 \cp -a patches/$P/$ANDR/.provisionals/$SMALI tmp/$SMALI >> "$LOG"
1325 done
1327 [[ -n ${DELS[@]} ]] && echo "### delete patch $P/$A/$ROMTYPE/$B ###"
1328 echo "### delete patch $P/$A/$R/$B ###" >> "$LOG"
1329 for FILE in ${DELS[@]}; do
1330 printtask "... deleting $FILE ..."
1331 \rm -rf ./$FILE
1332 done
1333 [[ -n ${JARS[@]} ]] && echo "### jar patch $P/$A/$ROMTYPE/$B ###"
1334 echo "### jar patch $P/$A/$R/$B ###" >> "$LOG"
1335 for FILE in ${JARS[@]}; do
1336 JAR=${FILE##*/}
1337 if [[ $FILE == *".jar" ]]; then # allows for *.apks to be decompiled by baksmali
1338 NAME=${JAR%.jar}
1339 else
1340 NAME=$JAR # TODO: Maybe rename this, since it now encompases apks at times
1342 printtask "... apply $NAME.patch ..."
1343 patch -Nls -p1 -d tmp/${FILE}.out < $PARB/${NAME}.patch 2>&1 > ${JAR}.log
1344 cat ${JAR}.log | tee -a "$LOG"
1345 case "$NAME" in
1346 framework)
1347 # patch preloaded-classes only if a patch exists
1348 if [ -f $PARB/preloaded.patch ]; then
1349 printtask "... apply preloaded.patch ..."
1350 patch -Nls -p1 -d tmp/${FILE}.out < $PARB/preloaded.patch 2>&1 > preloaded.log
1351 cat preloaded.log | tee -a "$LOG"
1352 [[ `grep FAILED preloaded.log` != "" ]] && print_error "failed preloaded.patch"
1356 echo -n "" # do nothing else
1358 esac
1359 # substitute failed smali with provisional (a prepatched smali file)
1360 unset FAILS
1361 FAILS=(`grep FAILED ${JAR}.log | sed -e 's/.*smali\///' | sed -e 's/\.rej//'`)
1362 if [[ -n ${FAILS[@]} ]]; then
1363 printtask "!!! PATCHING FAILED FOR ${FAILS[@]} !!!"
1364 echo "### replace ${FAILS[@]} ###" > ${JAR}.log
1365 for FAIL in ${FAILS[@]}; do
1366 PROVISIONAL="patches/$P/$ANDR/.provisionals/${FILE}.out/smali/${FAIL}"
1367 echo "!!! patch error for $FAIL !!!" >> "$LOG"
1368 #cat tmp/$FILE.out/smali/${FAIL}.rej >> "$LOG" # FOR DEBUGGING
1369 [[ ${SID[@]} =~ $FAIL ]] && print_error "$FAIL was already replaced before"
1370 [ -f "$PROVISIONAL" ] || print_error "failed $FAIL in $JAR cannot be remedied"
1371 copyfailed
1372 printtask "... replace $FAIL ..."
1373 \rm -rf tmp/${FILE}.out/smali/${FAIL} tmp/${FILE}.out/smali/${FAIL}.orig tmp/${FILE}.out/smali/${FAIL}.rej
1374 \cp -av "$PROVISIONAL" tmp/${FILE}.out/smali/${FAIL} >> "$LOG"
1375 SID=(${SID[@]} $FAIL)
1376 done
1378 [[ `grep FAILED ${JAR}.log` != "" ]] && print_error "failed $NAME.patch"
1379 garbage tmp/${FILE}.out
1381 # run special $JAR.sh scripts if any JAR needs special attention
1382 if [ -f patches/$P/$A/$R/$B/${JAR}.sh ]; then
1383 printtask "... apply $JAR.sh ..."
1384 . patches/$P/$A/$R/$B/${JAR}.sh 2>&1 > ${JAR}.log
1385 cat ${JAR}.log | tee -a "$LOG"
1387 done
1389 [[ -n ${APKS[@]} ]] && echo "### apk patch $P/$A/$ROMTYPE/$B ###"
1390 echo "### apk patch $P/$A/$R/$B ###" >> "$LOG"
1391 for FILE in ${APKS[@]}; do
1392 APK=${FILE##*/}
1393 if [ -d "tmp/${FILE}.out" ] ; then
1394 printtask "... apply $APK.patch ..."
1395 patch -Nls -p2 -d tmp/${FILE}.out < $PARB/${APK}.patch 2>&1 >> ${APK}.log
1396 cat ${APK}.log | tee -a "$LOG"
1397 [[ `grep FAILED ${APK}.log` != "" ]] && apk_check
1398 garbage tmp/${FILE}.out
1399 else
1400 echo "No $APK in your ROM. Not able to patch this file."
1401 echo "## No $APK in ROM ###" >> "$LOG"
1403 done
1404 [[ -n ${IMGS[@]} ]] && echo "### img patch $P/$A/$ROMTYPE/$B ###"
1405 echo "### img patch $P/$A/$R/$B ###" >> "$LOG"
1406 for FILE in ${IMGS[@]}; do
1407 IMG=${FILE##*/}
1408 printtask "... applying $IMG.patch ..."
1409 patch -Nls -p1 -d boot/ramdisk < $PARB/${IMG}.patch >> "$LOG" || print_error "failed patching $FILE"
1410 done
1412 # Text Editing Functions --this can really do just about anything. Needs a working restore!
1413 [[ -n ${TXTS[@]} ]] && echo "### text patch $P/$A/$ROMTYPE/$B ###"
1414 echo "### text patch $P/$A/$R/$B ###" >> "$LOG"
1415 for FILE in ${TXTS[@]}; do
1416 TXT=${FILE##*/}
1417 if [[ -f $PARB/${TXT}.patch ]]; then
1418 printtask "... apply $TXT.patch ..."
1419 patch -Nls -p2 -d system/ < $PARB/${TXT}.patch 2>&1 > ${TXT}.log
1420 #cat ${TXT}.log | tee -a "$LOG"
1421 [[ `grep FAILED ${TXT}.log` != "" ]] && print_error "failed $TXT.patch"
1423 if [[ -f $PAR/${TXT}.awk ]]; then
1424 printtask "... apply $TXT.awk ..."
1425 awk -f $PAR/${TXT}.awk $FILE > text || print_error "failed $TXT.awk"
1426 mv text $FILE
1428 if [[ -f $PAR/${TXT}.sed ]]; then
1429 printtask "... apply $TXT.sed ..."
1430 sed -f $PAR/${TXT}.sed $FILE > text || print_error "failed $TXT.sed"
1431 mv text $FILE
1433 if [[ -f $PAR/${TXT}.sh ]]; then
1434 printtask "... apply $TXT.sh ..."
1435 . $PAR/${TXT}.sh 2>&1 >> ${TXT}.log || print_error "failed $TXT.sh"
1437 garbage system/
1438 done
1439 done
1441 # Device specific scripts- Placement is up-for-review
1442 if [ -f patches/.devices/$DID/$DID.sh ]; then
1443 . patches/.devices/$DID/$DID.sh
1446 # Replace updater-script for CM7- it formats system -Testing
1447 if [ "$ANDR" == "gingerbread" ]; then
1448 replace_updater
1451 # Rebuilding system files
1453 [[ -n ${JID[@]} ]] && printtask "### rebuild jar ###"
1454 for FILE in ${JID[@]}; do
1455 JAR=${FILE##*/}
1456 printtask "... rebuild $JAR ..."
1457 java -Xmx512M -jar smali.jar -a $API tmp/${FILE}.out/smali -o tmp/${FILE}.out/classes.dex >> "$LOG" 2>> "$LOG"
1458 [ -f tmp/${FILE}.out/classes.dex ] || smali_error "failed compiling $JAR !!!"
1459 jar -ufv ${FILE} -C tmp/${FILE}.out/ classes.dex >> "$LOG" 2>> "$LOG"
1460 if [ $FILE == "system/framework/framework.jar" ]; then
1461 jar -ufv ${FILE} -C tmp/${FILE}.out/ preloaded-classes >> "$LOG" 2>> "$LOG"
1463 done
1465 [[ -n ${AID[@]} ]] && printtask "### rebuild apk ###"
1466 for FILE in ${AID[@]}; do
1467 APK=${FILE##*/}
1468 if [ -d tmp/${FILE}.out ]; then
1469 printtask "... rebuild $APK ..."
1470 java -jar apktool.jar b tmp/${FILE}.out >> "$LOG" 2>> "$LOG" || print_error "failed compiling $FILE !!!"
1471 jar -uvf $FILE -C tmp/${FILE}.out/build/apk/ . > /dev/null 2>> "$LOG"
1473 done
1475 [[ -n ${IID[@]} ]] && printtask "### rebuild img ###"
1476 for FILE in ${IID[@]}; do
1477 printtask "### rebuild $FILE ###"
1478 case $FILE in
1479 boot.img)
1480 # Rebuilding boot.img
1481 cd boot
1482 printtask "... rebuilding ramdisk ..."
1483 ./mkbootfs$EXE ./ramdisk | gzip > ramdisk-new.gz
1485 printtask "... composing boot.img ..."
1486 BASE=$(cat boot.img-base)
1487 # hex to decimal in cygwin prefixing "0x" w/ C arithmetic
1488 PGSIZE=$((${PGFORM}$(cat boot.img-pagesize)))
1489 CMDLINE=$(cat boot.img-cmdline)
1490 echo "cmdline = no_console_suspend=1 console=null $CMDLINE" >> "$LOG"
1491 echo "pagesize = $PGSIZE" >> "$LOG"
1492 echo "base = $BASE" >> "$LOG"
1493 printtask "... rebuilding boot.img ..."
1494 ./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"
1495 cd ..
1498 print_error "cannot process $FILE"
1500 esac
1501 done
1503 printtask "### create $UPDATE.zip ###"
1504 jar -cfv tmp.zip ${IID[@]} ${JID[@]} ${AID[@]} ${CID[@]} ${TID[@]} META-INF >> "$LOG" 2>> "$LOG"
1505 java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip $UPDATE.zip 2>> "$LOG"
1507 \mv $RESTORE.zip $UPDATE.zip ..
1508 echo "### finished ###"
1509 echo "flash $UPDATE.zip to install the patched files"
1510 echo "flash $RESTORE.zip to restore the original system"
1512 # add announcement- optional.
1513 for P in ${PID[@]}; do
1514 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1515 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1516 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1517 if [ -f patches/$P/$A/$R/$B/README.txt ]; then
1518 cat patches/$P/$A/$R/$B/README.txt
1519 elif [ -f patches/$P/$A/$R/README.txt ]; then
1520 cat patches/$P/$A/$R/README.txt
1521 elif [ -f patches/$P/$A/README.txt ]; then
1522 cat patches/$P/$A/README.txt
1524 done
1526 cd ..
1527 \rm -rf "$TEMP"