Update PA-jellybean-legacy patches
[auto-patcher.git] / auto_patcher
blob8eeefc6e85513906f11578f63626fed98bf75820
1 #!/bin/bash
3 # Look after changelog for script/patch version info.
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 # 2012.05.12. (v0.2) allows user to specify a different version of patches
15 # 2012.05.13. (v0.3.0) force "patch -N", remove temp upon failure, generate log output
16 # 2012.05.13. (v0.3.1) revised the generation of updater-script (SGS2)
17 # 2012.05.15. added AOSP patches
18 # 2012.05.15. added crespo-aosp patches; device-specific patching if patch exists
19 # 2012.05.15. remove restore.zip upon failure
20 # 2012.05.15. (v0.4.1) added CM7 (GB) patches
21 # 2012.05.18. (v0.4.2) added checking for tool commands
22 # 2012.05.21. (v0.4.3) apply device-specific patches only when it is specified
23 # 2012.05.26. added task title to log
24 # 2012.05.31. (v0.4.4) CM9 patches updated, crespo-aosp added
25 # 2012.06.04. (v0.4.5) added checking tools and rom, added aroma installer support
26 # add patch outputs reroute
27 # 2012.06.15. CM9 patches updated
28 # 2012.06.16. (v0.4.6) AOKP patches updated, patch versions restructured
29 # 2012.06.17. (v0.5.0) patcher script reorganized, removed build.prop
30 # 2012.06.17. (v0.6.0) auto patcher script for pdroid and v6 patches
31 # 2012.06.19. (v0.6.1) add patches for CM7.2 Final
32 # 2012.06.20. (v0.6.2) updated CM 7.2 patches
33 # 2012.06.23. (v0.6.3) fix symlinks
34 # 2012.06.26. (v0.6.4) added 0618 patches for cm7 nightlies; removed 0619 cm7.2 final
35 # 2012.06.27. (v0.6.5) added new CM9 patches (20120626)
36 # 2012.06.27. (v0.6.6) added CM7 nightly patches (20120625) (finally!)
37 # 2012.07.02. (v0.7.0) Redid AOSP/AOKP; add Windows support (using Cygwin). Thanks kobik77!
38 # 2012.07.06. (v0.7.1) updated CM9 patches (20120706)
39 # 2012.07.08. (v0.7.2) updated AOKP (20120707) and CM9 (20120708) pdroid patches
40 # 2012.07.11. (v1.0.0) reworked script works on Linux, Mac OSX, and Windows (on Cygwin);
41 # added new ICS/JellyBean support for the new V6-Supercharger
42 # 2012.07.18. (v1.0.1) new CM7/CM9 Pdroid patches (20120718)
43 # 2012.07.23. (v1.0.2) updated CM9 patches (20120723)
44 # 2012.07.23. (v1.0.3) updated CM9 patches (20120724)
45 # 2012.08.06. (v1.5.0) updated smali/baksmali binaries to 1.33
46 # 2012.08.06. Added Pdroid/V6supercharger support for CM10 Jellybean!
47 # 2012.08.06. Improved PDroid stability and efficiency (Thanks CollegeDev)
48 # 2012.08.06. (v1.6.0) added aokp-jb patches for pdroid/v6supercharger, script update
49 # 2012.08.17. (v1.9.5) Added support for pdroid_addon, by CollegeDev.
50 # Added insecure boot.img mod
51 # Added support for aosp-jb (This needs testing, and may not be
52 # a wide patch due to large variation between AOSP roms.
53 # -Please report all experiences!
54 # Updated all v6supercharger patches w/new edits to ProcessList
55 # Major script overhaul in preparation for additional mods!
56 # 2012.08.20. (v1.9.6) Conditional support for Official cm10 and aokp-jb builds
57 # 2012.08.23. (v1.9.7) Final/confirmed pdroid support for Official CM10 and AOKP-JB
58 # 2012.09.04 (v1.9.8) Bundled cygwin-compatible tools (original was corrupt).
59 # For Cygwin, replaced h2b function with simple bash math
60 # conversion (req'd for compat w/ Cygwin tools).
61 # 2012.08.26. (v2.0.0) Added .apk patching
62 # Added 3G Dongle support for Nexus 7 (trevd)
63 # TabletUI support for Nexus 7 (maybe more)
64 # Google Voice support for Nexus 7
65 # mods are 3gdongle, tabletUI, voice, or nexus7suite (for all)
66 # Added provisional file copy menu to widen patching base
67 # 2012.09.11. (v2.0.1) Cygwin support fixes
68 # 2012.09.11. (v2.0.2) Bugfix for 3gdongle (all)
69 # 2012.09.16. (v2.1.0) Significant restructuring of core operations; added edit text file
70 # fix for "method-cap" errors in pdroid.
71 # 2012.09.20. (v2.1.1) Fix for Phone FC's; OSX support finalized; ContentResolver resolved
72 # 2012.09.28. (v2.1.2) Hotfix for failed pdroid patching. Logging improvements.
73 # 2012.10.07. (v2.1.5) Final pdroid support for CM7.2 Official Releases
74 # Added aosp-mod patches for pdroid patching of AOSP kangs
75 # Switched to Chainfire's (f)aapt for speed/space reasons
76 # 2012.10.13. (v2.1.6) New PDroid patches for aokp-jb and cm10 4.1.2
77 # Revert (f)aapt- temporary due to reported issues
78 # 2012.10.15. (v2.17) New (again) CM10 pdroid patches.
79 # Move files to be copied into $p/$R/$B
80 # -This required a bunch of file moving-report broken symlinks.
81 # Some error check on the old RIL delete functions (thanks bundrik)
82 # 2012.10.16. (v2.1.7.5) Fix FC on phone with CM10 pdroid patches
83 # 2012.10.19. (v2.1.9) Testing CM10 support for PDroid Extension by CollegeDev.
84 # 2012.10.22. (v2.2.0) aosp/aokp and cm10 support for pdroid extension by CollegeDev
85 # MAJOR reworking of patches and improved query. only 4 mod types:
86 # cm, aokp, aosp, and pa. See our OP for details.
87 # 2012.10.26. (v2.3.0) Final (LTS) version. Stable for now until upstream breaks any patches
88 # Thanks to KicknGuitar for the OSX testing!
89 # 2012.11.01. (v2.3.1) Fix for pdroid RIL deletion for older roms
90 # Better Build query logic and help messages
91 # 2012.11.02. (v2.3.5) Add Evervolv support for all mods- Thanks to new maintainer poncik!
92 # Fix method cap for pdroid/pd2.0 for AOKP and kangs
93 # 2012.11.06. (v2.4.0) Update pd2.0 patches to latest pd2.0 release- all except Evervolv
94 # add GsmService to smali.txt; improve rom probe
95 # 2012.11.08. (v2.4.2) Add Evervolv support for pd2.0; Device-specific scripts
96 # Will display error if using a mod on an inapplicable rom
97 # 2012.11.09. (v2.4.5) Error catch for random method issues, fix pd2.0 Evervolv and aosp-jb
98 # 2012.11.17. (v2.4.6) Fix pdroid for CM7. FINALLY!.
99 # 2012.11.17. (v2.4.7) Internal debugging improvements
100 # 2013.01.13. (v2.5.0) Added 'openpdroid' mod --Open-Source Pdroid framework
101 # BIG Improvements to help and error-catch. Try ./auto_patcher -h
102 # 2013.01.15. (v2.5.1) OpenPDroid support for Evervolv and ParanoidAndroid, hotfix for Mms
103 # 2013.01.15. (v2.5.2) Fix for cygwin temp files (kobik), provisional telephony files added
104 # 2013.01.16. (v2.5.3) SlimRom support. Rearrange structure for ApG.
105 # 2013.01.23. (v2.5.4) Fix small bugs related to rearrange
106 # 2013.01.25. (v2.5.7) 4.2 TabletUI support [cm,aokp,aosp,Evervolv]
107 # 2013.01.28. (v2.5.8) Fix for ICS PDroid; small fixes/expansions
108 # 2013.02.01. (v2.6.0) OpenPdroid 1.0.1 patches (cm, aokp, aosp, evervolv and slimrom. no pa.
109 # Fixed TabletUI for Cm10.1- aosp to come. Removed most old patches.
110 # 2013.02.01. (v2.6.25) PA OpenPDroid 1.0.1 patches; AOSP TabletUI. removed opd all 1.0.0
111 # 2013.02.09. (v2.7.0) Add new AOKP, CM9, CM10,CM10.1 and PA (3.0) patches for OPD
112 # 2013.02.09. (v2.7.5) Add new AOKP, AOSP, CM10.1 and PA (3.0) patches for OPD (Andr. 4.2.2)
113 # 2013.02.17. (v2.7.9) 4.2.2 opd 4 evervolv; v6supercharger,3gdongle and all but tabletUI.
114 # 2013.02.20. (v2.8.0) New CM10.1 opd patches. Each BID can have own provisionals now.
115 # 2013.02.23. (v2.8.2) SlimRom 4.2.2 support (from karamelos), APK recompile safety net.
116 # 2013.03.01. (v2.8.3) PAC (.aosp-pac) 4.2.2 support (from AussieLambChops), apktool 1.5.2
117 # 2013.03.03. (v2.8.4) Remove settings.apk from tabUI, replace Mms.apk. Refactors.
118 # 2013.03.06. (v2.8.5) Bugfixes, mainly.
119 # 2013.03.17. (v2.8.6) Added 4.2.2 tabletUI test run for CM from Caldair.
120 # 2013.03.18. (v2.8.6.5) Hotfix from caldair for tabletUI, new SlimRom patches
121 # 2013.03.18. (v2.8.7) TabletUI support for 10 inch screens (caldair)
122 # 2013.03.25. (v2.8.8) Fix for Cygwin paths with spaces (from kobik77)
123 # 2013.04.06. (v2.9.0) Added new tabletUI patches for CM and 4.2 conflicts.
124 # 2013.04.10. (v2.9.1) Updated aokp openpdroid patches (0405) please report.
125 # 2013.04.18. (V2.9.2) Added AOSP and SlimROm TabletUI patches (credit: Caldair)
126 # 2013.04.18. (V2.9.3) Added missing framework2.jar opd aosp 4.1
127 # 2013.05.08. (v2.9.4) Updates to TabletUI (from Caldair)
128 # 2013.05.18. (v2.9.5) New AOKP openpdroid patches (0514)
129 # 2013.05.20. (v2.9.6) New CM and PAC-man (aosp) openpdroid patches.
130 # 2013.05.27. (v2.9.7) $INCREMENTAL patches for bugs/updates and GPS fix for opd (credits to phillipberndt)
131 # 2013.05.30. (v2.9.8) Improve apk handling: test fix disappearing apks. New opd: evervolv,slim
132 # 2013.06.18. (v2.9.83) Introduce auto-update for OSX and Linux...turn off by setting it false in .config
133 # Update PACman patches for OPD and update telephony for PA to silence errors
134 # 2013.06.18. (v2.9.84) Some environment trickery to speed up search/sort. Add WEBSITE for mods.
135 # Check updating. New AOKP OPD patches
136 # 2013.06.19. (v2.9.85) Fixes to auto-update. Added changelog.txt
137 # 2013.06.20. (v2.9.865) Various bugfixes, add color, obfuscate $PROVISIONALS.
138 # 2013.06.21. (v2.9.87) Added ALTERNATE patches feature- hopefully fixes PA telephony issues.
139 # 2013.06.22. (v2.9.875) New tabletUI patches, revert flawed CONFLICTS feature
140 # 2013.06.22. (v2.9.88) New CM opd patches
141 # 2013.06.28. (v2.9.89) revert baksmali changes for now (still needs work), add new PACman OPD 6/26
142 # 2013.07.02. (v2.9.91) Switch to SlimRom team's aapt and apktool for OSX+Windows (Need OSX builder!)
143 # 2013.07.07. (v2.9.92) New opd patches for Slim/PA; some fixes to tabletUi by Caldair
144 # 2013.07.17. (v2.9.927) Fix missing Mms (finally), support for CM Final, many bugfixes (conflicts, mod ordering, etc.)
145 # 2013.07.20. (v2.9.93) New OPD CM patches, many bugfixes
146 # 2013.07.20. (v2.9.935) New PA, AOKP patches. gitattribute. FIx PING for cygwin. (h/t: gcydtmkq)
147 # 2013.08.05. (v2.9.941) Bundle patchv2.6.1 for cygwin.
148 # 2013.08.07. (v3.0.0) Support for Android-4.3 (Opendproid only- CM and AOSP).
149 # 2013.08.09. (v3.0.1) Build date and patch date matching for multiple mods- all mods will now use best available match.
150 # 2013.08.12. (v3.0.2) OpD support for Evervolv, PACman and PA and CM10 returns
153 # SHELL PROGRAMMING NOTES:
154 # [ -s FILE ]
155 # [[ -n STRING ]] or [[ -z STRING ]]
157 VERSION="v3.0.214"
158 # PATCHES_VERSION needs to be incremented every time ANY changes occur to patches.
159 PATCHES_VERSION="20130820"
160 CURRENT_ANDROID="4.3.0"
162 # pass variables to children
163 set -a
165 # Set any environmental variables
166 LANG=C
167 CYGWIN=false
168 # unused for now...for experiments with "-s" flag and new patches made with it.
169 BAKSMALI_BINARY=baksmali.jar
170 SMALI_BINARY=smali.jar
171 declare -a MODS_LIST
172 declare -a PATCH_DATE_LIST
174 # Available ROMTYPES.
175 # ROMTYPES that are hidden can be forced on the command line. But they are best left
176 # blank to be automatically parsed by our romprobe or by just entering the parent...usually AOSP.
178 #Non-obvious ROMTYPE legend
179 # @.aosp-slim: SlimRom @.aosp-pac: PAC-man
180 # @.aosp-ever: Evervolv @pa: ParanoidAndroid (official jellybean branch only for now)
181 declare -a AVAILABLE_ROMTYPES=('aokp' 'aosp' 'cm' 'pa' '.aosp-slim' '.aosp-pac' '.aosp-ever')
183 # Config file: For now hosting AUTO_UPDATE and PRODUCTION(currently unused). Not under version control.
184 if [ ! -f .config ]; then
185 cp -a ap_scripts/config_template .config
187 source .config
189 # Colorize and add text parameters
190 red=$((tput setaf 1) 2>/dev/null) # red
191 grn=$((tput setaf 2) 2>/dev/null) # green
192 cyan=$((tput setaf 6) 2>/dev/null) # cyan
193 txtBold=$((tput bold) 2>/dev/null) # Bold
194 txtReset=$((tput sgr0) 2>/dev/null) # Reset
196 colorize () {
197 # pass color and then reset
198 echo -e $@${txtReset}
201 colorize_bold () {
202 echo -e ${txtBold}$@${txtReset}
205 printusage_help () {
206 PID="openpdroid,3gdongle" # default example
207 brief_help
210 brief_help () {
211 echo " usage: ./auto_patcher <ROM> <MODS> <ROMTYPE>"
212 echo " example: ./auto_patcher CM10.zip $PID cm"
213 echo ""
214 echo "Use ./auto_patcher -h for the help menu"
215 echo ""
216 cleanup
217 exit
220 usage_help () {
221 PID=mods
222 mods_display
223 echo "Multiple MODS can be combined by separating them with a comma and NO SPACES!!!"
224 echo ""
225 echo " usage: ./auto_patcher <ROM> <MODS> <ROMTYPE>"
226 echo ""
227 echo " example: ./auto_patcher CM10.zip openpdroid,3gdongle cm"
228 echo ""
229 usage_more_help
232 usage_more_help () {
233 echo "* press 'q' available patches or CTRL-c to quit the help menu *"
236 display_help () {
237 cd patches
238 echo ""
239 echo "AVAILABLE PATCHES"
240 echo ""
241 echo "*******************************************************************"
242 echo "Note: There are ONLY 4 ROMTYPES: [pa, cm, aokp, and aosp]."
243 echo ""
244 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
245 echo ""
246 echo "!!! Do not put Android Version number on command line !!!!"
247 echo "*****************************************************************"
248 echo "Specific auto_patcher script options"
249 echo " ./auto_patcher -h mods Lists mods"
250 echo " -h <MODNAME> Specific <MOD> info"
251 echo " -h advanced Advanced usage+lists all available patch dates"
252 echo ""
253 cleanup
254 exit
257 romtype_help () {
258 # From rom_error (bad romtype) and date_error (patch date w/o specifying romtype)
259 echo ""
260 echo "!!!There are only four supported ROMTYPES: 1) cm 2) aokp 3) aosp 4) pa"
261 echo ""
262 echo "Find out which of the above ROMTYPES your rom is based on and try again!"
263 echo "**********************************************"
264 echo ""
265 cleanup
266 brief_help
269 advanced_help () {
270 echo ""
271 echo "The Auto-Patcher Advanced Usage"
272 echo "*********************************"
273 echo ""
274 echo "For those of you determined to try everything..."
275 echo ""
276 echo "You can also try adding a patch date as a final argument."
277 echo ""
278 echo " ./auto_patcher <ROM> <MOD> <ROMTYPE> <DATE>"
279 echo ""
280 echo "Please note: There are only four ROMTYPES: {pa, aokp, aosp and cm}"
281 echo " -The various appellations after that are for internal use only!"
282 echo ""
283 echo "The Auto-Patcher has a pretty great rom probe, specifying the date is"
284 echo " deprecated...you don't need to, we promise."
285 echo ""
288 cleanup () {
289 [[ -n $ROOT ]] && \rm -rf "$ROOT"/tmp*
292 garbage () {
293 unset GARBAGE
294 GARBAGE=($(find $@ -name "*.orig")) && rm -rf ${GARBAGE[@]} && echo "GARBAGE= ${GARBAGE[@]}" >> "$LOG"
295 GARBAGE=($(find $@ -name "*.rej")) && rm -rf ${GARBAGE[@]} && echo "GARBAGE= ${GARBAGE[@]}" >> "$LOG"
299 print_error () {
300 # General purpose error. Used for errors in main, as opposed to probe or set-up.
301 echo ""
302 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
303 printtask "!!! error: $@"
304 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
305 echo ""
306 brief_help
309 smali_error () {
310 # Smali binary error. Problem often goes away on second run.
311 echo ""
312 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
313 printtask "!!! error: $@"
314 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
315 echo ""
316 if [[ $(grep 'method index is too large' "$LOG") != "" ]]; then
317 printtask "!!! Problem with method cap !!!"
318 printtask "... attempting fix ..."
319 . patches/.common/framework.jar.sh 2>&1 > ${JAR}.log
320 printtask "... rebuild framework.jar ..."
321 java -Xmx512M -jar smali.jar -a $API tmp/${FILE}.out/smali -o tmp/${FILE}.out/classes.dex >> "$LOG" 2>> "$LOG"
322 [ -f tmp/${FILE}.out/classes.dex ] || print_error "Could not resolve method cap issue- please submit log"
323 else
324 printtask "!!! This error is generally due to an unknown bug in the smali binary!"
325 echo "In our experience, it goes away if you run the patcher a second time."
326 echo " Please run the Auto-Patcher with the same command once again."
327 echo ""
328 echo "If after the third attempt the same thing happens,"
329 echo " please upload your logfile to our support thread!"
330 echo ""
331 cleanup
332 exit
336 unknown_mod_error () {
337 echo ""
338 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
339 printtask "!!! error: $@"
340 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
341 echo ""
342 cleanup
343 printusage_help
346 mismatch_error () {
347 # Function that exposes attempts to apply a mod to an upsupported Android version
348 echo ""
349 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
350 printtask "!!! error: $@"
351 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
352 echo ""
353 cleanup
354 brief_help
357 date_error () {
358 # Remind users to include a romtype if they are going to specify a patch date
359 echo ""
360 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
361 printtask "!!! error: $@"
362 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
363 echo ""
364 echo "Please put a ROMTYPE before the patch date and run again!!"
365 romtype_help
368 rom_error () {
369 # For when an unsupported romtype is manually entered on the command-line
370 echo ""
371 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
372 printtask "!!! error: $@"
373 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
374 romtype_help
377 conflict_error () {
378 # For conflicting packages
379 echo ""
380 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
381 printtask "!!! error: $@"
382 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
383 cleanup
384 PID=mods
385 mods_info
388 misspatch_error () {
389 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
390 printtask "!! error: $@ "
391 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
392 echo ""
393 printtask "!! The Auto-Patcher could not find its patches and/or tools!"
394 echo ""
395 echo "* Did you run ./batch.sh first?"
396 echo ""
397 echo "The patch_patches.tgz and patch_tools.tgz need to be in this directory,"
398 echo " one way or another..."
399 echo ""
400 cleanup
401 brief_help
404 misstools_error () {
405 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
406 printtask "!! error: $@ "
407 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
408 printtask "Your set-up is missing a dependency."
409 echo "We require JDK, tar, patch and cpio."
410 echo ""
411 echo ""
412 echo "Each distro is different"
413 echo "but ensure you have them all installed and try again."
414 echo ""
415 cleanup
416 brief_help
419 miss_git_error () {
420 printtask "Updater: disabled"
421 echo ""
422 printtask "You will not be able to get automatic updates because we could not find 'git'."
423 printtask "Find out how to install git for your system and that feature should work automatically"
424 echo ""
427 printtask () {
428 echo "" >> "$LOG"
429 echo -e $@ | tee -a "$LOG"
432 print_to_log () {
433 echo "$@" >> "$LOG"
436 copy_prepatched_provisional () {
437 print_to_log "File for which patching failed:"
438 print_to_log "---------------------------------------------"
439 print_to_log ""
440 print_to_log "${FAIL##*/}"
441 print_to_log ""
442 print_to_log "---------------------------------------------"
443 print_to_log ""
444 print_to_log "We are adding a pre-patched copy of those files."
445 print_to_log ""
446 print_to_log "Please only file a bug report if running the program gives you problems!!!"
447 print_to_log "... replace $FAIL ..."
448 \rm -rf tmp/${FILE}.out/smali/${FAIL} tmp/${FILE}.out/smali/${FAIL}.orig tmp/${FILE}.out/smali/${FAIL}.rej
449 \cp -av "$PROVISIONAL" tmp/${FILE}.out/smali/${FAIL} >> "$LOG" 2>&1
450 SID=(${SID[@]} $FAIL)
451 print_to_log "... failed patch sucessfully resolved ..."
454 prep_alternate_patch () {
455 # Use alt.patch, if exists. Increment in case there are multiple alternates.
456 mv -v $ALTERNATIVE_PATCH $PARB/${NAME}.patch >> "$LOG"
457 ALT_PATCH_NUMBER=$((PATCH_NUMBER + 1))
459 # Get fresh files/variables + decompile again (use rm b/c privacy files wouldn't get overwritten)
460 # TODO: test patch -R instead of re-decompiling. Should work.
461 rm -rf tmp/${FILE}.out/smali
462 java -jar baksmali.jar -b -a $API -o tmp/${FILE}.out/smali ${FILE} >> "$LOG" 2>> "$LOG"
463 unset FAILS && unset SID
464 current_jar=$(($current_jar - 1))
465 break
468 no_network_access () {
469 PING_CHECK "www.github.com" >> "$LOG" 2>&1 && NETWORK=true # second try and check github
470 PING_CHECK "www.google.com" >> "$LOG" 2>&1 # test for internet in general
471 if [[ "$NETWORK" == true ]]; then
472 return
473 else
474 printtask "Check for update failed, probably because of no internet access."
475 echo "The autopatcher will continue with current local version: $VERSION"
476 NETWORK=false
477 echo ""
478 sleep 2
482 auto_update_error () {
483 echo ""
484 printtask "### Update failed ###"
485 printtask ""
486 printtask "It appears you may have made some changes that prevent automatic updating."
487 echo ""
488 printtask "You could run 'git reset --hard' to return the autopatcher to its original form"
489 printtask " or set AUTO_UPDATE to false in the .config file to stop getting this message."
490 echo ""
491 printusage_help
494 backup_script () {
495 printtask "... backing up auto_patcher to auto_patcher.bak ..."
496 cp -av auto_patcher auto_patcher.bak >> "$LOG" #backup for user in case of changes
497 echo ""
500 warn_of_overwrite () {
501 # Only seen once, by users without ".git" directories
502 # Only users who got program @ download page see this, all others (ApG included) use git
503 echo "This is a one time set-up process that will overwrite all local changes!"
504 echo "If this is not ok with you press ctrl-C and set AUTO_UPDATE to false in .config"
505 echo ""
508 establish_repo() {
509 printtask "### establishing the repo ###"
510 echo "... please be patient, this should only be needed once ..."
511 echo ""
512 git clone https://github.com/mateor/auto-patcher >> "$LOG" || no_network_access
513 if ($NETWORK); then
514 mv -v auto-patcher/".git" . >> "$LOG"
515 rm -rf auto-patcher
516 git checkout -q master || auto_update_error
517 git reset --hard 2>&1 >> "$LOG"
518 echo ""
522 export_log_and_variables () {
523 AUTO_PATCHER_OLD_VERSION=$VERSION
524 AUTO_PATCHER_OLD_PATCHES_VERSION=$PATCHES_VERSION
525 AUTO_PATCHER_WAS_UPDATED=true
526 UPDATED_LOG="$PATCHES_VERSION".updated.log
527 cp -a "$LOG" "$UPDATED_LOG"
528 rm -f "$LOG"
531 print_changelog () {
532 CHANGELOG="changelog.txt"
533 echo "" > "$CHANGELOG"
534 CURRENT_HEAD=$(git rev-parse HEAD)
535 echo "Changelog from Autopatcher$AUTO_PATCHER_OLD_VERSION to Autopatcher$VERSION" >> "$CHANGELOG"
536 echo "---------------------------------------------------------------------------" >> "$CHANGELOG"
537 echo "" >> "$CHANGELOG"
538 echo " Get more info about any individual commit by entering 'git show \$NUMBER'" >> "$CHANGELOG"
539 echo "" >> "$CHANGELOG"
540 git log --pretty=oneline $ORIGINAL_HEAD...$CURRENT_HEAD >> changelog.txt
541 printtask "... "$CHANGELOG" has been updated ..."
544 replace_updater () {
546 # Function for devices that use SDcard installs. Also to be tested for CM7
547 # since CM7 seems to use an updater-script that wipes EMMC. Testing
549 \rm $UPDATER_LOC/$UPDS 2>&1
550 \cp patches/.common/$UPDATER_LOC/$UPDS $UPDATER_LOC >> "$LOG" 2>&1
551 echo "run_program(\"/sbin/busybox\", \"umount\", \"/system\");" >> UPDATE.txt
552 cat UPDATE.txt >> $UPDATER_LOC/$UPDS
553 echo ""
554 echo "New updater-script being used:" >> "$LOG"
555 echo "-----------------------------" >> "$LOG"
556 cat $UPDATER_LOC/$UPDS >> "$LOG"
559 abspath () {
560 case $(uname -s) in
561 CYGWIN*)
562 echo $(cygpath -ua "$1") | sed 's:/$::g'
564 Darwin)
565 #[[ $(echo $1 | awk '/^\//') == $1 ]] && echo "$1" || echo "$PWD/$1"
566 [[ ${1:0:1} == "/" ]] && echo "$1" || echo "$PWD/$1"
568 Linux)
569 echo $(readlink -f "$1")
572 if [[ ${1:0:1} == "/" ]]; then
573 echo "$1"
574 elif [[ ${1:0:2} == "./" ]]; then
575 echo "$PWD/${1:2}"
576 else
577 echo "$PWD/$1"
580 esac
583 mods_display () {
584 echo ""
585 echo "The Auto-Patcher $VERSION"
586 echo "*******************************"
587 echo ""
588 echo "The available mods are"
589 echo "****************************************************"
590 echo "* pdroid openpdroid voice v6supercharger *"
591 echo "* voice insecure secure external_internal *"
592 echo "* tabletUI 3gdongle pd2.0 *"
593 echo "****************************************************"
594 echo ""
595 echo "To find out more about any mod, simply enter:"
596 echo " ./auto_patcher -h <MODNAME>"
597 echo ""
598 cleanup
601 mods_info () {
602 # Defaults
603 DEPENDENCY="None"
604 DEV="Unknown"
605 CEILING=$CURRENT_ANDROID
606 ROM_CONFLICTS=(None)
607 UNKNOWN_MOD=false
608 case $PID in
609 mods)
610 mods_display
611 exit
613 auto*)
614 echo ""
615 echo "**************************************"
616 echo "The Auto-Patcher ate a kitten once..."
617 echo "**************************************"
618 echo ""
619 DEV="mateor and Caldair"
620 WEBSITE="https://github.com/mateor/auto-patcher"
621 printusage_help
623 advanced)
624 cd patches/
625 (advanced_help && find -H * -name 201*) | more -d
626 echo ""
627 brief_help
629 voice)
630 FLOOR=4.0.0
631 DESC="Use on wifi-only tablets to have the software register as 'voice-enabled'. Allows VOIP like Google Voice to function."
632 DESC="bongostl's setup method can be seen at the link."
633 WEBSITE="http://forum.xda-developers.com/showthread.php?t=1823701"
634 DEV="bongostl"
636 v6 | v6supercharger)
637 FLOOR=4.0.0
638 CEILING=4.2.2
639 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."
640 DEV="Zeppelinrox"
641 DEPENDENCY="The V6 Supercharger Script. Get it at the link"
642 WEBSITE="http://forum.xda-developers.com/showthread.php?t=991276"
644 PID="v6supercharger" # allows shorthand 'v6' to find patches.
646 pdroid)
647 FLOOR=2.3.7
648 CEILING=4.1.2
649 DESC="Security Software that manages access to personal data w/o causing FC's. No longer under development."
650 DESC1="Try the open-source expansion of this program, OpenPdroid."
651 DESC2="(It's the 'openpdroid' mod within the Auto-Patcher)."
652 DEV="Svyat"
653 DEPENDENCY="The Pdroid app. You can get it at the link"
654 WEBSITE="http://forum.xda-developers.com/showthread.php?t=1923576"
657 pd2.0)
658 FLOOR=4.1.2
659 CEILING=4.1.2
660 DESC="An expansion of the PDroid application/framework."
661 DEV="CollegeDev"
662 DEPENDENCY="The free PDroid2.0 app available at the link"
663 WEBSITE="http://forum.xda-developers.com/showthread.php?t=1923576"
665 openpdroid)
666 FLOOR=4.1.2
667 CEILING=4.3.0
668 DESC="A fork of the open-source PDroid and Pdroid2.0 framework."
669 DEV="CollegeDev/FFU5y/wbedard/mateorod/Community"
670 DEPENDENCY="PDroidManager(opensource) or PDroid2.0(CollegeDev)"
671 WEBSITE="http://forum.xda-developers.com/showthread.php?t=1994860"
673 opendroid)
674 echo ""
675 echo "No mod named 'opendroid'. You probably mean 'openpdroid'. Try again."
676 PID="mods"
677 mods_info
679 external_internal)
680 FLOOR=2.3.3
681 CEILING=4.1.2
682 DESC="Swap internal and external storage."
684 insecure)
685 FLOOR=2.3.3
686 DESC="Make any boot.img insecure and allow remount as well as adb push/pull of system files. True root."
688 secure)
689 FLOOR=2.3.3
690 DESC="Make any boot.img secure."
692 3gdongle)
693 FLOOR=4.1.0
694 CEILING=4.2.2
695 DESC="Allows 3gdongles to work on wifi tablets w/o 3rd party applications."
696 DEV="trevd"
697 DEPENDENCY="None, but read the troubleshooting guide at the link"
698 WEBSITE="http://forum.xda-developers.com/showthread.php?t=1798631"
700 tabletUI)
701 FLOOR=4.1.0
702 CEILING=4.3.0
703 if [[ $ANDR == "4.3" ]]; then
704 ROM_CONFLICTS=(aosp .aosp-slim .aosp-ever aokp pa)
705 elif [[ $ANDR == "4.2" ]]; then
706 ROM_CONFLICTS=(.aosp-ever aokp pa)
707 else
708 ROM_CONFLICTS=(pa .aosp-slim)
710 DESC="Changes the user interface of Phones and Phablets to the popular Tablet UI."
711 DEV="barmullio/Caldair"
712 WEBSITE="http://forum.xda-developers.com/showthread.php?t=2154075"
715 UNKNOWN_MOD=true
716 FLOOR=?????
717 CEILING=?????
718 DESC="??? Unknown modtype ??? Check your spelling or the mod list!"
719 DESC1=" Try: \"./auto_patcher -h mods\""
720 esac
722 # strip decimals from android version (i.e. 2.3.7 becomes 237) so we can do math
723 NVID=${VID//[.]/}
724 COMPATF=${FLOOR//[.]/}
725 COMPATC=${CEILING//[.]/}
726 if [[ ${#NVID} -lt 3 ]]; then
727 NVID="$NVID"0
731 apk_copy () {
732 if [ -f patches/$P/$A/$R/$B/$FILE ]; then
733 mkdir apk_staging
734 cd apk_staging
735 # Move the certs and manifests from the ROM's apk into the prepatched copy
736 jar -xvf ../"$FILE" META-INF AndroidManifest.xml >> "$LOG"
737 jar -ufv ../patches/$P/$A/$R/$B/$FILE META-INF/CERT* AndroidManifest.xml >> "$LOG" 2>> "$LOG"
738 cd ..
739 \cp -av patches/$P/$A/$R/$B/$FILE $FILE >> "$LOG" 2>&1
740 echo "... Patching $APK failed, but we have successfuly copied over a prepatched file ..."
741 apk_was_copied=true
742 else
743 print_error "failed patching $APK!!!"
747 no_mod_selected_error () {
748 echo ""
749 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
750 printtask "!!! error: $@"
751 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
752 echo ""
753 printtask "You need to enter a MOD before you try and specify the ROMTYPE."
754 printtask "Check the help menu for the list of available MODS"
755 echo ""
756 printusage_help
759 check_against_rom_types () {
760 # this checks to see if the user has entered a ROMTYPE in the MOD spot and outputs advice if so.
761 NUMBER_OF_AVAILABLE_ROMTYPES=${#AVAILABLE_ROMTYPES[@]}
762 for ((i=0; i < $NUMBER_OF_AVAILABLE_ROMTYPES; i++)); do
763 if [[ ${AVAILABLE_ROMTYPES[i]} == "$P" ]]; then
764 no_mod_selected_error "\"$P\" is a ROMTYPE not a MOD"
766 done
769 compat_check () {
770 for G in ${PID[@]}; do
771 mods_info
772 if ($UNKNOWN_MOD); then
773 check_against_rom_types
774 unknown_mod_error "\"$G\" is not a valid mod. Check your spelling or the mod list!!!"
775 elif [[ "$NVID" -lt "$COMPATF" ]]; then
776 mismatch_error "Your Android $VID rom is too old! The minimum for $G is \n !!! Android $FLOOR!"
777 elif [[ "$NVID" -gt "$COMPATC" ]]; then
778 mismatch_error "Sorry, $G has not been made available for Android $VID yet!"
780 done
783 rom_compat_check () {
784 N=${#ROM_CONFLICTS[@]}
785 for ((i=0; i < $N; i++)); do
786 if [[ $RID == ${ROM_CONFLICTS[$i]} ]]; then
787 rom_compat_error
789 done
792 rom_compat_error () {
793 print_error "$RID is incompatible with $PID!!!"
796 extpath () {
797 case $(uname -s) in
798 CYGWIN*)
799 echo $(cygpath -da "$1")
802 echo $(abspath "$1")
804 esac
807 #contains () { for e in "${@:2}"; do [[ "$e" = "$1" ]] && return 0; done; return 1; }
809 parse () { echo "${1%%_*}"; }
811 getbuildprop () {
812 if [ -f system/build.prop ]; then
813 result=($(grep $1 system/build.prop | tr -d '\r' | tr '=' ' '))
814 echo "${result[1]}"
815 else
816 echo ""
821 aosp_mod_check() {
822 jar -xvf "$ROMX" system/framework/framework2.jar >> "$LOG"
823 if [ -s system/framework/framework2.jar ]; then
824 ever_check
825 else
826 AOSP=aosp
828 echo $AOSP
831 ever_check() {
832 MID=$(getbuildprop ro.build.romversion)
833 if [[ $MID == "Evervolv"* ]]; then
834 AOSP=".aosp-ever"
835 else
836 MID=$(getbuildprop ro.build.display.id)
837 if [[ "$MID" == "ev"* ]]; then
838 AOSP=".aosp-ever"
839 else
840 pac_check
843 echo $AOSP
846 pac_check() {
847 MID=$(getbuildprop ro.build.romversion)
848 if [[ "$MID" == "pac"* ]] || [[ "$MID" == "PAC"* ]]; then
849 AOSP=".aosp-pac"
850 else
851 MID=$(getbuildprop ro.build.display.id)
852 if [[ "$MID" == "pac"* ]] || [[ "$MID" == "PAC"* ]]; then
853 AOSP=".aosp-pac"
854 else
855 slim_check
860 slim_check() {
861 SLMID=$(getbuildprop ro.modversion)
862 SLMMID=$(getbuildprop updateme.name)
863 if [[ "$SLMMID" == "Slim"* ]] || [[ $SLMMID == "slim"* ]]; then
864 AOSP=".aosp-slim"
865 elif [[ "$SLMID" == "Slim"* ]] || [[ $SLMID == "slim"* ]]; then
866 AOSP=".aosp-slim"
867 else
868 if [[ "$ANDR" == "4.1" ]]; then
869 AOSP=.aosp-mod
870 else
871 AOSP="aosp"
876 pa_check() {
877 CMID=$(getbuildprop ro.modversion)
878 PAID=$(getbuildprop ro.pa.version)
879 MID=$(getbuildprop ro.build.display.id)
880 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
881 DID=$(getbuildprop ro.product.device)
882 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
883 if [[ -n $PAID ]]; then
884 RID=pa
885 else
886 case $CMID in
887 [Pp][Aa]*)
888 RID=pa;
891 RID=cm;
893 esac
897 romtype_set () {
898 case $RID in
900 ROMTYPE="cm"
902 aokp*)
903 ROMTYPE="aokp"
906 ROMTYPE="pa"
909 ROMTYPE="aosp"
911 esac
914 proberom () {
915 VID=$(getbuildprop ro.build.version.release)
916 if [ ${#VID} -lt 4 ]; then # in case of non-standard versioning in build.prop (defy!)
917 ANDR=$VID
918 else
919 ANDR="${VID%.*}" # Cut to 1 significant digit to cover specific range or release.
921 if [ "$ANDR" == "2.3" ]; then
922 FLAVR=gingerbread
923 API=10
924 RID=cm;
925 elif [ "$ANDR" == "4.0" ]; then
926 FLAVR=ics
927 API=15
928 MID=$(getbuildprop ro.rommanager.developerid)
929 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.modversion))
930 DID=$(getbuildprop ro.product.device)
931 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
933 case "$MID" in
934 pa|cm9|cm|cyanogenmod*)
935 RID=cm;
937 aokp|teamkang)
938 RID=aokp;
940 aosp*)
941 RID=aosp;
944 echo "!!! $MID is not supported yet, trying aosp !!!"
945 RID=aosp
947 esac
948 elif [ "$ANDR" == "4.1" ]; then
949 FLAVR=jellybean
950 API=16
951 CMID=$(getbuildprop ro.cm.version)
952 if [[ -n $CMID ]]; then
953 pa_check
954 else
955 MID=$(getbuildprop ro.build.display.id)
956 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
957 DID=$(getbuildprop ro.product.device)
958 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
959 case "$MID" in
960 cm10|cm*|cyanogenmod*)
961 RID=cm;
963 aokp*|teamkang)
964 RID=aokp;
966 pa*)
967 RID=pa;
969 ev*)
970 RID=".aosp-ever";
973 RID=$(aosp_mod_check);
975 esac
977 elif [ "$ANDR" == "4.2" ] || [ "$ANDR" == "4.3" ]; then
978 FLAVR=jellybean
979 [ "$ANDR" == "4.2" ] && API=17
980 if [ "$ANDR" == "4.3" ]; then
981 API=18
982 BAKSMALI_BINARY="baksmali.jar"
983 SMALI_BINARY="smali.jar"
985 CMID=$(getbuildprop ro.cm.version)
986 MID=$(getbuildprop ro.build.display.id)
987 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
988 DID=$(getbuildprop ro.product.device)
989 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
991 case "$MID" in
992 cm*|cyanogenmod*)
993 RID=cm;
994 # hack to account for Final builds with old code and current build dates. Huge hack, but if there
995 # is one thing I don't believe in, it's "educating the user-base". Not happening. So hack it is.
996 if [[ "$CMID" == "10.1.2"* ]] || [[ "$CMID" == "10.1.3"* ]]; then
997 echo " ### CMID: $CMID: Selecting CM Final Build patches" >> "$LOG"
998 BID_OVERRIDE=20130516
1001 aokp*|teamkang)
1002 RID=aokp;
1004 [Pp][Aa]*)
1005 if [[ "$MID" == "pac"* ]] || [[ "$MID" == "PAC"* ]]; then
1006 RID=".aosp-pac"
1007 else
1008 RID=pa;
1011 ev*|Ever*)
1012 RID=".aosp-ever";
1015 RID="$(ever_check)";
1017 esac
1018 else
1019 print_error "unknown ROM version $VID: generally means cannot find/read build.prop"
1021 # romtype_set allows hiding ".aosp-*" types from users while leaving them as options on CLI
1022 romtype_set
1023 echo "... result of ROM check: version= $VID rom= $ROMTYPE ..."
1027 # Advanced build date query
1028 # This should set the patch date automatically.
1030 build_query() {
1031 UTC=$(getbuildprop ro.build.date.utc)
1033 # Difference in how OS X and Linux/Cygwin handles 'date' utility
1034 case $(uname -s) in
1035 [Dd]arwin)
1036 BDID=$(date -r $UTC +%Y%m%d)
1037 echo "#### Darwin Build Query used ####" >> "$LOG"
1040 BDID=$(date -d "1970-01-01 UTC $UTC seconds" +"%Y%m%d")
1041 echo "#### Standard Build Query ####" >> "$LOG"
1043 esac
1045 # If patch date is specified on CLI, use that patch date
1046 if [ $# -gt 3 ]; then
1047 BID=${4//,/ };
1048 BDID=$BID
1049 else
1050 case $ANDR in
1051 2.3)
1052 # CM7 roms do not have UTC time stamp- so no build query.
1053 BID=latest;
1054 echo "*** CM7 roms default to latest patches. If using an older rom ***"
1055 echo "*** specify patch date on command line. Use -h to see available patches ***"
1058 PATCH_COUNTER=0
1059 for P in ${PID[@]}; do
1060 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1061 [ -d patches/$P/$A/"$RID" ] && R=$RID || R=generic
1062 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1063 PAR=patches/$P/$A/$R
1064 PARB=patches/$P/$A/$R/$B
1065 DATES=$(ls patches/$P/$A/"$R" | grep '201*')
1066 # Intialize variable - an upperbound to determine lowest in first loop.
1067 BID=20201231
1068 # find earliest available patch date
1069 for i in $DATES; do
1070 if [[ $i -lt $BID ]]; then
1071 BID=$i
1073 done
1074 # Check if earliest patches are from before build date. Else use earliest
1076 # If rom is newer than earliest patch set, find best match
1077 if [[ $(($BID-$BDID)) -lt 0 ]]; then
1078 for g in $DATES; do
1079 # use any patch that matches $UTC
1080 if [[ $(($BDID-$g)) -eq 0 ]]; then
1081 BID=$g
1082 break
1083 # Set highest $BID w/o going over $UTC
1084 elif [[ $(($BDID-$g)) -gt 0 ]] && [[ $g -gt $BID ]]; then
1085 BID=$g
1087 done
1089 # Error catch if query fails.
1090 [[ $BID == "20201231" ]] && BID=latest && echo "Build Query Failed!! Default to latest!" >> "$LOG"
1091 if [[ -n "$BID_OVERRIDE" ]]; then
1092 BID="$BID_OVERRIDE"
1094 printtask "... $P patch date has been set to: $BID ..."
1095 MODS_LIST[$PATCH_COUNTER]=$P
1096 PATCH_DATE_LIST[$PATCH_COUNTER]=$BID
1097 PATCH_COUNTER=$(($PATCH_COUNTER + 1))
1098 done
1100 esac
1104 proberil () {
1105 RIL=$(getbuildprop ro.telephony.ril_class)
1106 [[ -n $RIL ]] && printtask "... result of ROM check: RIL= $RIL"
1109 rominfo () {
1110 echo "# VER= $VERSION" >> "$LOG"
1111 echo "# OS= $OSTYPE ${BIT}bit" >> "$LOG"
1112 echo "# VID= $VID" >> "$LOG"
1113 echo "# PID= ${PID[@]}" >> "$LOG"
1114 echo "# MID= $MID" >> "$LOG"
1115 echo "# RID= $RID" >> "$LOG"
1116 echo "# ANDR= $ANDR" >> "$LOG"
1117 echo "# BDID= $BDID" >> "$LOG"
1118 echo "# DID= $DID" >> "$LOG"
1119 echo "# BID= $BID" >> "$LOG"
1121 if [ -d ../".git" ]; then
1122 echo "" >> "$LOG"
1123 echo -n "Current HEAD: " >> "$LOG"
1124 git log --pretty=oneline HEAD^..HEAD >> "$LOG"
1125 echo "" >> "$LOG"
1130 if [[ $1 == -h ]]; then
1131 if [ $# -gt 1 ]; then
1132 PID=$2
1133 mods_info
1134 echo ""
1135 echo "The Auto-Patcher $VERSION by Mateorod and Pastime1971"
1136 echo "*************************************************"
1137 echo ""
1138 echo "Mod Name: $PID"
1139 echo ""
1140 echo " $DESC"
1141 if [[ $DESC1 ]]; then # test to see is there is a second DESC line
1142 echo " $DESC1"
1144 if [[ $DESC2 ]]; then
1145 echo -n "$DESC2"
1147 echo ""
1148 echo "Developer: $DEV"
1149 echo "Dependancies: $DEPENDENCY"
1150 if [[ $WEBSITE ]]; then
1151 echo "Website: $WEBSITE"
1153 echo ""
1154 echo "Works on ROMs from Android $FLOOR -> $CEILING"
1155 echo
1156 brief_help
1157 exit
1161 [[ $# -lt 1 || -z $1 ]] && PID="mods" && mods_info
1162 [[ $1 == "-h" ]] && usage_help | less && display_help
1164 echo ""
1165 echo "The Auto-Patcher $VERSION"
1166 # by pastime1971 and mateorod
1167 if [[ -n "$AUTO_PATCHER_WAS_UPDATED" ]]; then
1168 echo " (auto-updated from $AUTO_PATCHER_OLD_VERSION)"
1169 print_changelog
1171 echo ""
1173 ROOT="$(abspath "$(dirname "$(abspath "$(type -p "$0")")")")"
1174 TOOL="$ROOT/patch_tools.tgz"
1175 PTCH="$ROOT/patch_patches.tgz"
1176 cleanup
1177 # set temporary directory
1178 DATE=$(date +%Y%m%d%H%M%S)
1179 TEMP="$ROOT/tmp$DATE"
1180 TMP="$ROOT/tmp$DATE"
1181 TMPDIR="$ROOT/tmp$DATE"
1182 mkdir "$TEMP"
1183 ROM=$(abspath "$1")
1184 ROMX=$(extpath "$1")
1185 PATCH_BINARY=patch
1186 PINGCOUNT="-c1"
1188 if [[ $OSTYPE == "cygwin" ]]; then
1189 CYGWIN=true
1190 EXE=".exe"
1191 PGFORM="0x"
1192 PINGCOUNT="-n 1"
1193 #PATCH_BINARY="./patch"
1194 AUTO_UPDATE=false # CYGWIN AUTO_UPDATE TESTERS COMMENT THIS LINE HERE!
1197 PING_CHECK() {
1198 case $(uname -s) in
1199 [Dd]arwin*)
1200 (ping "$PINGCOUNT" "$@")
1203 (ping $@ $PINGCOUNT)
1205 esac
1209 LOG=$(abspath ./log$DATE.txt)
1210 #echo $ROOT $TOOL $ROM $TEMP "$LOG"
1211 echo "ROOT= $ROOT" >> "$LOG"
1212 echo "TOOL= $TOOL" >> "$LOG"
1213 echo "ROM= $ROM" >> "$LOG"
1214 echo "ROMX= $ROMX" >> "$LOG"
1217 # Auto-Update # excluding ApG/cygwin for now until I talk with kobik.
1218 # To turn off auto updating, set AUTO_UPDATE in .config to false
1221 # Check for git
1222 if [ $(which git) ]; then
1223 GIT=true
1224 else
1225 miss_git_error "Missing \"git\" utility"
1226 GIT=false
1229 if [[ "$AUTO_UPDATE" == true ]] && [[ "$GIT" == true ]]; then
1230 PING_CHECK "www.github.com" > /dev/null 2>&1 && NETWORK=true || no_network_access
1231 if [[ "$NETWORK" == true ]]; then
1232 printtask "### checking for updates ###"
1234 # establish the repo if not already present- one time operation.
1235 if [ ! -d ".git" ]; then
1236 printtask "... initial setup to allow automatic updating ..."
1237 backup_script && warn_of_overwrite
1238 establish_repo && export_log_and_variables
1239 printtask "### rerunning script with latest version ###"
1240 $0 "$@"
1241 exit 0
1244 # Here is the regular update process
1245 git fetch origin 2>&1 >> "$LOG" || no_network_access
1246 if !("$NETWORK"); then
1247 printtask "Updater: not able to run auto_update."
1248 else
1249 COMMITS_BEHIND=$(git rev-list HEAD..origin/master --count)
1250 case "$COMMITS_BEHIND" in
1252 printtask "Updater: Auto-Patcher is already up to date"
1255 ORIGINAL_HEAD=$(git rev-parse HEAD)
1256 printtask "... Updater: update found ..."
1257 backup_script
1258 printtask "... Updating Auto-Patcher ..."
1259 git merge --no-edit origin/master 2>&1 >> "$LOG" || auto_update_error
1260 export_log_and_variables
1261 printtask "### updated, now rerunning script with latest version ###"
1262 $0 "$@"
1263 exit 0
1265 esac
1266 echo ""
1271 if ( [[ -n "$AUTO_PATCHER_WAS_UPDATED" ]] || [ -f *".updated.log" ] ); then
1272 ORIGINAL_PATCHES_VERSION=$( ls *.updated.log | sed -e 's/\.updated.log//' )
1273 if ( [[ $PATCHES_VERSION -gt $AUTO_PATCHER_OLD_PATCHES_VERSION ]] || [[ $PATCHES_VERSION -gt $ORIGINAL_PATCHES_VERSION ]] ); then
1274 echo "... integrating new patches ..."
1275 sh batch.sh >> /dev/null 2>> "$LOG"
1279 # If program was updated, merge the logs
1280 if ( [[ -n "$AUTO_PATCHER_WAS_UPDATED" ]] || [ -f *".updated.log" ] ); then
1281 cat *".updated.log" >> "$LOG"
1282 rm -f *".updated.log"
1285 #remove old zips, if built under identical parameters.
1286 \rm -f $RESTORE.zip $UPDATE.zip
1288 CHK=$(getconf LONG_BIT)
1289 if [[ $CHK = "64" ]]; then
1290 BIT=64
1291 else [[ $BIT = "32" ]];
1292 BIT=32
1295 printtask "### verify tools ###"
1297 if [[ $CYGWIN == false ]];then
1298 which patch >> "$LOG" || misstools_error "Missing \"patch\" utility."
1300 which tar >> "$LOG" || misstools_error "Missing \"tar\" utility"
1301 which jar >> "$LOG" || misstools_error "Missing \"Java Development Kit\" (JDK)"
1302 which java >> "$LOG" || misstools_error "Missing \"Java Development Kit\" (JDK)"
1303 which cpio >> "$LOG" || misstools_error "Missing \"cpio\" utility"
1304 [ -f "$TOOL" ] || misspatch_error "patch_tool.tgz is missing"
1305 [ -f "$PTCH" ] || misspatch_error "patch_patches.tgz is missing"
1306 printtask "### verify ROM ###"
1307 [ -f "$ROM" ] || print_error "Cannot find $1!! Make sure you have the location and name right"
1308 echo "### running $0 $@" >> "$LOG"
1309 cd "$TEMP"
1311 PATH="$TEMP:$PATH"
1312 export PATH
1313 echo "PATH= $PATH" >> "$LOG"
1315 printtask "### unzip patch tools ###"
1316 tar xzf "$TOOL" > /dev/null || print_error "failed extracting tools !!!"
1318 # Get OS specific tools
1319 case $(uname -s) in
1320 CYGWIN*)
1321 \mv cygwin/aapt.exe .
1322 \mv cygwin/patch.* .
1323 \mv cygwin/*.exe boot/
1324 \rm -rf cygwin # why? If you want to we can keep/add it to mac/linux, though.
1326 [Dd]arwin)
1327 \mv mac/aapt .
1329 [Ll]inux)
1330 \mv linux/aapt .
1333 \mv linux/aapt .
1335 esac
1336 # Ensure aapt permissions - possibly to one day be expanded to all tools in a function.
1337 chmod a+x aapt$EXE
1339 printtask "### unzip patch patches ###"
1340 tar xzf "$PTCH" > /dev/null || print_error "failed extracting patches !!!"
1342 # we need build.prop for both RIL probing and ROM probing
1343 jar -xvf "$ROMX" system/build.prop 2>> "$LOG" || print_error "failed extracting build.prop from $ROMX !!!"
1345 # rom + ril type
1346 proberil
1347 printtask "### probe rom type ###"
1348 proberom
1350 # rom type
1351 if [ $# -gt 1 ]; then
1352 PIT=$2
1353 if [[ "$PIT" = "-h" ]]; then
1354 display_help
1358 if [ $# -gt 2 ]; then
1359 RID=$3
1360 case "$RID" in
1361 cm*|cyanogenmod*)
1362 RID=cm;
1364 aokp*|teamkang)
1365 RID=aokp;
1367 pa*)
1368 RID=pa;
1370 .aosp-ever)
1371 RID=".aosp-ever";
1373 .aosp-slim)
1374 RID=".aosp-slim"
1376 .aosp-pac)
1377 RID=".aosp-pac"
1379 aosp*)
1380 case "ANDR" in
1381 4.1)
1382 RID=$(aosp_mod_check);
1385 RID=$(ever_check)
1387 esac
1389 201*)
1390 date_error "You must specify ROMTYPE if designating a patch date!!"
1393 rom_error "$RID is not a valid ROMTYPE!!"
1395 esac
1396 romtype_set
1397 echo "... Using $ROMTYPE patches ..."
1398 else
1399 echo "... Using results of ROM check ..."
1402 # patch type
1403 if [ $# -gt 1 ]; then
1404 PIL=${2//,/ } # If more than one mod, make string separated by spaces
1405 else
1406 PIL="openpdroid"
1407 echo "No mods selected. Defaulting to openpdroid, since that's what you probably want..."
1410 # Ensure only 1 Pdroid mod at a time; PDroid first, so provisionals do not overwrite other mods...
1412 PID=(${PIL// / }) # turn string of requested mods into array
1413 COPYPID=("${PID[@]}") # working copy to iterate over
1414 MODS_NUMBER=${#COPYPID[@]} # number of elements (mods)
1416 if [[ $MODS_NUMBER > 1 ]]; then # because if only one mod, not needed
1417 INDEX=0
1418 for p in ${COPYPID[@]}; do
1419 # this first loop detects presence of any pdroid mod and sets it to be first applied (SPID[0])
1420 if [ "$p" = "pdroid" ] || [ "$p" = "pd2.0" ] ||[ "$p" = "openpdroid" ]; then
1421 SPID[0]=$p #set pdroid first
1422 unset COPYPID["$INDEX"]
1423 break
1424 else
1425 INDEX=$((INDEX + 1)) # if (!pdroid), set as 1, 2...
1427 done
1428 for p in ${COPYPID[@]}; do
1429 # ensures they aren't applyingy more than one pdroid mod and slots in any remaining mods.
1430 if [ "$p" = "pdroid" ] || [ $p = "pd2.0" ] ||[ $p = "openpdroid" ]; then
1431 conflict_error "Those mods conflict! Only one pdroid mod at a time!"
1432 else
1433 i=${#SPID[@]}
1434 SPID[$i]=$p
1435 i+=1
1437 done
1438 else
1439 SPID=("${COPYPID[@]}")
1441 # reset the mod list, with the pdroid-type mod applied first (for provisional use's sake)
1442 PID=("${SPID[@]}")
1444 # Check if selected mods are available for rom's Android version.
1445 compat_check
1447 # Make sure mod and rom don't conflict (e.g. pa and tabletUI)
1448 for T in ${PID[@]}; do
1449 PID=$T #Set PID so mods_info function returns different values for each mod
1450 mods_info
1451 if [[ ${ROM_CONFLICTS[@]} != "None" ]]; then
1452 rom_compat_check
1454 done
1455 # reset to original ordered list
1456 PID=("${SPID[@]}")
1458 # Build date
1459 if [ $# -gt 3 ]; then # if a date is specified on command line...
1460 # Set date to match argument and ensure that patches with that date exist
1461 BID=$4
1462 [ -d patches/$PID/$ANDR/$RID/$BID ] || print_error "No $PID patches for $RID on $BID!! Try the help menu!!"
1463 # Run build_query- this overrides the above but gets useful info
1464 build_query
1465 # Reset patch date to argument (basically undo the effects of the build_query call)
1466 BID=$4
1467 printtask "... $PID patch date set manually to: $BID ..."
1468 PATCH_DATE_LIST[0]=$BID
1469 else
1470 build_query # if no date specified, use one from build_query
1473 # echo ROM info
1474 rominfo
1476 if [[ ( "$PID" == "-h" || "$RID" == "-h" || "$BID" == "-h" ) ]]; then
1477 #Although this placement may be perfect for romfilter. although it throws the scheme...
1478 display_help
1480 #Begin cycle
1482 for P in ${PID[@]}; do
1483 [ -d patches/$P ] || print_error "$P is not available"
1484 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1485 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1486 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1488 unset FILES
1489 [ -f patches/$P/files.txt ] && FILES=$(cat patches/$P/files.txt)
1490 [ -f patches/$P/$A/files.txt ] && FILES=$(cat patches/$P/$A/files.txt)
1491 [ -f patches/$P/$A/$R/files.txt ] && FILES=$(cat patches/$P/$A/$R/files.txt)
1492 [ -f patches/$P/$A/$R/$B/files.txt ] && FILES=$(cat patches/$P/$A/$R/$B/files.txt)
1493 for FILE in ${FILES[@]}; do
1494 case "$FILE" in
1495 +system/*)
1496 [[ ${CID[@]} =~ ${FILE:1} ]] && print_error "${FILE:1} is already being copied" || CID=(${CID[@]} ${FILE:1})
1498 -system/*)
1499 [[ ${EID[@]} =~ ${FILE:1} ]] || EID=(${EID[@]} ${FILE:1})
1501 system/*.jar)
1502 [[ ${JID[@]} =~ $FILE ]] || JID=(${JID[@]} $FILE)
1503 echo "set_perm(0, 0, 0644, \"/$FILE\");" >> UPDATE.txt
1505 # added for the use-case of apktool failure
1506 @system/*apk) # apks to decompile with smali binaries instead of apktool
1507 [[ ${JID[@]} =~ ${FILE:1} ]] || JID=(${JID[@]} ${FILE:1})
1508 FORMATTED_FILE=${FILE:1}
1509 echo "set_perm(0, 0, 0644, \"/$FORMATTED_FILE\");" >> UPDATE.txt
1511 system/*.apk)
1512 [[ ${AID[@]} =~ $FILE ]] || AID=(${AID[@]} $FILE)
1513 echo "set_perm(0, 0, 0644, \"/$FILE\");" >> UPDATE.txt
1514 # $APKID will have elements removed sometimes--$AID is the master list for the update.zip
1515 declare -a APKID=( "${AID[@]}" )
1517 *.img)
1518 [[ ${IID[@]} =~ $FILE ]] || IID=(${IID[@]} $FILE)
1520 system/*)
1521 [[ ${TID[@]} =~ $FILE ]] || TID=(${TID[@]} $FILE)
1523 esac
1524 done
1525 done
1526 echo "### DELETE FILES= ${EID[@]}" >> "$LOG"
1527 echo "### COPY FILES= ${CID[@]}" >> "$LOG"
1528 echo "### JAR FILES= ${JID[@]}" >> "$LOG"
1529 echo "### APK FILES= ${AID[@]}" >> "$LOG"
1530 echo "### IMG FILES= ${IID[@]}" >> "$LOG"
1531 echo "### TXT FILES= ${TID[@]}" >> "$LOG"
1533 # extract system files
1534 printtask "### unzip rom ###"
1535 jar -xvf "$ROMX" ${JID[@]} ${AID[@]} ${IID[@]} ${TID[@]} 2>> "$LOG" || print_error "failed extracting ${JID[@]} ${AID[@]} ${IID[@]} from $ROMX !!!"
1538 # Update/Restore.zip scripts and prep
1539 printtask "### create updater script ###"
1540 UPDATER_LOC=META-INF/com/google/android
1541 UPDS=updater-script
1542 UPDATE="update-$ROMTYPE-$DID-$BDID-${PIL// /-}"
1543 RESTORE="restore-$ROMTYPE-$DID-$BDID"
1545 jar -xvf "$ROMX" $UPDATER_LOC/$UPDS $UPDATER_LOC/update-binary
1546 jar -xvf "$ROMX" $UPDATER_LOC/update-binary-installer 1> /dev/null 2> /dev/null
1548 # Determine Installer- Aroma or ClockworkMod
1549 if [ -f $UPDATER_LOC/update-binary-installer ]; then
1550 printtask "... using Aroma installer ..."
1551 \mv $UPDATER_LOC/update-binary-installer $UPDATER_LOC/update-binary
1552 else
1553 printtask "... using Clockworkmod installer ..."
1556 # Create updater scripts
1557 cat patches/.common/updater-message.txt >> $UPDS
1558 cat $UPDATER_LOC/$UPDS | grep ^mount | grep "/system" | head -n 1 >> $UPDS
1559 [ -s $UPDS ] || echo "run_program(\"/sbin/busybox\", \"mount\", \"/system\");" >> $UPDS
1560 # restore the original
1561 for FILE in ${EID[@]}; do
1562 jar -xvf "$ROMX" $FILE 2> /dev/null || printtask "!!! warning $FILE cannot be restored !!!"
1563 done
1564 # replace with the original or delete it
1565 for FILE in ${CID[@]}; do
1566 jar -xvf "$ROMX" $FILE 2> /dev/null || echo "delete(\"/$FILE\");" >> $UPDS
1567 done
1568 echo "package_extract_dir(\"system\", \"/system\");" >> $UPDS
1569 # permission management for files that need specific perms
1570 cat $UPDATER_LOC/$UPDS | grep set_perm | grep "/system" >> $UPDS
1571 for P in ${PID[@]}; do
1572 if [ -s patches/$P/$A/set_perm.txt ]; then
1573 echo "...setting permissions..."
1574 cat patches/$P/$A/set_perm.txt >> $UPDS
1576 done
1577 cat $UPDATER_LOC/$UPDS | grep ^unmount | grep "/system" | head -n 1 >> $UPDS
1578 [[ ${IID[@]} =~ boot.img ]] && cat $UPDATER_LOC/$UPDS | grep "boot.img" >> $UPDS
1579 echo "ui_print(\" .\");" >> $UPDS
1580 echo "ui_print(\" .\");" >> $UPDS
1581 echo "ui_print(\" done!\");" >> $UPDS
1582 cat $UPDS > $UPDATER_LOC/$UPDS
1583 echo "# generated $UPDS" >> "$LOG"
1584 cat $UPDS >> "$LOG"
1586 printtask "### create restore.zip ###"
1587 jar -cvf tmp.zip ${JID[@]} ${AID[@]} ${IID[@]} META-INF > /dev/null 2>> "$LOG"
1588 java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip signed.zip 2>> "$LOG"
1589 \mv signed.zip $RESTORE.zip
1590 \rm -f tmp.zip
1593 # Begin patching process
1595 # decompile system files
1596 printtask "### decompile system files ###"
1597 for FILE in ${JID[@]}; do
1598 JAR=${FILE##*/}
1599 printtask "... decompile $JAR ..."
1600 java -jar baksmali.jar -b -a $API -o tmp/${FILE}.out/smali ${FILE} >> "$LOG" 2>> "$LOG"
1601 if [ $FILE == "system/framework/framework.jar" ]; then
1602 printtask "... extract preloaded-classes ..."
1603 jar -xvf ${FILE} preloaded-classes >> "$LOG" 2>> "$LOG"
1604 \mv preloaded-classes tmp/${FILE}.out/
1606 done
1608 # install framework-files for APK...
1609 if [ ${#AID[@]} -gt 0 ]; then
1610 jar -xvf "$ROMX" system/framework/framework-res.apk >> "$LOG"
1611 printtask "... installing framework files ..."
1612 java -jar apktool.jar if system/framework/framework-res.apk
1613 # Decompile APKs
1614 for FILE in ${AID[@]}; do
1615 APK=${FILE##*/}
1616 if [ -f $FILE ]; then
1617 printtask "... decompile $APK ..."
1618 java -jar apktool.jar d -f $FILE tmp/$FILE.out 2>> "$LOG"
1620 done
1623 # Unpack image files {boot.img only so far...}
1624 for FILE in ${IID[@]}; do
1625 printtask "### unpacking $FILE ###"
1626 case "$FILE" in
1627 boot.img)
1628 if [ -f boot.img ]; then
1629 cd boot
1630 ./unpackbootimg$EXE -i ../boot.img >> "$LOG" 2>> "$LOG"
1631 mkdir ramdisk
1632 cd ramdisk
1633 gzip -dc ../boot.img-ramdisk.gz | cpio -i >> "$LOG" 2>> "$LOG"
1634 cd ../../
1635 else
1636 print_error "A mod needs to patch boot.img! This rom does not contains boot.img."
1640 print_error "cannot process $FILE"
1642 esac
1643 done
1645 # apply system modification
1647 for ((i=0; i < ${#PID[@]}; i++)); do
1648 P=${MODS_LIST[$i]}
1649 BID=${PATCH_DATE_LIST[$i]}
1650 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1651 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1652 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1653 PAR=patches/$P/$A/$R
1654 PARB=patches/$P/$A/$R/$B
1656 unset FILES COPY DELS JARS APKS IMGS TXTS
1657 [ -f patches/$P/files.txt ] && FILES=$(cat patches/$P/files.txt)
1658 [ -f patches/$P/$A/files.txt ] && FILES=$(cat patches/$P/$A/files.txt)
1659 [ -f patches/$P/$A/$R/files.txt ] && FILES=$(cat patches/$P/$A/$R/files.txt)
1660 [ -f patches/$P/$A/$R/$B/files.txt ] && FILES=$(cat patches/$P/$A/$R/$B/files.txt)
1661 for FILE in ${FILES[@]}; do
1662 case $FILE in
1663 +system/*)
1664 COPY=(${COPY[@]} ${FILE:1})
1666 -system/*)
1667 DELS=(${DELS[@]} ${FILE:1})
1669 system/*.jar)
1670 JARS=(${JARS[@]} $FILE)
1672 @system/*)
1673 JARS=(${JARS[@]} ${FILE:1})
1675 system/*.apk)
1676 APKS=(${APKS[@]} $FILE)
1678 *.img)
1679 IMGS=(${IMGS[@]} $FILE)
1681 system/*)
1682 TXTS=(${TXTS[@]} $FILE)
1684 esac
1685 done
1687 [[ -n ${COPY[@]} ]] && echo "### copy patch $P/$A/$ROMTYPE/$B ###"
1688 echo "### copy patch $P/$A/$R/$B ###" >> "$LOG"
1689 for FILE in ${COPY[@]}; do
1690 printtask "... copying $FILE ..."
1691 DEST=${FILE%/*}
1692 mkdir -p ./$DEST
1693 if [ -e patches/$P/$A/$R/$B/$FILE ]; then
1694 printtask "... overwriting $FILE from $P ..."
1695 \cp -av patches/$P/$A/$R/$B/$FILE ./$DEST >> "$LOG" 2>&1
1696 elif [ -e patches/$P/common/$FILE ]; then
1697 printtask "... overwriting $FILE from $P ..."
1698 echo " ### SOMETHING WENT WRONG!! Could not find file-- using common. ###" >> "$LOG"
1699 \cp -av patches/$P/common/$FILE ./$DEST >> "$LOG" 2>&1
1700 else
1701 print_error "$FILE is missing in the patch. Please upload your logfile to the support thread!"
1703 done
1705 # unconditional smali copying- For particularly troublesome files
1706 [ -f patches/$P/smali.txt ] && SMALI=$(cat patches/$P/smali.txt)
1707 [ -f patches/$P/$A/smali.txt ] && SMALI=$(cat patches/$P/$A/smali.txt)
1708 [ -f patches/$P/$A/$R/smali.txt ] && SMALI=$(cat patches/$P/$A/$R/smali.txt)
1709 [ -f patches/$P/$A/$R/$B/smali.txt ] && SMALI=$(cat patches/$P/$A/$R/$B/smali.txt)
1710 MOVE=${SMALI##*/}
1711 for SMALI in ${SMALI[@]}; do
1712 if [ -f patches/$P/$A/$R/$B/$SMALI ]; then
1713 printtask "... overwriting $MOVE ..."
1714 \cp -a patches/$P/$ANDR/$R/$B/$SMALI tmp/$SMALI >> "$LOG" 2>&1
1715 # This lower area should be deprecated now...wait and see. Each BID has own link to provisionals now.
1716 elif [ -f patches/$P/$A/.provisionals/$SMALI ]; then
1717 printtask "... overwriting $MOVE ..."
1718 \cp -a patches/$P/$ANDR/.provisionals/$SMALI tmp/$SMALI >> "$LOG"
1720 done
1722 [[ -n ${DELS[@]} ]] && echo "### delete patch $P/$A/$ROMTYPE/$B ###"
1723 echo "### delete patch $P/$A/$R/$B ###" >> "$LOG"
1724 for FILE in ${DELS[@]}; do
1725 printtask "... deleting $FILE ..."
1726 \rm -rf ./$FILE
1727 done
1728 [[ -n ${JARS[@]} ]] && echo "### jar patch $P/$A/$ROMTYPE/$B ###"
1729 echo "### jar patch $P/$A/$R/$B ###" >> "$LOG"
1731 # Iterate through jars and patch. If fails, try prepatched provisionals or look for alternative patch.
1732 for (( current_jar=0; current_jar < ${#JARS[@]}; current_jar++)); do
1733 FILE=${JARS[$current_jar]}
1734 JAR=${FILE##*/}
1735 if [[ $FILE == *".jar" ]]; then # allows for *.apks to be decompiled by baksmali
1736 NAME=${JAR%.jar}
1737 else
1738 # check for abscense of any apks decompiled by baksmali (~* in files.txt). Missing jars will still error
1739 if [ ! -d "tmp/${FILE}.out" ] ; then
1740 echo "No $JAR in your ROM. Not able to patch this file."
1741 echo "## No $JAR in ROM ###" >> "$LOG"
1742 declare -a JID=( ${JID[@]/$FILE/} )
1743 break;
1745 NAME=$JAR # TODO: Maybe rename this, since it now encompases apks at times
1747 printtask "... apply $NAME.patch ..."
1748 $PATCH_BINARY -Nls -p1 -d tmp/${FILE}.out < $PARB/${NAME}.patch 2>&1 > ${JAR}.log
1749 for INCREMENTAL in $(ls $PARB/${NAME}-*.patch 2>/dev/null); do
1750 printtask "... apply $(basename $INCREMENTAL) ..."
1751 $PATCH_BINARY -Nls -p1 -d tmp/${FILE}.out < $INCREMENTAL 2>&1 >> ${JAR}.log
1752 done
1753 cat ${JAR}.log >> "$LOG"
1754 case "$NAME" in
1755 framework)
1756 # patch preloaded-classes only if a patch exists
1757 if [ -f $PARB/preloaded.patch ]; then
1758 printtask "... apply preloaded.patch ..."
1759 $PATCH_BINARY -Nls -p1 -d tmp/${FILE}.out < $PARB/preloaded.patch 2>&1 > preloaded.log
1760 cat preloaded.log >> "$LOG"
1761 [[ $(grep FAILED preloaded.log) != "" ]] && print_error "failed preloaded.patch"
1765 echo -n "" # do nothing else
1767 esac
1768 # substitute failed smali with provisional (a prepatched smali file)
1769 unset FAILS
1770 FAILS=($(grep FAILED ${JAR}.log | sed -e 's/.*smali\///' | sed -e 's/\.rej//'))
1771 ALT_PATCH_NUMBER=2
1772 if [[ -n ${FAILS[@]} ]]; then
1773 print_to_log "!!! PATCHING FAILED FOR ${FAILS[@]} !!!"
1774 echo "### replace ${FAILS[@]} ###" > ${JAR}.log
1775 for FAIL in ${FAILS[@]}; do
1776 PROVISIONAL="patches/$P/$ANDR/.provisionals/${FILE}.out/smali/${FAIL}"
1777 ALTERNATIVE_PATCH=$(ls $PARB/${NAME}$ALT_PATCH_NUMBER*.patch 2>/dev/null)
1778 if [ ! -f "$PROVISIONAL" ]; then
1779 if [ -f "$ALTERNATIVE_PATCH" ]; then
1780 printtask "## trying alternative ${NAME} patch ###"
1781 prep_alternate_patch
1782 else
1783 print_error "failed $FAIL in $JAR cannot be remedied"
1785 else
1786 echo "!!! patch error for $FAIL !!!" >> "$LOG"
1787 [[ ${SID[@]} =~ $FAIL ]] && print_error "$FAIL was already replaced before"
1788 copy_prepatched_provisional
1790 done
1792 [[ $(grep FAILED ${JAR}.log) != "" ]] && print_error "failed $NAME.patch"
1793 garbage tmp/${FILE}.out
1795 # run special $JAR.sh scripts if any JAR needs special attention
1796 if [ -f patches/$P/$A/$R/$B/${JAR}.sh ]; then
1797 printtask "... apply $JAR.sh ..."
1798 . patches/$P/$A/$R/$B/${JAR}.sh 2>&1 > ${JAR}.log
1799 cat ${JAR}.log | tee -a "$LOG"
1801 done
1803 [[ -n ${APKS[@]} ]] && echo "### apk patch $P/$A/$ROMTYPE/$B ###"
1804 echo "### apk patch $P/$A/$R/$B ###" >> "$LOG"
1805 for FILE in ${APKS[@]}; do
1806 APK=${FILE##*/}
1807 if [ -d "tmp/${FILE}.out" ] ; then
1808 printtask "... apply $APK.patch ..."
1809 $PATCH_BINARY -Nls -p2 -d tmp/${FILE}.out < $PARB/${APK}.patch 2>&1 > ${APK}.log
1810 cat ${APK}.log >> "$LOG"
1812 if [[ $(grep FAILED ${APK}.log) != "" ]]; then
1813 apk_copy
1814 declare -a APKID=( ${APKID[@]/$FILE/} )
1816 garbage tmp/${FILE}.out
1817 else
1818 echo "No $APK in your ROM. Not able to patch this file."
1819 echo "## No $APK in ROM ###" >> "$LOG"
1821 done
1822 [[ -n ${IMGS[@]} ]] && echo "### img patch $P/$A/$ROMTYPE/$B ###"
1823 echo "### img patch $P/$A/$R/$B ###" >> "$LOG"
1824 for FILE in ${IMGS[@]}; do
1825 IMG=${FILE##*/}
1826 printtask "... applying $IMG.patch ..."
1827 $PATCH_BINARY -Nls -p1 -d boot/ramdisk < $PARB/${IMG}.patch >> "$LOG" || print_error "failed patching $FILE"
1828 done
1830 # Text Editing Functions --this can really do just about anything. Needs a working restore!
1831 [[ -n ${TXTS[@]} ]] && echo "### text patch $P/$A/$ROMTYPE/$B ###"
1832 echo "### text patch $P/$A/$R/$B ###" >> "$LOG"
1833 for FILE in ${TXTS[@]}; do
1834 TXT=${FILE##*/}
1835 if [[ -f $PARB/${TXT}.patch ]]; then
1836 printtask "... apply $TXT.patch ..."
1837 $PATCH_BINARY -Nls -p2 -d system/ < $PARB/${TXT}.patch 2>&1 > ${TXT}.log
1838 #cat ${TXT}.log | tee -a "$LOG"
1839 [[ $(grep FAILED ${TXT}.log) != "" ]] && print_error "failed $TXT.patch"
1841 if [[ -f $PAR/${TXT}.awk ]]; then
1842 printtask "... apply $TXT.awk ..."
1843 awk -f $PAR/${TXT}.awk $FILE > text || print_error "failed $TXT.awk"
1844 mv text $FILE
1846 if [[ -f $PAR/${TXT}.sed ]]; then
1847 printtask "... apply $TXT.sed ..."
1848 sed -f $PAR/${TXT}.sed $FILE > text || print_error "failed $TXT.sed"
1849 mv text $FILE
1851 if [[ -f $PAR/${TXT}.sh ]]; then
1852 printtask "... apply $TXT.sh ..."
1853 . $PAR/${TXT}.sh 2>&1 >> ${TXT}.log || print_error "failed $TXT.sh"
1855 garbage system/
1856 done
1857 done
1859 # Device specific scripts- Placement is up-for-review
1860 if [ -f patches/.devices/$DID/$DID.sh ]; then
1861 . patches/.devices/$DID/$DID.sh
1864 # Replace updater-script for CM7- it formats system -Testing
1865 if [ "$ANDR" == "gingerbread" ]; then
1866 replace_updater
1869 # Rebuilding system files
1871 [[ -n ${JID[@]} ]] && printtask "### rebuild jar ###"
1872 for FILE in ${JID[@]}; do
1873 JAR=${FILE##*/}
1874 printtask "... rebuild $JAR ..."
1875 java -Xmx512M -jar smali.jar -a $API tmp/${FILE}.out/smali -o tmp/${FILE}.out/classes.dex >> "$LOG" 2>> "$LOG"
1876 [ -f tmp/${FILE}.out/classes.dex ] || smali_error "failed compiling $JAR !!!"
1877 jar -ufv ${FILE} -C tmp/${FILE}.out/ classes.dex >> "$LOG" 2>> "$LOG"
1878 if [ $FILE == "system/framework/framework.jar" ]; then
1879 jar -ufv ${FILE} -C tmp/${FILE}.out/ preloaded-classes >> "$LOG" 2>> "$LOG"
1881 done
1883 [[ -n ${APKID[@]} ]] && printtask "### rebuild apk ###"
1884 for FILE in ${APKID[@]}; do
1885 APK=${FILE##*/}
1886 if [ -d tmp/${FILE}.out ]; then
1887 apk_was_copied=false
1888 printtask "... rebuild $APK ..."
1889 java -jar apktool.jar b tmp/${FILE}.out >> "$LOG" 2>> "$LOG" || apk_copy
1890 if !("$apk_was_copied"); then
1891 jar -uvf $FILE -C tmp/${FILE}.out/build/apk/ . > /dev/null 2>> "$LOG"
1894 done
1896 [[ -n ${IID[@]} ]] && printtask "### rebuild img ###"
1897 for FILE in ${IID[@]}; do
1898 printtask "### rebuild $FILE ###"
1899 case $FILE in
1900 boot.img)
1901 # Rebuilding boot.img
1902 cd boot
1903 printtask "... rebuilding ramdisk ..."
1904 ./mkbootfs$EXE ./ramdisk | gzip > ramdisk-new.gz
1905 printtask "... composing boot.img ..."
1906 BASE=$(cat boot.img-base)
1907 # hex to decimal in cygwin prefixing "0x" w/ C arithmetic
1908 PGSIZE=$((${PGFORM}$(cat boot.img-pagesize)))
1909 CMDLINE=$(cat boot.img-cmdline)
1910 echo "cmdline = no_console_suspend=1 console=null $CMDLINE" >> "$LOG"
1911 echo "pagesize = $PGSIZE" >> "$LOG"
1912 echo "base = $BASE" >> "$LOG"
1913 printtask "... rebuilding boot.img ..."
1914 ./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"
1915 cd ..
1918 print_error "cannot process $FILE"
1920 esac
1921 done
1923 printtask "### create $UPDATE.zip ###"
1924 jar -cfv tmp.zip ${IID[@]} ${JID[@]} ${AID[@]} ${CID[@]} ${TID[@]} META-INF >> "$LOG" 2>> "$LOG"
1925 java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip $UPDATE.zip 2>> "$LOG"
1927 \mv $RESTORE.zip $UPDATE.zip ..
1928 printtask "### finished ###"
1929 printtask ""
1930 printtask "$(colorize_bold ${red}Congratulations), the patching was $(colorize_bold ${red}successful)."
1931 printtask "Any errors you may have seen were succesfully handled!"
1932 printtask ""
1933 printtask "!!! Only file a bug report if the software is $(colorize_bold ${grn}not) behaving as expected !!!"
1934 printtask ""
1935 echo "to install patched files, flash:"
1936 printtask "---$(colorize_bold ${grn}$UPDATE.zip)"
1937 echo ""
1938 printtask "to restore original system, flash:"
1939 printtask "---$(colorize_bold ${grn}$RESTORE.zip)"
1940 echo ""
1942 # add announcement- optional.
1943 for P in ${PID[@]}; do
1944 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1945 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1946 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1947 if [ -f patches/$P/$A/$R/$B/README.txt ]; then
1948 cat patches/$P/$A/$R/$B/README.txt
1949 elif [ -f patches/$P/$A/$R/README.txt ]; then
1950 cat patches/$P/$A/$R/README.txt
1951 elif [ -f patches/$P/$A/README.txt ]; then
1952 cat patches/$P/$A/README.txt
1954 done
1956 cd ..
1957 \rm -rf "$TEMP"