Hide the "tpu not found" errors in Cygwin
[auto-patcher.git] / auto_patcher
blob4e0d8d64302cafb627ff87bf3ef9d92eabf28d12
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. (2.9.875) New tabletUI patches, revert flawed CONFLICTS feature
140 # 2013.06.22. (2.9.88) New CM opd patches
141 # 2013.06.28. (2.9.89) revert baksmali changes for now (still needs work), add new PACman OPD 6/26
142 # 2013.07.02. (2.9.91) Switch to SlimRom team's aapt and apktool for OSX+Windows (Need OSX builder!)
143 # 2013.07.07. (2.9.92) New opd patches for Slim/PA; some fixes to tabletUi by Caldair
146 # SHELL PROGRAMMING NOTES:
147 # [ -s FILE ]
148 # [[ -n STRING ]] or [[ -z STRING ]]
150 VERSION="v2.9.9268"
151 # PATCHES_VERSION needs to be incremented every time ANY changes occur to patches.
152 PATCHES_VERSION="20130717"
153 CURRENT_ANDROID="4.2.2"
155 # Available ROMTYPES.
156 # ROMTYPES that are hidden can be forced on the command line. But they are best left
157 # blank to be automatically parsed by our romprobe or by just entering the parent...usually AOSP.
159 #Non-obvious ROMTYPE legend
160 # @.aosp-slim: SlimRom @.aosp-pac: PAC-man
161 # @.aosp-ever: Evervolv @pa: ParanoidAndroid (official jellybean branch only for now)
162 declare -a AVAILABLE_ROMTYPES=('aokp' 'aosp' 'cm' 'pa' '.aosp-slim' '.aosp-pac' '.aosp-ever')
164 # pass variables to children
165 set -a
167 # Set any environmental variables
168 LANG=C
170 # Config file: For now hosting AUTO_UPDATE and PRODUCTION(currently unused). Not under version control.
171 if [ ! -f .config ]; then
172 cp -a ap_scripts/config_template .config
174 source .config
176 # Colorize and add text parameters
177 red=$((tput setaf 1) 2>/dev/null) # red
178 grn=$((tput setaf 2) 2>/dev/null) # green
179 cyan=$((tput setaf 6) 2>/dev/null) # cyan
180 txtBold=$((tput bold) 2>/dev/null) # Bold
181 txtReset=$((tput sgr0) 2>/dev/null) # Reset
183 colorize () {
184 # pass color and then reset
185 echo -e $@${txtReset}
188 colorize_bold () {
189 echo -e ${txtBold}$@${txtReset}
192 printusage_help () {
193 PID="openpdroid,3gdongle" # default example
194 brief_help
197 brief_help () {
198 echo " usage: ./auto_patcher <ROM> <MODS> <ROMTYPE>"
199 echo " example: ./auto_patcher CM10.zip $PID cm"
200 echo ""
201 echo "Use ./auto_patcher -h for the help menu"
202 echo ""
203 cleanup
204 exit
207 usage_help () {
208 PID=mods
209 mods_display
210 echo "Multiple MODS can be combined by separating them with a comma and NO SPACES!!!"
211 echo ""
212 echo " usage: ./auto_patcher <ROM> <MODS> <ROMTYPE>"
213 echo ""
214 echo " example: ./auto_patcher CM10.zip openpdroid,3gdongle cm"
215 echo ""
216 usage_more_help
219 usage_more_help () {
220 echo "* press 'q' available patches or CTRL-c to quit the help menu *"
223 display_help () {
224 cd patches
225 echo ""
226 echo "AVAILABLE PATCHES"
227 echo ""
228 echo "*******************************************************************"
229 echo "Note: There are ONLY 4 ROMTYPES: [pa, cm, aokp, and aosp]."
230 echo ""
231 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
232 echo ""
233 echo "!!! Do not put Android Version number on command line !!!!"
234 echo "*****************************************************************"
235 echo "Specific auto_patcher script options"
236 echo " ./auto_patcher -h mods Lists mods"
237 echo " -h <MODNAME> Specific <MOD> info"
238 echo " -h advanced Advanced usage+lists all available patch dates"
239 echo ""
240 cleanup
241 exit
244 romtype_help () {
245 # From rom_error (bad romtype) and date_error (patch date w/o specifying romtype)
246 echo ""
247 echo "!!!There are only four supported ROMTYPES: 1) cm 2) aokp 3) aosp 4) pa"
248 echo ""
249 echo "Find out which of the above ROMTYPES your rom is based on and try again!"
250 echo "**********************************************"
251 echo ""
252 cleanup
253 brief_help
256 advanced_help () {
257 echo ""
258 echo "The Auto-Patcher Advanced Usage"
259 echo "*********************************"
260 echo ""
261 echo "For those of you determined to try everything..."
262 echo ""
263 echo "You can also try adding a patch date as a final argument."
264 echo ""
265 echo " ./auto_patcher <ROM> <MOD> <ROMTYPE> <DATE>"
266 echo ""
267 echo "Please note: There are only four ROMTYPES: {pa, aokp, aosp and cm}"
268 echo " -The various appellations after that are for internal use only!"
269 echo ""
270 echo "The Auto-Patcher has a pretty great rom probe, specifying the date is"
271 echo " deprecated...you don't need to, we promise."
272 echo ""
275 cleanup () {
276 [[ -n $ROOT ]] && \rm -rf "$ROOT"/tmp*
279 garbage () {
280 unset GARBAGE
281 GARBAGE=($(find $@ -name "*.orig")) && rm -rf ${GARBAGE[@]} && echo "GARBAGE= ${GARBAGE[@]}" >> "$LOG"
282 GARBAGE=($(find $@ -name "*.rej")) && rm -rf ${GARBAGE[@]} && echo "GARBAGE= ${GARBAGE[@]}" >> "$LOG"
286 print_error () {
287 # General purpose error. Used for errors in main, as opposed to probe or set-up.
288 echo ""
289 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
290 printtask "!!! error: $@"
291 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
292 echo ""
293 brief_help
296 smali_error () {
297 # Smali binary error. Problem often goes away on second run.
298 echo ""
299 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
300 printtask "!!! error: $@"
301 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
302 echo ""
303 if [[ $(grep 'method index is too large' "$LOG") != "" ]]; then
304 printtask "!!! Problem with method cap !!!"
305 printtask "... attempting fix ..."
306 . patches/.common/framework.jar.sh 2>&1 > ${JAR}.log
307 printtask "... rebuild framework.jar ..."
308 java -Xmx512M -jar smali.jar -a $API tmp/${FILE}.out/smali -o tmp/${FILE}.out/classes.dex >> "$LOG" 2>> "$LOG"
309 [ -f tmp/${FILE}.out/classes.dex ] || print_error "Could not resolve method cap issue- please submit log"
310 else
311 printtask "!!! This error is generally due to an unknown bug in the smali binary!"
312 echo "In our experience, it goes away if you run the patcher a second time."
313 echo " Please run the Auto-Patcher with the same command once again."
314 echo ""
315 echo "If after the third attempt the same thing happens,"
316 echo " please upload your logfile to our support thread!"
317 echo ""
318 cleanup
319 exit
323 unknown_mod_error () {
324 echo ""
325 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
326 printtask "!!! error: $@"
327 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
328 echo ""
329 cleanup
330 printusage_help
333 mismatch_error () {
334 # Function that exposes attempts to apply a mod to an upsupported Android version
335 echo ""
336 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
337 printtask "!!! error: $@"
338 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
339 echo ""
340 cleanup
341 brief_help
344 date_error () {
345 # Remind users to include a romtype if they are going to specify a patch date
346 echo ""
347 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
348 printtask "!!! error: $@"
349 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
350 echo ""
351 echo "Please put a ROMTYPE before the patch date and run again!!"
352 romtype_help
355 rom_error () {
356 # For when an unsupported romtype is manually entered on the command-line
357 echo ""
358 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
359 printtask "!!! error: $@"
360 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
361 romtype_help
364 conflict_error () {
365 # For conflicting packages
366 echo ""
367 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
368 printtask "!!! error: $@"
369 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
370 cleanup
371 PID=mods
372 mods_info
375 misspatch_error () {
376 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
377 printtask "!! error: $@ "
378 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
379 echo ""
380 printtask "!! The Auto-Patcher could not find its patches and/or tools!"
381 echo ""
382 echo "* Did you run ./batch.sh first?"
383 echo ""
384 echo "The patch_patches.tgz and patch_tools.tgz need to be in this directory,"
385 echo " one way or another..."
386 echo ""
387 cleanup
388 brief_help
391 misstools_error () {
392 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
393 printtask "!! error: $@ "
394 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
395 printtask "Your set-up is missing a dependency."
396 echo "We require JDK, tar, patch and cpio."
397 echo ""
398 echo ""
399 echo "Each distro is different"
400 echo "but ensure you have them all installed and try again."
401 echo ""
402 cleanup
403 brief_help
406 miss_git_error () {
407 printtask "Updater: disabled"
408 echo ""
409 printtask "You will not be able to get automatic updates because we could not find 'git'."
410 printtask "Find out how to install git for your system and that feature should work automatically"
411 echo ""
414 printtask () {
415 echo "" >> "$LOG"
416 echo -e $@ | tee -a "$LOG"
419 print_to_log () {
420 echo "$@" >> "$LOG"
423 copy_prepatched_provisional () {
424 print_to_log "File for which patching failed:"
425 print_to_log "---------------------------------------------"
426 print_to_log ""
427 print_to_log "${FAIL##*/}"
428 print_to_log ""
429 print_to_log "---------------------------------------------"
430 print_to_log ""
431 print_to_log "We are adding a pre-patched copy of those files."
432 print_to_log ""
433 print_to_log "Please only file a bug report if running the program gives you problems!!!"
434 print_to_log "... replace $FAIL ..."
435 \rm -rf tmp/${FILE}.out/smali/${FAIL} tmp/${FILE}.out/smali/${FAIL}.orig tmp/${FILE}.out/smali/${FAIL}.rej
436 \cp -av "$PROVISIONAL" tmp/${FILE}.out/smali/${FAIL} >> "$LOG" 2>&1
437 SID=(${SID[@]} $FAIL)
438 print_to_log "... failed patch sucessfully resolved ..."
441 prep_alternate_patch () {
442 # Use alt.patch, if exists. Increment in case there are multiple alternates.
443 mv -v $ALTERNATIVE_PATCH $PARB/${NAME}.patch >> "$LOG"
444 ALT_PATCH_NUMBER=$((PATCH_NUMBER + 1))
446 # Get fresh files/variables + decompile again (use rm b/c privacy files wouldn't get overwritten)
447 rm -rf tmp/${FILE}.out/smali
448 java -jar baksmali.jar -b -a $API -o tmp/${FILE}.out/smali ${FILE} >> "$LOG" 2>> "$LOG"
449 unset FAILS && unset SID
450 current_jar=$(($current_jar - 1))
451 break
454 no_network_access () {
455 ping -c1 www.github.com >> "$LOG" 2>&1 && NETWORK=true # second try and check github
456 ping -c1 www.google.com >> "$LOG" 2>&1 # test for internet in general
457 if [[ "$NETWORK" == true ]]; then
458 return
459 else
460 printtask "Check for update failed, probably because of no internet access."
461 echo "The autopatcher will continue with current local version: $VERSION"
462 NETWORK=false
463 echo ""
464 sleep 2
468 auto_update_error () {
469 echo ""
470 printtask "### Update failed ###"
471 printtask ""
472 printtask "It appears you may have made some changes to the script that prevent automatic updating."
473 printtask "You could run 'git reset --hard' to return the autopatcher to its original form"
474 printtask " or set AUTO_UPDATE to false in the .config file to stop getting this message."
475 echo ""
476 printusage_help
479 backup_script () {
480 printtask "... backing up auto_patcher to auto_patcher.bak ..."
481 cp -av auto_patcher auto_patcher.bak >> "$LOG" #backup for user in case of changes
482 echo ""
485 warn_of_overwrite () {
486 # Only seen once, by users without ".git" directories
487 # Only users who got program @ download page see this, all others (ApG included) use git
488 echo "This is a one time set-up process that will overwrite all local changes!"
489 echo "If this is not ok with you press ctrl-C and set AUTO_UPDATE to false in .config"
490 echo ""
493 establish_repo() {
494 printtask "### establishing the repo ###"
495 echo "... please be patient, this should only be needed once ..."
496 echo ""
497 git clone https://github.com/mateor/auto-patcher >> "$LOG" || no_network_access
498 if ($NETWORK); then
499 mv -v auto-patcher/".git" . >> "$LOG"
500 rm -rf auto-patcher
501 git checkout -q master || auto_update_error
502 git reset --hard 2>&1 >> "$LOG"
503 echo ""
507 export_log_and_variables () {
508 cp -a "$LOG" .updated.log
509 rm -If "$LOG"
510 AUTO_PATCHER_OLD_VERSION=$VERSION
511 AUTO_PATCHER_OLD_PATCHES_VERSION=$PATCHES_VERSION
512 AUTO_PATCHER_WAS_UPDATED=true
515 print_changelog () {
516 CHANGELOG="changelog.txt"
517 echo "" > "$CHANGELOG"
518 CURRENT_HEAD=$(git rev-parse HEAD)
519 echo "Changelog from Autopatcher$AUTO_PATCHER_OLD_VERSION to Autopatcher$VERSION" >> "$CHANGELOG"
520 echo "---------------------------------------------------------------------------" >> "$CHANGELOG"
521 echo "" >> "$CHANGELOG"
522 echo " Get more info about any individual commit by entering 'git show \$NUMBER'" >> "$CHANGELOG"
523 echo "" >> "$CHANGELOG"
524 git log --pretty=oneline $ORIGINAL_HEAD...$CURRENT_HEAD >> changelog.txt
525 printtask "... "$CHANGELOG" has been updated ..."
528 replace_updater () {
530 # Function for devices that use SDcard installs. Also to be tested for CM7
531 # since CM7 seems to use an updater-script that wipes EMMC. Testing
533 \rm $UPDATER_LOC/$UPDS 2>&1
534 \cp patches/.common/$UPDATER_LOC/$UPDS $UPDATER_LOC >> "$LOG" 2>&1
535 echo "run_program(\"/sbin/busybox\", \"umount\", \"/system\");" >> UPDATE.txt
536 cat UPDATE.txt >> $UPDATER_LOC/$UPDS
537 echo ""
538 echo "New updater-script being used:" >> "$LOG"
539 echo "-----------------------------" >> "$LOG"
540 cat $UPDATER_LOC/$UPDS >> "$LOG"
543 abspath () {
544 case $(uname -s) in
545 CYGWIN*)
546 echo $(cygpath -ua "$1") | sed 's:/$::g'
548 Darwin)
549 #[[ $(echo $1 | awk '/^\//') == $1 ]] && echo "$1" || echo "$PWD/$1"
550 [[ ${1:0:1} == "/" ]] && echo "$1" || echo "$PWD/$1"
552 Linux)
553 echo $(readlink -f "$1")
556 if [[ ${1:0:1} == "/" ]]; then
557 echo "$1"
558 elif [[ ${1:0:2} == "./" ]]; then
559 echo "$PWD/${1:2}"
560 else
561 echo "$PWD/$1"
564 esac
567 mods_display () {
568 echo ""
569 echo "The Auto-Patcher $VERSION"
570 echo "*******************************"
571 echo ""
572 echo "The available mods are"
573 echo "****************************************************"
574 echo "* pdroid openpdroid voice v6supercharger *"
575 echo "* voice insecure secure external_internal *"
576 echo "* tabletUI 3gdongle pd2.0 *"
577 echo "****************************************************"
578 echo ""
579 echo "To find out more about any mod, simply enter:"
580 echo " ./auto_patcher -h <MODNAME>"
581 echo ""
582 cleanup
585 mods_info () {
586 # Defaults
587 DEPENDENCY="None"
588 DEV="Unknown"
589 CEILING=$CURRENT_ANDROID
590 ROM_CONFLICTS="None"
591 UNKNOWN_MOD=false
592 case $PID in
593 mods)
594 mods_display
595 exit
597 auto*)
598 echo ""
599 echo "**************************************"
600 echo "The Auto-Patcher ate a kitten once..."
601 echo "**************************************"
602 echo ""
603 DEV="mateor and Caldair"
604 WEBSITE="https://github.com/mateor/auto-patcher"
605 printusage_help
607 advanced)
608 cd patches/
609 (advanced_help && find -H * -name 201*) | more -d
610 echo ""
611 brief_help
613 voice)
614 FLOOR=4.0.0
615 DESC="Use on wifi-only tablets to have the software register as 'voice-enabled'. Allows VOIP like Google Voice to function."
616 DESC="bongostl's setup method can be seen at the link."
617 WEBSITE="http://forum.xda-developers.com/showthread.php?t=1823701"
618 DEV="bongostl"
620 v6 | v6supercharger)
621 FLOOR=4.0.0
622 CEILING=4.2.2
623 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."
624 DEV="Zeppelinrox"
625 DEPENDENCY="The V6 Supercharger Script. Get it at the link"
626 WEBSITE="http://forum.xda-developers.com/showthread.php?t=991276"
628 PID="v6supercharger" # allows shorthand 'v6' to find patches.
630 pdroid)
631 FLOOR=2.3.7
632 CEILING=4.1.2
633 DESC="Security Software that manages access to personal data w/o causing FC's. No longer under development."
634 DESC1="Try the open-source expansion of this program, OpenPdroid."
635 DESC2="(It's the 'openpdroid' mod within the Auto-Patcher)."
636 DEV="Svyat"
637 DEPENDENCY="The Pdroid app. You can get it at the link"
638 WEBSITE="http://forum.xda-developers.com/showthread.php?t=1923576"
641 pd2.0)
642 FLOOR=4.1.2
643 CEILING=4.1.2
644 DESC="An expansion of the PDroid application/framework."
645 DEV="CollegeDev"
646 DEPENDENCY="The free PDroid2.0 app available at the link"
647 WEBSITE="http://forum.xda-developers.com/showthread.php?t=1923576"
649 openpdroid)
650 FLOOR=4.1.2
651 CEILING=4.2.2
652 DESC="A fork of the open-source PDroid and Pdroid2.0 framework."
653 DEV="CollegeDev/FFU5y/wbedard/mateorod/Community"
654 DEPENDENCY="PDroidManager(opensource) or PDroid2.0(CollegeDev)"
655 WEBSITE="http://forum.xda-developers.com/showthread.php?t=1994860"
657 opendroid)
658 echo ""
659 echo "No mod named 'opendroid'. You probably mean 'openpdroid'. Try again."
660 PID="mods"
661 mods_info
663 external_internal)
664 FLOOR=2.3.3
665 CEILING=4.1.2
666 DESC="Swap internal and external storage."
668 insecure)
669 FLOOR=2.3.3
670 DESC="Make any boot.img insecure and allow remount as well as adb push/pull of system files. True root."
672 secure)
673 FLOOR=2.3.3
674 DESC="Make any boot.img secure."
676 3gdongle)
677 FLOOR=4.1.0
678 CEILING=4.2.2
679 DESC="Allows 3gdongles to work on wifi tablets w/o 3rd party applications."
680 DEV="trevd"
681 DEPENDENCY="None, but read the troubleshooting guide at the link"
682 WEBSITE="http://forum.xda-developers.com/showthread.php?t=1798631"
684 tabletUI)
685 FLOOR=4.1.0
686 CEILING=4.2.2
687 if [[ $ANDR == "4.2" ]]; then
688 ROM_CONFLICTS=(pa .aosp-ever aokp)
689 else
690 ROM_CONFLICTS=(pa .aosp-slim)
692 DESC="Changes the user interface of Phones and Phablets to the popular Tablet UI."
693 DEV="barmullio/Caldair"
694 WEBSITE="http://forum.xda-developers.com/showthread.php?t=2154075"
697 UNKNOWN_MOD=true
698 FLOOR=?????
699 CEILING=?????
700 DESC="??? Unknown modtype ??? Check your spelling or the mod list!"
701 DESC1=" Try: \"./auto_patcher -h mods\""
702 esac
704 # strip decimals from android version (i.e. 2.3.7 becomes 237) so we can do math
705 NVID=${VID//[.]/}
706 COMPATF=${FLOOR//[.]/}
707 COMPATC=${CEILING//[.]/}
710 apk_copy () {
711 if [ -f patches/$P/$A/$R/$B/$FILE ]; then
712 mkdir apk_staging
713 cd apk_staging
714 # Move the certs and manifests from the ROM's apk into the prepatched copy
715 jar -xvf ../"$FILE" META-INF AndroidManifest.xml >> "$LOG"
716 jar -ufv ../patches/$P/$A/$R/$B/$FILE META-INF/CERT* AndroidManifest.xml >> "$LOG" 2>> "$LOG"
717 cd ..
718 \cp -av patches/$P/$A/$R/$B/$FILE $FILE >> "$LOG" 2>&1
719 echo "... Patching $APK failed, but we have successfuly copied over a prepatched file ..."
720 apk_was_copied=true
721 else
722 print_error "failed patching $APK!!!"
726 no_mod_selected_error () {
727 echo ""
728 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
729 printtask "!!! error: $@"
730 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
731 echo ""
732 printtask "You need to enter a MOD before you try and specify the ROMTYPE."
733 printtask "Check the help menu for the list of available MODS"
734 echo ""
735 printusage_help
738 check_against_rom_types () {
739 # this checks to see if the user has entered a ROMTYPE in the MOD spot and outputs advice if so.
740 NUMBER_OF_AVAILABLE_ROMTYPES=${#AVAILABLE_ROMTYPES[@]}
741 for ((i=0; i < $NUMBER_OF_AVAILABLE_ROMTYPES; i++)); do
742 if [[ ${AVAILABLE_ROMTYPES[i]} == "$P" ]]; then
743 no_mod_selected_error "\"$P\" is a ROMTYPE not a MOD"
745 done
748 compat_check () {
749 for P in ${PID[@]}; do
750 mods_info
751 if ($UNKNOWN_MOD); then
752 check_against_rom_types
753 unknown_mod_error "\"$P\" is not a valid mod. Check your spelling or the mod list!!!"
754 elif [[ "$NVID" -lt "$COMPATF" ]]; then
755 mismatch_error "Your Android $VID rom is too old! The minimum for $P is \n !!! Android $FLOOR!"
756 elif [[ "$NVID" -gt "$COMPATC" ]]; then
757 mismatch_error "Sorry, $P has not been made available for Android $VID yet!"
759 done
762 rom_compat_check () {
763 for P in ${PID[@]}; do
764 N=${#ROM_CONFLICTS[@]}
765 for ((i=0; i < $N; i++)); do
766 if [[ $RID == ${ROM_CONFLICTS[$i]} ]]; then
767 rom_compat_error
769 done
770 done
773 rom_compat_error () {
774 print_error "$RID is incompatible with $PID!!!"
777 extpath () {
778 case $(uname -s) in
779 CYGWIN*)
780 echo $(cygpath -da "$1")
783 echo $(abspath "$1")
785 esac
788 #contains () { for e in "${@:2}"; do [[ "$e" = "$1" ]] && return 0; done; return 1; }
790 parse () { echo "${1%%_*}"; }
792 getbuildprop () {
793 if [ -f system/build.prop ]; then
794 result=($(grep $1 system/build.prop | tr -d '\r' | tr '=' ' '))
795 echo "${result[1]}"
796 else
797 echo ""
802 aosp_mod_check() {
803 jar -xvf "$ROMX" system/framework/framework2.jar >> "$LOG"
804 if [ -s system/framework/framework2.jar ]; then
805 ever_check
806 else
807 AOSP=aosp
809 echo $AOSP
812 ever_check() {
813 MID=$(getbuildprop ro.build.romversion)
814 if [[ $MID == "Evervolv"* ]]; then
815 AOSP=".aosp-ever"
816 else
817 MID=$(getbuildprop ro.build.display.id)
818 if [[ "$MID" == "ev"* ]]; then
819 AOSP=".aosp-ever"
820 else
821 pac_check
824 echo $AOSP
827 pac_check() {
828 MID=$(getbuildprop ro.build.romversion)
829 if [[ "$MID" == "pac"* ]] || [[ "$MID" == "PAC"* ]]; then
830 AOSP=".aosp-pac"
831 else
832 MID=$(getbuildprop ro.build.display.id)
833 if [[ "$MID" == "pac"* ]] || [[ "$MID" == "PAC"* ]]; then
834 AOSP=".aosp-pac"
835 else
836 slim_check
841 slim_check() {
842 SLMID=$(getbuildprop ro.modversion)
843 SLMMID=$(getbuildprop updateme.name)
844 if [[ "$SLMMID" == "Slim"* ]] || [[ $SLMMID == "slim"* ]]; then
845 AOSP=".aosp-slim"
846 elif [[ "$SLMID" == "Slim"* ]] || [[ $SLMID == "slim"* ]]; then
847 AOSP=".aosp-slim"
848 else
849 if [[ "$ANDR" == "4.1" ]]; then
850 AOSP=.aosp-mod
851 else
852 AOSP="aosp"
857 pa_check() {
858 CMID=$(getbuildprop ro.modversion)
859 PAID=$(getbuildprop ro.pa.version)
860 MID=$(getbuildprop ro.build.display.id)
861 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
862 DID=$(getbuildprop ro.product.device)
863 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
864 if [[ -n $PAID ]]; then
865 RID=pa
866 else
867 case $CMID in
868 [Pp][Aa]*)
869 RID=pa;
872 RID=cm;
874 esac
878 romtype_set () {
879 case $RID in
881 ROMTYPE="cm"
883 aokp*)
884 ROMTYPE="aokp"
887 ROMTYPE="pa"
890 ROMTYPE="aosp"
892 esac
895 proberom () {
896 VID=$(getbuildprop ro.build.version.release)
897 if [ ${#VID} -lt 4 ]; then # in case of non-standard versioning in build.prop (defy!)
898 ANDR=$VID
899 else
900 ANDR="${VID%.*}" # Cut to 1 significant digit to cover specific range or release.
902 if [ "$ANDR" == "2.3" ]; then
903 FLAVR=gingerbread
904 API=10
905 RID=cm;
906 elif [ "$ANDR" == "4.0" ]; then
907 FLAVR=ics
908 API=15
909 MID=$(getbuildprop ro.rommanager.developerid)
910 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.modversion))
911 DID=$(getbuildprop ro.product.device)
912 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
914 case "$MID" in
915 pa|cm9|cm|cyanogenmod*)
916 RID=cm;
918 aokp|teamkang)
919 RID=aokp;
921 aosp*)
922 RID=aosp;
925 echo "!!! $MID is not supported yet, trying aosp !!!"
926 RID=aosp
928 esac
929 elif [ "$ANDR" == "4.1" ]; then
930 FLAVR=jellybean
931 API=16
932 CMID=$(getbuildprop ro.cm.version)
933 if [[ -n $CMID ]]; then
934 pa_check
935 else
936 MID=$(getbuildprop ro.build.display.id)
937 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
938 DID=$(getbuildprop ro.product.device)
939 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
940 case "$MID" in
941 cm10|cm*|cyanogenmod*)
942 RID=cm;
944 aokp*|teamkang)
945 RID=aokp;
947 pa*)
948 RID=pa;
950 ev*)
951 RID=".aosp-ever";
954 RID=$(aosp_mod_check);
956 esac
958 elif [ "$ANDR" == "4.2" ]; then
959 FLAVR=jellybean
960 API=17
961 CMID=$(getbuildprop ro.cm.version)
962 MID=$(getbuildprop ro.build.display.id)
963 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
964 DID=$(getbuildprop ro.product.device)
965 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
967 case "$MID" in
968 cm*|cyanogenmod*)
969 RID=cm;
970 # hack to account for Final builds with old code and current build dates. Huge hack, but if there
971 # is one thing I don't believe in, it's "educating the user-base". Not happening. So hack it is.
972 echo "CMID is $CMID" #debug
973 if [[ "$CMID" == "10.1."* ]]; then
974 BID_OVERRIDE=20130516
977 aokp*|teamkang)
978 RID=aokp;
980 [Pp][Aa]*)
981 if [[ "$MID" == "pac"* ]] || [[ "$MID" == "PAC"* ]]; then
982 RID=".aosp-pac"
983 else
984 RID=pa;
987 ev*|Ever*)
988 RID=".aosp-ever";
991 RID="$(ever_check)";
993 esac
994 else
995 print_error "unknown ROM version $VID: generally means cannot find/read build.prop"
997 # romtype_set allows hiding ".aosp-*" types from users while leaving them as options on CLI
998 romtype_set
999 echo "... result of ROM check: version= $VID rom= $ROMTYPE ..."
1003 # Advanced build date query
1004 # This should set the patch date automatically.
1006 build_query() {
1007 UTC=$(getbuildprop ro.build.date.utc)
1009 # Difference in how OS X and Linux/Cygwin handles 'date' utility
1010 case $(uname -s) in
1011 [Dd]arwin)
1012 BDID=$(date -r $UTC +%Y%m%d)
1013 echo "#### Darwin Build Query used ####" >> "$LOG"
1016 BDID=$(date -d "1970-01-01 UTC $UTC seconds" +"%Y%m%d")
1017 echo "#### Standard Build Query ####" >> "$LOG"
1019 esac
1021 # If patch date is specified on CLI, use that patch date
1022 if [ $# -gt 3 ]; then
1023 BID=${4//,/ };
1024 BDID=$BID
1025 else
1026 case $ANDR in
1027 2.3)
1028 # CM7 roms do not have UTC time stamp- so no build query.
1029 BID=latest;
1030 echo "*** CM7 roms default to latest patches. If using an older rom ***"
1031 echo "*** specify patch date on command line. Use -h to see available patches ***"
1034 for P in ${PID[@]}; do
1035 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1036 [ -d patches/$P/$A/"$RID" ] && R=$RID || R=generic
1037 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1038 PAR=patches/$P/$A/$R
1039 PARB=patches/$P/$A/$R/$B
1040 DATES=$(ls patches/$P/$A/"$R" | grep '201*')
1041 # Intialize variable - an upperbound to determine lowest in first loop.
1042 BID=20201231
1043 # find earliest available patch date
1044 for i in $DATES; do
1045 if [[ $i -lt $BID ]]; then
1046 BID=$i
1048 done
1049 # Check if earliest patches are from before build date. Else use earliest
1051 # If rom is newer than earliest patch set, find best match
1052 if [[ $(($BID-$BDID)) -lt 0 ]]; then
1053 for g in $DATES; do
1054 # use any patch that matches $UTC
1055 if [[ $(($BDID-$g)) -eq 0 ]]; then
1056 BID=$g
1057 break
1058 # Set highest $BID w/o going over $UTC
1059 elif [[ $(($BDID-$g)) -gt 0 ]] && [[ $g -gt $BID ]]; then
1060 BID=$g
1062 done
1064 # Error catch if query fails.
1065 [[ $BID == "20201231" ]] && BID=latest && echo "Build Query Failed!! Default to latest!" >> "$LOG"
1066 if [[ -n "$BID_OVERRIDE" ]]; then
1067 BID="$BID_OVERRIDE"
1069 echo "... $PID patch date has been set to: $BID ..."
1070 B=$BID
1071 break
1072 done
1074 esac
1078 proberil () {
1079 RIL=$(getbuildprop ro.telephony.ril_class)
1080 [[ -n $RIL ]] && printtask "... result of ROM check: RIL= $RIL"
1083 rominfo () {
1084 echo "# VER= $VERSION" >> "$LOG"
1085 echo "# OS= $OSTYPE ${BIT}bit" >> "$LOG"
1086 echo "# VID= $VID" >> "$LOG"
1087 echo "# PID= ${PID[@]}" >> "$LOG"
1088 echo "# MID= $MID" >> "$LOG"
1089 echo "# RID= $RID" >> "$LOG"
1090 echo "# ANDR= $ANDR" >> "$LOG"
1091 echo "# BDID= $BDID" >> "$LOG"
1092 echo "# DID= $DID" >> "$LOG"
1093 echo "# BID= $BID" >> "$LOG"
1094 echo "Patches are $PID/$ANDR/$RID/$BID" >> "$LOG"
1096 if [ -d ../".git" ]; then
1097 echo "" >> "$LOG"
1098 echo -n "Current HEAD: " >> "$LOG"
1099 git log --pretty=oneline HEAD^..HEAD >> "$LOG"
1100 echo "" >> "$LOG"
1105 if [[ $1 == -h ]]; then
1106 if [ $# -gt 1 ]; then
1107 PID=$2
1108 mods_info
1109 echo ""
1110 echo "The Auto-Patcher $VERSION by Mateorod and Pastime1971"
1111 echo "*************************************************"
1112 echo ""
1113 echo "Mod Name: $PID"
1114 echo ""
1115 echo " $DESC"
1116 if [[ $DESC1 ]]; then # test to see is there is a second DESC line
1117 echo " $DESC1"
1119 if [[ $DESC2 ]]; then
1120 echo -n "$DESC2"
1122 echo ""
1123 echo "Developer: $DEV"
1124 echo "Dependancies: $DEPENDENCY"
1125 if [[ $WEBSITE ]]; then
1126 echo "Website: $WEBSITE"
1128 echo ""
1129 echo "Works on ROMs from Android $FLOOR -> $CEILING"
1130 echo
1131 brief_help
1132 exit
1136 [[ $# -lt 1 || -z $1 ]] && PID="mods" && mods_info
1137 [[ $1 == "-h" ]] && usage_help | less && display_help
1139 echo ""
1140 echo "The Auto-Patcher $VERSION"
1141 # by pastime1971 and mateorod
1142 if [[ -n "$AUTO_PATCHER_WAS_UPDATED" ]]; then
1143 echo " (auto-updated from $AUTO_PATCHER_OLD_VERSION)"
1144 print_changelog
1146 echo ""
1148 ROOT="$(abspath "$(dirname "$(abspath "$(type -p "$0")")")")"
1149 TOOL="$ROOT/patch_tools.tgz"
1150 PTCH="$ROOT/patch_patches.tgz"
1151 cleanup
1152 # set temporaray directory
1153 DATE=$(date +%Y%m%d%H%M%S)
1154 TEMP="$ROOT/tmp$DATE"
1155 TMP="$ROOT/tmp$DATE"
1156 TMPDIR="$ROOT/tmp$DATE"
1157 mkdir "$TEMP"
1158 ROM=$(abspath "$1")
1159 ROMX=$(extpath "$1")
1161 if [[ $OSTYPE == "cygwin" ]]; then
1162 EXE=".exe"
1163 PGFORM="0x"
1164 AUTO_UPDATE=false # CYGWIN AUTO_UPDATE TESTERS COMMENT THIS LINE HERE!
1167 LOG=$(abspath ./log$DATE.txt)
1168 #echo $ROOT $TOOL $ROM $TEMP "$LOG"
1169 echo "ROOT= $ROOT" >> "$LOG"
1170 echo "TOOL= $TOOL" >> "$LOG"
1171 echo "ROM= $ROM" >> "$LOG"
1172 echo "ROMX= $ROMX" >> "$LOG"
1175 # Auto-Update # excluding ApG/cygwin for now until I talk with kobik.
1176 # To turn off auto updating, set AUTO_UPDATE in .config to false
1179 # Check for git
1180 if [ $(which git) ]; then
1181 GIT=true
1182 else
1183 miss_git_error "Missing \"git\" utility"
1184 GIT=false
1187 # If program was updated, merge the logs
1188 if [[ -n "$AUTO_PATCHER_WAS_UPDATED" ]]; then
1189 cat .updated.log >> "$LOG"
1190 rm -If .updated.log
1193 if [[ "$AUTO_UPDATE" == true ]] && [[ "$GIT" == true ]]; then
1194 ping -c1 www.github.com > /dev/null 2>&1 && NETWORK=true || no_network_access
1195 if [[ "$NETWORK" == true ]]; then
1196 printtask "### checking for updates ###"
1198 # establish the repo if not already present- one time operation.
1199 if [ ! -d ".git" ]; then
1200 printtask "... initial setup to allow automatic updating ..."
1201 backup_script && warn_of_overwrite
1202 establish_repo && export_log_and_variables
1203 printtask "### rerunning script with latest version ###"
1204 $0 "$@"
1205 exit 0
1208 # Here is the regular update process
1209 git fetch origin 2>&1 >> "$LOG" || no_network_access
1210 if !("$NETWORK"); then
1211 printtask "Updater: not able to run auto_update."
1212 else
1213 COMMITS_BEHIND=$(git rev-list HEAD..origin/master --count)
1214 case "$COMMITS_BEHIND" in
1216 printtask "Updater: Auto-Patcher is already up to date"
1219 ORIGINAL_HEAD=$(git rev-parse HEAD)
1220 printtask "... Updater: update found ..."
1221 backup_script
1222 printtask "... Updating Auto-Patcher ..."
1223 git merge --no-edit origin/master 2>&1 >> "$LOG" || auto_update_error
1224 export_log_and_variables
1225 printtask "### updated, now rerunning script with latest version ###"
1226 $0 "$@"
1227 exit 0
1229 esac
1230 echo ""
1235 if [[ -n "$AUTO_PATCHER_WAS_UPDATED" ]]; then
1236 if [[ $PATCHES_VERSION -gt $AUTO_PATCHER_OLD_PATCHES_VERSION ]]; then
1237 echo "... integrating new patches ..."
1238 sh batch.sh >> /dev/null 2>> "$LOG"
1242 #remove old zips, if built under identical parameters.
1243 \rm -f $RESTORE.zip $UPDATE.zip
1245 CHK=$(getconf LONG_BIT)
1246 if [[ $CHK = "64" ]]; then
1247 BIT=64
1248 else [[ $BIT = "32" ]];
1249 BIT=32
1252 printtask "### verify tools ###"
1253 which patch >> "$LOG" || misstools_error "Missing \"patch\" utility."
1254 which tar >> "$LOG" || misstools_error "Missing \"tar\" utility"
1255 which jar >> "$LOG" || misstools_error "Missing \"Java Development Kit\" (JDK)"
1256 which java >> "$LOG" || misstools_error "Missing \"Java Development Kit\" (JDK)"
1257 which cpio >> "$LOG" || misstools_error "Missing \"cpio\" utility"
1258 [ -f "$TOOL" ] || misspatch_error "patch_tool.tgz is missing"
1259 [ -f "$PTCH" ] || misspatch_error "patch_patches.tgz is missing"
1260 printtask "### verify ROM ###"
1261 [ -f "$ROM" ] || print_error "Cannot find $1!! Make sure you have the location and name right"
1262 echo "### running $0 $@" >> "$LOG"
1263 cd "$TEMP"
1265 PATH="$TEMP:$PATH"
1266 export PATH
1267 echo "PATH= $PATH" >> "$LOG"
1269 printtask "### unzip patch tools ###"
1270 tar xzf "$TOOL" > /dev/null || print_error "failed extracting tools !!!"
1272 # Get OS specific tools
1273 case $(uname -s) in
1274 CYGWIN*)
1275 \mv cygwin/aapt.exe .
1276 \mv cygwin/*.exe boot/
1277 \rm -rf cygwin # why? If you want to we can keep/add it to mac/linux, though.
1279 [Dd]arwin)
1280 \mv mac/aapt .
1282 [Ll]inux)
1283 \mv linux/aapt .
1286 \mv linux/aapt .
1288 esac
1289 # Ensure aapt permissions - possibly to one day be expanded to all tools in a function.
1290 chmod a+x aapt$EXE
1292 printtask "### unzip patch patches ###"
1293 tar xzf "$PTCH" > /dev/null || print_error "failed extracting patches !!!"
1295 # we need build.prop for both RIL probing and ROM probing
1296 jar -xvf "$ROMX" system/build.prop 2>> "$LOG" || print_error "failed extracting build.prop from $ROMX !!!"
1298 # rom + ril type
1299 proberil
1300 printtask "### probe rom type ###"
1301 proberom
1303 # rom type
1304 if [ $# -gt 1 ]; then
1305 PIT=$2
1306 if [[ "$PIT" = "-h" ]]; then
1307 display_help
1311 if [ $# -gt 2 ]; then
1312 RID=$3
1313 case "$RID" in
1314 cm*|cyanogenmod*)
1315 RID=cm;
1317 aokp*|teamkang)
1318 RID=aokp;
1320 pa*)
1321 RID=pa;
1323 .aosp-ever)
1324 RID=".aosp-ever";
1326 .aosp-slim)
1327 RID=".aosp-slim"
1329 .aosp-pac)
1330 RID=".aosp-pac"
1332 aosp*)
1333 case "ANDR" in
1334 4.1)
1335 RID=$(aosp_mod_check);
1338 RID=$(ever_check)
1340 esac
1342 201*)
1343 date_error "You must specify ROMTYPE if designating a patch date!!"
1346 rom_error "$RID is not a valid ROMTYPE!!"
1348 esac
1349 romtype_set
1350 echo "... Using $ROMTYPE patches ..."
1351 else
1352 echo "... Using results of ROM check ..."
1355 # patch type
1356 if [ $# -gt 1 ]; then
1357 PIL=${2//,/ } # If more than one mod, make string separated by spaces
1358 else
1359 PIL="openpdroid"
1360 echo "No mods selected. Defaulting to openpdroid, since that's what you probably want..."
1363 # Ensure only 1 Pdroid mod at a time; PDroid first, so provisionals do not overwrite other mods...
1365 PID=(${PIL// / }) # turn string of requested mods into array
1366 COPYPID=("${PID[@]}") # working copy to iterate over
1367 MODS_NUMBER=${#COPYPID[@]} # number of elements (mods)
1369 if [[ $MODS_NUMBER > 1 ]]; then # because if only one mod, not needed
1370 INDEX=0 # 'pd2.0' didn't work with unset; regex use bars multiple 'pdroid's
1371 for p in ${COPYPID[@]}; do
1372 if [ "$p" = "pdroid" ] || [ "$p" = "pd2.0" ] ||[ "$p" = "openpdroid" ]; then
1373 SPID[0]=$p #set pdroid first
1374 unset COPYPID["$INDEX"]
1375 break
1376 else
1377 INDEX=$((INDEX + 1)) # if (!pdroid), set as 1, 2...
1379 done
1380 for p in ${COPYPID[@]}; do
1381 if [ "$p" = "pdroid" ] || [ $p = "pd2.0" ] ||[ $p = "openpdroid" ]; then
1382 conflict_error "Those mods conflict! Only one pdroid mod at a time!"
1383 else
1384 i=${#SPID[@]}
1385 SPID[i]=$p
1386 i+=1
1388 done
1389 else
1390 SPID=${COPYPID[@]}
1392 for P in ${PIL[@]}; do
1393 [[ ${PID[@]} =~ $P ]] || PID=(${PID[@]} $P)
1394 done
1396 # Check if selected mods are available for rom's Android version.
1397 compat_check
1399 # Make sure mod and rom don't conflict (e.g. pa and tabletUI)
1400 if [[ $ROM_CONFLICTS != "None" ]]; then
1401 rom_compat_check
1404 # Build date
1405 if [ $# -gt 3 ]; then # if a date is specified on command line...
1406 # Set date to match argument and ensure that patches with that date exist
1407 BID=$4
1408 [ -d patches/$P/$ANDR/$RID/$BID ] || print_error "No $P patches for $RID on $BID!! Try the help menu!!"
1409 # Run build_query- this overrides the above but gets useful info
1410 build_query
1411 # Reset patch date to argument (basically undo the effects of the build_query call)
1412 BID=$4
1413 echo "... $PID patch date set manually to: $BID ..."
1414 else
1415 build_query # if no date specified, use one from build_query
1418 # echo ROM info
1419 rominfo
1421 if [[ ( "$PID" == "-h" || "$RID" == "-h" || "$BID" == "-h" ) ]]; then
1422 #Although this placement may be perfect for romfilter. although it throws the scheme...
1423 display_help
1425 #Begin cycle
1427 for P in ${PID[@]}; do
1428 [ -d patches/$P ] || print_error "$P is not available"
1429 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1430 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1431 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1433 unset FILES
1434 [ -f patches/$P/files.txt ] && FILES=$(cat patches/$P/files.txt)
1435 [ -f patches/$P/$A/files.txt ] && FILES=$(cat patches/$P/$A/files.txt)
1436 [ -f patches/$P/$A/$R/files.txt ] && FILES=$(cat patches/$P/$A/$R/files.txt)
1437 [ -f patches/$P/$A/$R/$B/files.txt ] && FILES=$(cat patches/$P/$A/$R/$B/files.txt)
1438 for FILE in ${FILES[@]}; do
1439 case "$FILE" in
1440 +system/*)
1441 [[ ${CID[@]} =~ ${FILE:1} ]] && print_error "${FILE:1} is already being copied" || CID=(${CID[@]} ${FILE:1})
1443 -system/*)
1444 [[ ${EID[@]} =~ ${FILE:1} ]] || EID=(${EID[@]} ${FILE:1})
1446 system/*.jar)
1447 [[ ${JID[@]} =~ $FILE ]] || JID=(${JID[@]} $FILE)
1448 echo "set_perm(0, 0, 0644, \"/$FILE\");" >> UPDATE.txt
1450 # added for the use-case of apktool failure
1451 @system/*apk) # apks to decompile with smali binaries instead of apktool
1452 [[ ${JID[@]} =~ ${FILE:1} ]] || JID=(${JID[@]} ${FILE:1})
1453 FORMATTED_FILE=${FILE:1}
1454 echo "set_perm(0, 0, 0644, \"/$FORMATTED_FILE\");" >> UPDATE.txt
1456 system/*.apk)
1457 [[ ${AID[@]} =~ $FILE ]] || AID=(${AID[@]} $FILE)
1458 echo "set_perm(0, 0, 0644, \"/$FILE\");" >> UPDATE.txt
1459 # $APKID will have elements removed sometimes--$AID is the master list for the update.zip
1460 declare -a APKID=( "${AID[@]}" )
1462 *.img)
1463 [[ ${IID[@]} =~ $FILE ]] || IID=(${IID[@]} $FILE)
1465 system/*)
1466 [[ ${TID[@]} =~ $FILE ]] || TID=(${TID[@]} $FILE)
1468 esac
1469 done
1470 done
1471 echo "### DELETE FILES= ${EID[@]}" >> "$LOG"
1472 echo "### COPY FILES= ${CID[@]}" >> "$LOG"
1473 echo "### JAR FILES= ${JID[@]}" >> "$LOG"
1474 echo "### APK FILES= ${AID[@]}" >> "$LOG"
1475 echo "### IMG FILES= ${IID[@]}" >> "$LOG"
1476 echo "### TXT FILES= ${TID[@]}" >> "$LOG"
1478 # extract system files
1479 printtask "### unzip rom ###"
1480 jar -xvf "$ROMX" ${JID[@]} ${AID[@]} ${IID[@]} ${TID[@]} 2>> "$LOG" || print_error "failed extracting ${JID[@]} ${AID[@]} ${IID[@]} from $ROMX !!!"
1483 # Update/Restore.zip scripts and prep
1484 printtask "### create updater script ###"
1485 UPDATER_LOC=META-INF/com/google/android
1486 UPDS=updater-script
1487 UPDATE="update-$ROMTYPE-$DID-$BDID-${PIL// /-}"
1488 RESTORE="restore-$ROMTYPE-$DID-$BDID"
1490 jar -xvf "$ROMX" $UPDATER_LOC/$UPDS $UPDATER_LOC/update-binary
1491 jar -xvf "$ROMX" $UPDATER_LOC/update-binary-installer 1> /dev/null 2> /dev/null
1493 # Determine Installer- Aroma or ClockworkMod
1494 if [ -f $UPDATER_LOC/update-binary-installer ]; then
1495 printtask "... using Aroma installer ..."
1496 \mv $UPDATER_LOC/update-binary-installer $UPDATER_LOC/update-binary
1497 else
1498 printtask "... using Clockworkmod installer ..."
1501 # Create updater scripts
1502 cat patches/.common/updater-message.txt >> $UPDS
1503 cat $UPDATER_LOC/$UPDS | grep ^mount | grep "/system" | head -n 1 >> $UPDS
1504 [ -s $UPDS ] || echo "run_program(\"/sbin/busybox\", \"mount\", \"/system\");" >> $UPDS
1505 # restore the original
1506 for FILE in ${EID[@]}; do
1507 jar -xvf "$ROMX" $FILE 2> /dev/null || printtask "!!! warning $FILE cannot be restored !!!"
1508 done
1509 # replace with the original or delete it
1510 for FILE in ${CID[@]}; do
1511 jar -xvf "$ROMX" $FILE 2> /dev/null || echo "delete(\"/$FILE\");" >> $UPDS
1512 done
1513 echo "package_extract_dir(\"system\", \"/system\");" >> $UPDS
1514 # permission management for files that need specific perms
1515 cat $UPDATER_LOC/$UPDS | grep set_perm | grep "/system" >> $UPDS
1516 for P in ${PID[@]}; do
1517 if [ -s patches/$P/$A/set_perm.txt ]; then
1518 echo "...setting permissions..."
1519 cat patches/$P/$A/set_perm.txt >> $UPDS
1521 done
1522 cat $UPDATER_LOC/$UPDS | grep ^unmount | grep "/system" | head -n 1 >> $UPDS
1523 [[ ${IID[@]} =~ boot.img ]] && cat $UPDATER_LOC/$UPDS | grep "boot.img" >> $UPDS
1524 echo "ui_print(\" .\");" >> $UPDS
1525 echo "ui_print(\" .\");" >> $UPDS
1526 echo "ui_print(\" done!\");" >> $UPDS
1527 cat $UPDS > $UPDATER_LOC/$UPDS
1528 echo "# generated $UPDS" >> "$LOG"
1529 cat $UPDS >> "$LOG"
1531 printtask "### create restore.zip ###"
1532 jar -cvf tmp.zip ${JID[@]} ${AID[@]} ${IID[@]} META-INF > /dev/null 2>> "$LOG"
1533 java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip signed.zip 2>> "$LOG"
1534 \mv signed.zip $RESTORE.zip
1535 \rm -f tmp.zip
1538 # Begin patching process
1540 # decompile system files
1541 printtask "### decompile system files ###"
1542 for FILE in ${JID[@]}; do
1543 JAR=${FILE##*/}
1544 printtask "... decompile $JAR ..."
1545 java -jar baksmali.jar -b -a $API -o tmp/${FILE}.out/smali ${FILE} >> "$LOG" 2>> "$LOG"
1546 if [ $FILE == "system/framework/framework.jar" ]; then
1547 printtask "... extract preloaded-classes ..."
1548 jar -xvf ${FILE} preloaded-classes >> "$LOG" 2>> "$LOG"
1549 \mv preloaded-classes tmp/${FILE}.out/
1551 done
1553 # install framework-files for APK...
1554 if [ ${#AID[@]} -gt 0 ]; then
1555 jar -xvf "$ROMX" system/framework/framework-res.apk >> "$LOG"
1556 printtask "... installing framework files ..."
1557 java -jar apktool.jar if system/framework/framework-res.apk
1558 # Decompile APKs
1559 for FILE in ${AID[@]}; do
1560 APK=${FILE##*/}
1561 if [ -f $FILE ]; then
1562 printtask "... decompile $APK ..."
1563 java -jar apktool.jar d -f $FILE tmp/$FILE.out 2>> "$LOG"
1565 done
1568 # Unpack image files {boot.img only so far...}
1569 for FILE in ${IID[@]}; do
1570 printtask "### unpacking $FILE ###"
1571 case "$FILE" in
1572 boot.img)
1573 if [ -f boot.img ]; then
1574 cd boot
1575 ./unpackbootimg$EXE -i ../boot.img >> "$LOG" 2>> "$LOG"
1576 mkdir ramdisk
1577 cd ramdisk
1578 gzip -dc ../boot.img-ramdisk.gz | cpio -i >> "$LOG" 2>> "$LOG"
1579 cd ../../
1580 else
1581 print_error "A mod needs to patch boot.img! This rom does not contains boot.img."
1585 print_error "cannot process $FILE"
1587 esac
1588 done
1590 # apply system modification
1592 for P in ${PID[@]}; do
1593 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1594 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1595 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1596 PAR=patches/$P/$A/$R
1597 PARB=patches/$P/$A/$R/$B
1599 unset FILES COPY DELS JARS APKS IMGS TXTS
1600 [ -f patches/$P/files.txt ] && FILES=$(cat patches/$P/files.txt)
1601 [ -f patches/$P/$A/files.txt ] && FILES=$(cat patches/$P/$A/files.txt)
1602 [ -f patches/$P/$A/$R/files.txt ] && FILES=$(cat patches/$P/$A/$R/files.txt)
1603 [ -f patches/$P/$A/$R/$B/files.txt ] && FILES=$(cat patches/$P/$A/$R/$B/files.txt)
1604 for FILE in ${FILES[@]}; do
1605 case $FILE in
1606 +system/*)
1607 COPY=(${COPY[@]} ${FILE:1})
1609 -system/*)
1610 DELS=(${DELS[@]} ${FILE:1})
1612 system/*.jar)
1613 JARS=(${JARS[@]} $FILE)
1615 ~system/*)
1616 JARS=(${JARS[@]} ${FILE:1})
1618 system/*.apk)
1619 APKS=(${APKS[@]} $FILE)
1621 *.img)
1622 IMGS=(${IMGS[@]} $FILE)
1624 system/*)
1625 TXTS=(${TXTS[@]} $FILE)
1627 esac
1628 done
1630 [[ -n ${COPY[@]} ]] && echo "### copy patch $P/$A/$ROMTYPE/$B ###"
1631 echo "### copy patch $P/$A/$R/$B ###" >> "$LOG"
1632 for FILE in ${COPY[@]}; do
1633 printtask "... copying $FILE ..."
1634 DEST=${FILE%/*}
1635 mkdir -p ./$DEST
1636 if [ -e patches/$P/$A/$R/$B/$FILE ]; then
1637 printtask "... overwriting $FILE from $P ..."
1638 \cp -av patches/$P/$A/$R/$B/$FILE ./$DEST >> "$LOG" 2>&1
1639 elif [ -e patches/$P/common/$FILE ]; then
1640 printtask "... overwriting $FILE from $P ..."
1641 echo " ### SOMETHING WENT WRONG!! Could not find file-- using common. ###" >> "$LOG"
1642 \cp -av patches/$P/common/$FILE ./$DEST >> "$LOG" 2>&1
1643 else
1644 print_error "$FILE is missing in the patch. Please upload your logfile to the support thread!"
1646 done
1648 # unconditional smali copying- For particularly troublesome files
1649 [ -f patches/$P/smali.txt ] && SMALI=$(cat patches/$P/smali.txt)
1650 [ -f patches/$P/$A/smali.txt ] && SMALI=$(cat patches/$P/$A/smali.txt)
1651 [ -f patches/$P/$A/$R/smali.txt ] && SMALI=$(cat patches/$P/$A/$R/smali.txt)
1652 [ -f patches/$P/$A/$R/$B/smali.txt ] && SMALI=$(cat patches/$P/$A/$R/$B/smali.txt)
1653 MOVE=${SMALI##*/}
1654 for SMALI in ${SMALI[@]}; do
1655 if [ -f patches/$P/$A/$R/$B/$SMALI ]; then
1656 printtask "... overwriting $MOVE ..."
1657 \cp -a patches/$P/$ANDR/$R/$B/$SMALI tmp/$SMALI >> "$LOG" 2>&1
1658 # This lower area should be deprecated now...wait and see. Each BID has own link to provisionals now.
1659 elif [ -f patches/$P/$A/.provisionals/$SMALI ]; then
1660 printtask "... overwriting $MOVE ..."
1661 \cp -a patches/$P/$ANDR/.provisionals/$SMALI tmp/$SMALI >> "$LOG"
1663 done
1665 [[ -n ${DELS[@]} ]] && echo "### delete patch $P/$A/$ROMTYPE/$B ###"
1666 echo "### delete patch $P/$A/$R/$B ###" >> "$LOG"
1667 for FILE in ${DELS[@]}; do
1668 printtask "... deleting $FILE ..."
1669 \rm -rf ./$FILE
1670 done
1671 [[ -n ${JARS[@]} ]] && echo "### jar patch $P/$A/$ROMTYPE/$B ###"
1672 echo "### jar patch $P/$A/$R/$B ###" >> "$LOG"
1674 # Iterate through jars and patch. If fails, try prepatched provisionals or look for alternative patch.
1675 ALT_PATCH_NUMBER=2
1676 for (( current_jar=0; current_jar < ${#JARS[@]}; current_jar++)); do
1677 FILE=${JARS[$current_jar]}
1678 JAR=${FILE##*/}
1679 if [[ $FILE == *".jar" ]]; then # allows for *.apks to be decompiled by baksmali
1680 NAME=${JAR%.jar}
1681 else
1682 # check for abscense of any apks decompiled by baksmali (~* in files.txt). Missing jars will still error
1683 if [ ! -d "tmp/${FILE}.out" ] ; then
1684 echo "No $JAR in your ROM. Not able to patch this file."
1685 echo "## No $JAR in ROM ###" >> "$LOG"
1686 declare -a JID=( ${JID[@]/$FILE/} )
1687 break;
1689 NAME=$JAR # TODO: Maybe rename this, since it now encompases apks at times
1691 printtask "... apply $NAME.patch ..."
1692 patch -Nls -p1 -d tmp/${FILE}.out < $PARB/${NAME}.patch 2>&1 > ${JAR}.log
1693 for INCREMENTAL in $(ls $PARB/${NAME}-*.patch 2>/dev/null); do
1694 printtask "... apply $(basename $INCREMENTAL) ..."
1695 patch -Nls -p1 -d tmp/${FILE}.out < $INCREMENTAL 2>&1 > ${JAR}.log
1696 done
1697 cat ${JAR}.log >> "$LOG"
1698 case "$NAME" in
1699 framework)
1700 # patch preloaded-classes only if a patch exists
1701 if [ -f $PARB/preloaded.patch ]; then
1702 printtask "... apply preloaded.patch ..."
1703 patch -Nls -p1 -d tmp/${FILE}.out < $PARB/preloaded.patch 2>&1 > preloaded.log
1704 cat preloaded.log >> "$LOG"
1705 [[ $(grep FAILED preloaded.log) != "" ]] && print_error "failed preloaded.patch"
1709 echo -n "" # do nothing else
1711 esac
1712 # substitute failed smali with provisional (a prepatched smali file)
1713 unset FAILS
1714 FAILS=($(grep FAILED ${JAR}.log | sed -e 's/.*smali\///' | sed -e 's/\.rej//'))
1715 if [[ -n ${FAILS[@]} ]]; then
1716 print_to_log "!!! PATCHING FAILED FOR ${FAILS[@]} !!!"
1717 echo "### replace ${FAILS[@]} ###" > ${JAR}.log
1718 for FAIL in ${FAILS[@]}; do
1719 PROVISIONAL="patches/$P/$ANDR/.provisionals/${FILE}.out/smali/${FAIL}"
1720 ALTERNATIVE_PATCH=$(ls $PARB/${NAME}$ALT_PATCH_NUMBER*.patch 2>/dev/null)
1721 if [ ! -f "$PROVISIONAL" ]; then
1722 if [ -f "$ALTERNATIVE_PATCH" ]; then
1723 printtask "## trying alternative ${NAME} patch ###"
1724 prep_alternate_patch
1725 else
1726 print_error "failed $FAIL in $JAR cannot be remedied"
1728 else
1729 echo "!!! patch error for $FAIL !!!" >> "$LOG"
1730 [[ ${SID[@]} =~ $FAIL ]] && print_error "$FAIL was already replaced before"
1731 copy_prepatched_provisional
1733 done
1735 [[ $(grep FAILED ${JAR}.log) != "" ]] && print_error "failed $NAME.patch"
1736 garbage tmp/${FILE}.out
1738 # run special $JAR.sh scripts if any JAR needs special attention
1739 if [ -f patches/$P/$A/$R/$B/${JAR}.sh ]; then
1740 printtask "... apply $JAR.sh ..."
1741 . patches/$P/$A/$R/$B/${JAR}.sh 2>&1 > ${JAR}.log
1742 cat ${JAR}.log | tee -a "$LOG"
1744 done
1746 [[ -n ${APKS[@]} ]] && echo "### apk patch $P/$A/$ROMTYPE/$B ###"
1747 echo "### apk patch $P/$A/$R/$B ###" >> "$LOG"
1748 for FILE in ${APKS[@]}; do
1749 APK=${FILE##*/}
1750 if [ -d "tmp/${FILE}.out" ] ; then
1751 printtask "... apply $APK.patch ..."
1752 patch -Nls -p2 -d tmp/${FILE}.out < $PARB/${APK}.patch 2>&1 > ${APK}.log
1753 cat ${APK}.log >> "$LOG"
1755 if [[ $(grep FAILED ${APK}.log) != "" ]]; then
1756 apk_copy
1757 declare -a APKID=( ${APKID[@]/$FILE/} )
1759 garbage tmp/${FILE}.out
1760 else
1761 echo "No $APK in your ROM. Not able to patch this file."
1762 echo "## No $APK in ROM ###" >> "$LOG"
1764 done
1765 [[ -n ${IMGS[@]} ]] && echo "### img patch $P/$A/$ROMTYPE/$B ###"
1766 echo "### img patch $P/$A/$R/$B ###" >> "$LOG"
1767 for FILE in ${IMGS[@]}; do
1768 IMG=${FILE##*/}
1769 printtask "... applying $IMG.patch ..."
1770 patch -Nls -p1 -d boot/ramdisk < $PARB/${IMG}.patch >> "$LOG" || print_error "failed patching $FILE"
1771 done
1773 # Text Editing Functions --this can really do just about anything. Needs a working restore!
1774 [[ -n ${TXTS[@]} ]] && echo "### text patch $P/$A/$ROMTYPE/$B ###"
1775 echo "### text patch $P/$A/$R/$B ###" >> "$LOG"
1776 for FILE in ${TXTS[@]}; do
1777 TXT=${FILE##*/}
1778 if [[ -f $PARB/${TXT}.patch ]]; then
1779 printtask "... apply $TXT.patch ..."
1780 patch -Nls -p2 -d system/ < $PARB/${TXT}.patch 2>&1 > ${TXT}.log
1781 #cat ${TXT}.log | tee -a "$LOG"
1782 [[ $(grep FAILED ${TXT}.log) != "" ]] && print_error "failed $TXT.patch"
1784 if [[ -f $PAR/${TXT}.awk ]]; then
1785 printtask "... apply $TXT.awk ..."
1786 awk -f $PAR/${TXT}.awk $FILE > text || print_error "failed $TXT.awk"
1787 mv text $FILE
1789 if [[ -f $PAR/${TXT}.sed ]]; then
1790 printtask "... apply $TXT.sed ..."
1791 sed -f $PAR/${TXT}.sed $FILE > text || print_error "failed $TXT.sed"
1792 mv text $FILE
1794 if [[ -f $PAR/${TXT}.sh ]]; then
1795 printtask "... apply $TXT.sh ..."
1796 . $PAR/${TXT}.sh 2>&1 >> ${TXT}.log || print_error "failed $TXT.sh"
1798 garbage system/
1799 done
1800 done
1802 # Device specific scripts- Placement is up-for-review
1803 if [ -f patches/.devices/$DID/$DID.sh ]; then
1804 . patches/.devices/$DID/$DID.sh
1807 # Replace updater-script for CM7- it formats system -Testing
1808 if [ "$ANDR" == "gingerbread" ]; then
1809 replace_updater
1812 # Rebuilding system files
1814 [[ -n ${JID[@]} ]] && printtask "### rebuild jar ###"
1815 for FILE in ${JID[@]}; do
1816 JAR=${FILE##*/}
1817 printtask "... rebuild $JAR ..."
1818 java -Xmx512M -jar smali.jar -a $API tmp/${FILE}.out/smali -o tmp/${FILE}.out/classes.dex >> "$LOG" 2>> "$LOG"
1819 [ -f tmp/${FILE}.out/classes.dex ] || smali_error "failed compiling $JAR !!!"
1820 jar -ufv ${FILE} -C tmp/${FILE}.out/ classes.dex >> "$LOG" 2>> "$LOG"
1821 if [ $FILE == "system/framework/framework.jar" ]; then
1822 jar -ufv ${FILE} -C tmp/${FILE}.out/ preloaded-classes >> "$LOG" 2>> "$LOG"
1824 done
1826 [[ -n ${APKID[@]} ]] && printtask "### rebuild apk ###"
1827 for FILE in ${APKID[@]}; do
1828 APK=${FILE##*/}
1829 if [ -d tmp/${FILE}.out ]; then
1830 apk_was_copied=false
1831 printtask "... rebuild $APK ..."
1832 java -jar apktool.jar b tmp/${FILE}.out >> "$LOG" 2>> "$LOG" || apk_copy
1833 if !("$apk_was_copied"); then
1834 jar -uvf $FILE -C tmp/${FILE}.out/build/apk/ . > /dev/null 2>> "$LOG"
1837 done
1839 [[ -n ${IID[@]} ]] && printtask "### rebuild img ###"
1840 for FILE in ${IID[@]}; do
1841 printtask "### rebuild $FILE ###"
1842 case $FILE in
1843 boot.img)
1844 # Rebuilding boot.img
1845 cd boot
1846 printtask "... rebuilding ramdisk ..."
1847 ./mkbootfs$EXE ./ramdisk | gzip > ramdisk-new.gz
1848 printtask "... composing boot.img ..."
1849 BASE=$(cat boot.img-base)
1850 # hex to decimal in cygwin prefixing "0x" w/ C arithmetic
1851 PGSIZE=$((${PGFORM}$(cat boot.img-pagesize)))
1852 CMDLINE=$(cat boot.img-cmdline)
1853 echo "cmdline = no_console_suspend=1 console=null $CMDLINE" >> "$LOG"
1854 echo "pagesize = $PGSIZE" >> "$LOG"
1855 echo "base = $BASE" >> "$LOG"
1856 printtask "... rebuilding boot.img ..."
1857 ./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"
1858 cd ..
1861 print_error "cannot process $FILE"
1863 esac
1864 done
1866 printtask "### create $UPDATE.zip ###"
1867 jar -cfv tmp.zip ${IID[@]} ${JID[@]} ${AID[@]} ${CID[@]} ${TID[@]} META-INF >> "$LOG" 2>> "$LOG"
1868 java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip $UPDATE.zip 2>> "$LOG"
1870 \mv $RESTORE.zip $UPDATE.zip ..
1871 printtask "### finished ###"
1872 printtask ""
1873 printtask "$(colorize_bold ${red}Congratulations), the patching was $(colorize_bold ${red}successful)."
1874 printtask "Any errors you may have seen were succesfully handled!"
1875 printtask ""
1876 printtask "!!! Only file a bug report if the software is $(colorize_bold ${grn}not) behaving as expected !!!"
1877 printtask ""
1878 echo "to install patched files, flash:"
1879 printtask "---$(colorize_bold ${grn}$UPDATE.zip)"
1880 echo ""
1881 printtask "to restore original system, flash:"
1882 printtask "---$(colorize_bold ${grn}$RESTORE.zip)"
1883 echo ""
1885 # add announcement- optional.
1886 for P in ${PID[@]}; do
1887 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1888 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1889 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1890 if [ -f patches/$P/$A/$R/$B/README.txt ]; then
1891 cat patches/$P/$A/$R/$B/README.txt
1892 elif [ -f patches/$P/$A/$R/README.txt ]; then
1893 cat patches/$P/$A/$R/README.txt
1894 elif [ -f patches/$P/$A/README.txt ]; then
1895 cat patches/$P/$A/README.txt
1897 done
1899 cd ..
1900 \rm -rf "$TEMP"