Updated patch version.
[auto-patcher.git] / auto_patcher
blobd77544ea8b5c0ea0db454df84d4a1ab4e22651c7
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
141 # SHELL PROGRAMMING NOTES:
142 # [ -s FILE ]
143 # [[ -n STRING ]] or [[ -z STRING ]]
145 VERSION="v2.9.878"
146 # PATCHES_VERSION needs to be incremented every time ANY changes occur to patches.
147 PATCHES_VERSION="20130624"
148 CURRENT_ANDROID="4.2.2"
150 # Available ROMTYPES.
151 # ROMTYPES that are hidden can be forced on the command line. But they are best left
152 # blank to be automatically parsed by our romprobe or by just entering the parent...usually AOSP.
154 #Non-obvious ROMTYPE legend
155 # @.aosp-slim: SlimRom @.aosp-pac: PAC-man
156 # @.aosp-ever: Evervolv @pa: ParanoidAndroid (official jellybean branch only for now)
157 declare -a AVAILABLE_ROMTYPES=('aokp' 'aosp' 'cm' 'pa' '.aosp-slim' '.aosp-pac' '.aosp-ever')
159 # pass variables to children
160 set -a
162 # Set any environmental variables
163 LANG=C
165 # Config file: For now hosting AUTO_UPDATE and PRODUCTION(currently unused). Not under version control.
166 if [ ! -f .config ]; then
167 cp -a ap_scripts/config_template .config
169 source .config
171 # Colorize and add text parameters
172 red=$(tput setaf 1) # red
173 grn=$(tput setaf 2) # green
174 cyan=$(tput setaf 6) # cyan
175 txtBold=$(tput bold) # Bold
176 txtReset=$(tput sgr0) # Reset
178 colorize () {
179 # pass color and then reset
180 echo -e $@${txtReset}
183 colorize_bold () {
184 echo -e ${txtBold}$@${txtReset}
187 printusage_help () {
188 PID="openpdroid,3gdongle" # default example
189 brief_help
192 brief_help () {
193 echo " usage: ./auto_patcher <ROM> <MODS> <ROMTYPE>"
194 echo " example: ./auto_patcher CM10.zip $PID cm"
195 echo ""
196 echo "Use ./auto_patcher -h for the help menu"
197 echo ""
198 cleanup
199 exit
202 usage_help () {
203 PID=mods
204 mods_display
205 echo "Multiple MODS can be combined by separating them with a comma and NO SPACES!!!"
206 echo ""
207 echo " usage: ./auto_patcher <ROM> <MODS> <ROMTYPE>"
208 echo ""
209 echo " example: ./auto_patcher CM10.zip openpdroid,3gdongle cm"
210 echo ""
211 usage_more_help
214 usage_more_help () {
215 echo "* press 'q' available patches or CTRL-c to quit the help menu *"
218 display_help () {
219 cd patches
220 echo ""
221 echo "AVAILABLE PATCHES"
222 echo ""
223 echo "*******************************************************************"
224 echo "Note: There are ONLY 4 ROMTYPES: [pa, cm, aokp, and aosp]."
225 echo ""
226 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
227 echo ""
228 echo "!!! Do not put Android Version number on command line !!!!"
229 echo "*****************************************************************"
230 echo "Specific auto_patcher script options"
231 echo " ./auto_patcher -h mods Lists mods"
232 echo " -h <MODNAME> Specific <MOD> info"
233 echo " -h advanced Advanced usage+lists all available patch dates"
234 echo ""
235 cleanup
236 exit
239 romtype_help () {
240 # From rom_error (bad romtype) and date_error (patch date w/o specifying romtype)
241 echo ""
242 echo "!!!There are only four supported ROMTYPES: 1) cm 2) aokp 3) aosp 4) pa"
243 echo ""
244 echo "Find out which of the above ROMTYPES your rom is based on and try again!"
245 echo "**********************************************"
246 echo ""
247 cleanup
248 brief_help
251 advanced_help () {
252 echo ""
253 echo "The Auto-Patcher Advanced Usage"
254 echo "*********************************"
255 echo ""
256 echo "For those of you determined to try everything..."
257 echo ""
258 echo "You can also try adding a patch date as a final argument."
259 echo ""
260 echo " ./auto_patcher <ROM> <MOD> <ROMTYPE> <DATE>"
261 echo ""
262 echo "Please note: There are only four ROMTYPES: {pa, aokp, aosp and cm}"
263 echo " -The various appellations after that are for internal use only!"
264 echo ""
265 echo "The Auto-Patcher has a pretty great rom probe, specifying the date is"
266 echo " deprecated...you don't need to, we promise."
267 echo ""
270 cleanup () {
271 [[ -n $ROOT ]] && \rm -rf "$ROOT"/tmp*
274 garbage () {
275 unset GARBAGE
276 GARBAGE=($(find $@ -name "*.orig")) && rm -rf ${GARBAGE[@]} && echo "GARBAGE= ${GARBAGE[@]}" >> "$LOG"
277 GARBAGE=($(find $@ -name "*.rej")) && rm -rf ${GARBAGE[@]} && echo "GARBAGE= ${GARBAGE[@]}" >> "$LOG"
281 print_error () {
282 # General purpose error. Used for errors in main, as opposed to probe or set-up.
283 echo ""
284 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
285 printtask "!!! error: $@"
286 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
287 echo ""
288 brief_help
291 smali_error () {
292 # Smali binary error. Problem often goes away on second run.
293 echo ""
294 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
295 printtask "!!! error: $@"
296 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
297 echo ""
298 if [[ $(grep 'method index is too large' "$LOG") != "" ]]; then
299 printtask "!!! Problem with method cap !!!"
300 printtask "... attempting fix ..."
301 . patches/.common/framework.jar.sh 2>&1 > ${JAR}.log
302 printtask "... rebuild framework.jar ..."
303 java -Xmx512M -jar smali.jar -a $API tmp/${FILE}.out/smali -o tmp/${FILE}.out/classes.dex >> "$LOG" 2>> "$LOG"
304 [ -f tmp/${FILE}.out/classes.dex ] || print_error "Could not resolve method cap issue- please submit log"
305 else
306 printtask "!!! This error is generally due to an unknown bug in the smali binary!"
307 echo "In our experience, it goes away if you run the patcher a second time."
308 echo " Please run the Auto-Patcher with the same command once again."
309 echo ""
310 echo "If after the third attempt the same thing happens,"
311 echo " please upload your logfile to our support thread!"
312 echo ""
313 cleanup
314 exit
318 unknown_mod_error () {
319 echo ""
320 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
321 printtask "!!! error: $@"
322 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
323 echo ""
324 cleanup
325 printusage_help
328 mismatch_error () {
329 # Function that exposes attempts to apply a mod to an upsupported Android version
330 echo ""
331 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
332 printtask "!!! error: $@"
333 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
334 echo ""
335 cleanup
336 brief_help
339 date_error () {
340 # Remind users to include a romtype if they are going to specify a patch date
341 echo ""
342 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
343 printtask "!!! error: $@"
344 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
345 echo ""
346 echo "Please put a ROMTYPE before the patch date and run again!!"
347 romtype_help
350 rom_error () {
351 # For when an unsupported romtype is manually entered on the command-line
352 echo ""
353 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
354 printtask "!!! error: $@"
355 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
356 romtype_help
359 conflict_error () {
360 # For conflicting packages
361 echo ""
362 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
363 printtask "!!! error: $@"
364 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
365 cleanup
366 PID=mods
367 mods_info
370 misspatch_error () {
371 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
372 printtask "!! error: $@ "
373 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
374 echo ""
375 printtask "!! The Auto-Patcher could not find its patches and/or tools!"
376 echo ""
377 echo "* Did you run ./batch.sh first?"
378 echo ""
379 echo "The patch_patches.tgz and patch_tools.tgz need to be in this directory,"
380 echo " one way or another..."
381 echo ""
382 cleanup
383 brief_help
386 misstools_error () {
387 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
388 printtask "!! error: $@ "
389 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
390 printtask "Your set-up is missing a dependency."
391 echo "We require JDK, tar, patch and cpio."
392 echo ""
393 echo ""
394 echo "Each distro is different"
395 echo "but ensure you have them all installed and try again."
396 echo ""
397 cleanup
398 brief_help
401 miss_git_error () {
402 echo "Updater: disabled"
403 echo ""
404 printtask "You will not be able to get automatic updates because we could not find 'git'."
405 printtask "Find out how to install git for your system and that feature should work automatically"
406 echo ""
409 printtask () {
410 echo "" >> "$LOG"
411 echo -e $@ | tee -a "$LOG"
414 print_to_log () {
415 echo "$@" >> "$LOG"
418 copy_prepatched_provisional () {
419 print_to_log "File for which patching failed:"
420 print_to_log "---------------------------------------------"
421 print_to_log ""
422 print_to_log "${FAIL##*/}"
423 print_to_log ""
424 print_to_log "---------------------------------------------"
425 print_to_log ""
426 print_to_log "We are adding a pre-patched copy of those files."
427 print_to_log ""
428 print_to_log "Please only file a bug report if running the program gives you problems!!!"
429 print_to_log "... replace $FAIL ..."
430 \rm -rf tmp/${FILE}.out/smali/${FAIL} tmp/${FILE}.out/smali/${FAIL}.orig tmp/${FILE}.out/smali/${FAIL}.rej
431 \cp -av "$PROVISIONAL" tmp/${FILE}.out/smali/${FAIL} >> "$LOG" 2>&1
432 SID=(${SID[@]} $FAIL)
433 print_to_log "... failed patch sucessfully resolved ..."
436 prep_alternate_patch () {
437 # Use alt.patch, if exists. Increment in case there are multiple alternates.
438 mv -v $ALTERNATIVE_PATCH $PARB/${NAME}.patch >> "$LOG"
439 ALT_PATCH_NUMBER=$((PATCH_NUMBER + 1))
441 # Get fresh files/variables + decompile again (use rm b/c privacy files wouldn't get overwritten)
442 rm -rf tmp/${FILE}.out/smali
443 java -jar baksmali.jar -b -a $API -o tmp/${FILE}.out/smali ${FILE} >> "$LOG" 2>> "$LOG"
444 unset FAILS && unset SID
445 current_jar=$(($current_jar - 1))
446 break
449 no_network_access () {
450 ping -c1 www.github.com >> "$LOG" 2>&1 && NETWORK=true # second try and check github
451 ping -c1 www.google.com >> "$LOG" 2>&1 # test for internet in general
452 if [[ "$NETWORK" == true ]]; then
453 return
454 else
455 printtask "Check for update failed, probably because of no internet access."
456 echo "The autopatcher will continue with current local version: $VERSION"
457 NETWORK=false
458 echo ""
459 sleep 2
463 auto_update_error () {
464 echo ""
465 printtask "### Update failed ###"
466 printtask ""
467 printtask "It appears you may have made some changes to the script that prevent automatic updating."
468 printtask "You could run 'git reset --hard' to return the autopatcher to its original form"
469 printtask " or set AUTO_UPDATE to false in the .config file to stop getting this message."
470 echo ""
471 printusage_help
474 backup_script () {
475 printtask "... backing up auto_patcher to auto_patcher.bak ..."
476 cp -av auto_patcher auto_patcher.bak >> "$LOG" #backup for user in case of changes
477 echo ""
480 warn_of_overwrite () {
481 # Only seen once, by users without ".git" directories
482 # Only users who got program @ download page see this, all others (ApG included) use git
483 echo "This is a one time set-up process that will overwrite all local changes!"
484 echo "If this is not ok with you press ctrl-C and set AUTO_UPDATE to false in .config"
485 echo ""
488 establish_repo() {
489 printtask "### establishing the repo ###"
490 echo "... please be patient, this should only be needed once ..."
491 echo ""
492 git clone https://github.com/mateor/auto-patcher >> "$LOG" || no_network_access
493 if ($NETWORK); then
494 mv -v auto-patcher/".git" . >> "$LOG"
495 rm -rf auto-patcher
496 git checkout -q master || auto_update_error
497 git reset --hard 2>&1 >> "$LOG"
498 echo ""
502 export_log_and_variables () {
503 cp -a "$LOG" .updated.log
504 rm -If "$LOG"
505 AUTO_PATCHER_OLD_VERSION=$VERSION
506 AUTO_PATCHER_OLD_PATCHES_VERSION=$PATCHES_VERSION
507 AUTO_PATCHER_WAS_UPDATED=true
510 print_changelog () {
511 CHANGELOG="changelog.txt"
512 echo "" > "$CHANGELOG"
513 CURRENT_HEAD=$(git rev-parse HEAD)
514 echo "Changelog from Autopatcher$AUTO_PATCHER_OLD_VERSION to Autopatcher$VERSION" >> "$CHANGELOG"
515 echo "---------------------------------------------------------------------------" >> "$CHANGELOG"
516 echo "" >> "$CHANGELOG"
517 echo " Get more info about any individual commit by entering 'git show \$NUMBER'" >> "$CHANGELOG"
518 echo "" >> "$CHANGELOG"
519 git log --pretty=oneline $ORIGINAL_HEAD...$CURRENT_HEAD >> changelog.txt
520 printtask "... "$CHANGELOG" has been updated ..."
523 replace_updater () {
525 # Function for devices that use SDcard installs. Also to be tested for CM7
526 # since CM7 seems to use an updater-script that wipes EMMC. Testing
528 \rm $UPDATER_LOC/$UPDS 2>&1
529 \cp patches/.common/$UPDATER_LOC/$UPDS $UPDATER_LOC >> "$LOG" 2>&1
530 echo "run_program(\"/sbin/busybox\", \"umount\", \"/system\");" >> UPDATE.txt
531 cat UPDATE.txt >> $UPDATER_LOC/$UPDS
532 echo ""
533 echo "New updater-script being used:" >> "$LOG"
534 echo "-----------------------------" >> "$LOG"
535 cat $UPDATER_LOC/$UPDS >> "$LOG"
538 abspath () {
539 case $(uname -s) in
540 CYGWIN*)
541 echo $(cygpath -ua "$1") | sed 's:/$::g'
543 Darwin)
544 #[[ $(echo $1 | awk '/^\//') == $1 ]] && echo "$1" || echo "$PWD/$1"
545 [[ ${1:0:1} == "/" ]] && echo "$1" || echo "$PWD/$1"
547 Linux)
548 echo $(readlink -f "$1")
551 if [[ ${1:0:1} == "/" ]]; then
552 echo "$1"
553 elif [[ ${1:0:2} == "./" ]]; then
554 echo "$PWD/${1:2}"
555 else
556 echo "$PWD/$1"
559 esac
562 mods_display () {
563 echo ""
564 echo "The Auto-Patcher $VERSION"
565 echo "*******************************"
566 echo ""
567 echo "The available mods are"
568 echo "****************************************************"
569 echo "* pdroid openpdroid voice v6supercharger *"
570 echo "* voice insecure secure external_internal *"
571 echo "* tabletUI 3gdongle pd2.0 *"
572 echo "****************************************************"
573 echo ""
574 echo "To find out more about any mod, simply enter:"
575 echo " ./auto_patcher -h <MODNAME>"
576 echo ""
577 cleanup
580 mods_info () {
581 # Defaults
582 DEPENDENCY="None"
583 DEV="Unknown"
584 CEILING=$CURRENT_ANDROID
585 ROM_CONFLICTS="None"
586 UNKNOWN_MOD=false
587 case $PID in
588 mods)
589 mods_display
590 exit
592 auto*)
593 echo ""
594 echo "**************************************"
595 echo "The Auto-Patcher ate a kitten once..."
596 echo "**************************************"
597 echo ""
598 DEV="mateor and Caldair"
599 WEBSITE="https://github.com/mateor/auto-patcher"
600 printusage_help
602 advanced)
603 cd patches/
604 (advanced_help && find -H * -name 201*) | more -d
605 echo ""
606 brief_help
608 voice)
609 FLOOR=4.0.0
610 DESC="Use on wifi-only tablets to have the software register as 'voice-enabled'. Allows VOIP like Google Voice to function."
611 DESC="bongostl's setup method can be seen at the link."
612 WEBSITE="http://forum.xda-developers.com/showthread.php?t=1823701"
613 DEV="bongostl"
615 v6 | v6supercharger)
616 FLOOR=4.0.0
617 CEILING=4.2.2
618 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."
619 DEV="Zeppelinrox"
620 DEPENDENCY="The V6 Supercharger Script. Get it at the link"
621 WEBSITE="http://forum.xda-developers.com/showthread.php?t=991276"
623 PID="v6supercharger" # allows shorthand 'v6' to find patches.
625 pdroid)
626 FLOOR=2.3.7
627 CEILING=4.1.2
628 DESC="Security Software that manages access to personal data w/o causing FC's. No longer under development."
629 DESC1="Try the open-source expansion of this program, OpenPdroid."
630 DESC2="(It's the 'openpdroid' mod within the Auto-Patcher)."
631 DEV="Svyat"
632 DEPENDENCY="The Pdroid app. You can get it at the link"
633 WEBSITE="http://forum.xda-developers.com/showthread.php?t=1923576"
636 pd2.0)
637 FLOOR=4.1.2
638 CEILING=4.1.2
639 DESC="An expansion of the PDroid application/framework."
640 DEV="CollegeDev"
641 DEPENDENCY="The free PDroid2.0 app available at the link"
642 WEBSITE="http://forum.xda-developers.com/showthread.php?t=1923576"
644 openpdroid)
645 FLOOR=4.1.2
646 CEILING=4.2.2
647 DESC="A fork of the open-source PDroid and Pdroid2.0 framework."
648 DEV="CollegeDev/FFU5y/wbedard/mateorod/Community"
649 DEPENDENCY="PDroidManager(opensource) or PDroid2.0(CollegeDev)"
650 WEBSITE="http://forum.xda-developers.com/showthread.php?t=1994860"
652 opendroid)
653 echo ""
654 echo "No mod named 'opendroid'. You probably mean 'openpdroid'. Try again."
655 PID="mods"
656 mods_info
658 external_internal)
659 FLOOR=2.3.3
660 CEILING=4.1.2
661 DESC="Swap internal and external storage."
663 insecure)
664 FLOOR=2.3.3
665 DESC="Make any boot.img insecure and allow remount as well as adb push/pull of system files. True root."
667 secure)
668 FLOOR=2.3.3
669 DESC="Make any boot.img secure."
671 3gdongle)
672 FLOOR=4.1.0
673 CEILING=4.2.2
674 DESC="Allows 3gdongles to work on wifi tablets w/o 3rd party applications."
675 DEV="trevd"
676 DEPENDENCY="None, but read the troubleshooting guide at the link"
677 WEBSITE="http://forum.xda-developers.com/showthread.php?t=1798631"
679 tabletUI)
680 FLOOR=4.1.0
681 CEILING=4.2.2
682 if [[ $ANDR == "4.2" ]]; then
683 ROM_CONFLICTS=(pa .aosp-ever aokp)
684 else
685 ROM_CONFLICTS=(pa .aosp-slim)
687 DESC="Changes the user interface of Phones and Phablets to the popular Tablet UI."
688 DEV="barmullio/Caldair"
689 WEBSITE="http://forum.xda-developers.com/showthread.php?t=2154075"
692 UNKNOWN_MOD=true
693 FLOOR=?????
694 CEILING=?????
695 DESC="??? Unknown modtype ??? Check your spelling or the mod list!"
696 DESC1=" Try: \"./auto_patcher -h mods\""
697 esac
699 # strip decimals from android version (i.e. 2.3.7 becomes 237) so we can do math
700 NVID=${VID//[.]/}
701 COMPATF=${FLOOR//[.]/}
702 COMPATC=${CEILING//[.]/}
705 apk_copy () {
706 if [ -f patches/$P/$A/$R/$B/$FILE ]; then
707 \cp -av patches/$P/$A/$R/$B/$FILE $FILE >> "$LOG" 2>&1
708 echo "... Patching $APK failed, but we have successfuly copied over a prepatched file ..."
709 apk_was_copied=true
710 else
711 print_error "failed patching $APK!!!"
715 no_mod_selected_error () {
716 echo ""
717 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
718 printtask "!!! error: $@"
719 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
720 echo ""
721 printtask "You need to enter a MOD before you try and specify the ROMTYPE."
722 printtask "Check the help menu for the list of available MODS"
723 echo ""
724 printusage_help
727 check_against_rom_types () {
728 # this checks to see if the user has entered a ROMTYPE in the MOD spot and outputs advice if so.
729 NUMBER_OF_AVAILABLE_ROMTYPES=${#AVAILABLE_ROMTYPES[@]}
730 for ((i=0; i < $NUMBER_OF_AVAILABLE_ROMTYPES; i++)); do
731 if [[ ${AVAILABLE_ROMTYPES[i]} == "$P" ]]; then
732 no_mod_selected_error "\"$P\" is a ROMTYPE not a MOD"
734 done
737 compat_check () {
738 for P in ${PID[@]}; do
739 mods_info
740 if ($UNKNOWN_MOD); then
741 check_against_rom_types
742 unknown_mod_error "\"$P\" is not a valid mod. Check your spelling or the mod list!!!"
743 elif [[ "$NVID" -lt "$COMPATF" ]]; then
744 mismatch_error "Your Android $VID rom is too old! The minimum for $P is \n !!! Android $FLOOR!"
745 elif [[ "$NVID" -gt "$COMPATC" ]]; then
746 mismatch_error "Sorry, $P has not been made available for Android $VID yet!"
748 done
751 rom_compat_check () {
752 for P in ${PID[@]}; do
753 N=${#ROM_CONFLICTS[@]}
754 for ((i=0; i < $N; i++)); do
755 if [[ $RID == ${ROM_CONFLICTS[$i]} ]]; then
756 rom_compat_error
758 done
759 done
762 rom_compat_error () {
763 print_error "$RID is incompatible with $PID!!!"
766 extpath () {
767 case $(uname -s) in
768 CYGWIN*)
769 echo $(cygpath -da "$1")
772 echo $(abspath "$1")
774 esac
777 #contains () { for e in "${@:2}"; do [[ "$e" = "$1" ]] && return 0; done; return 1; }
779 parse () { echo "${1%%_*}"; }
781 getbuildprop () {
782 if [ -f system/build.prop ]; then
783 result=($(grep $1 system/build.prop | tr -d '\r' | tr '=' ' '))
784 echo "${result[1]}"
785 else
786 echo ""
791 aosp_mod_check() {
792 jar -xvf "$ROMX" system/framework/framework2.jar >> "$LOG"
793 if [ -s system/framework/framework2.jar ]; then
794 ever_check
795 else
796 AOSP=aosp
798 echo $AOSP
801 ever_check() {
802 MID=$(getbuildprop ro.build.romversion)
803 if [[ $MID == "Evervolv"* ]]; then
804 AOSP=".aosp-ever"
805 else
806 MID=$(getbuildprop ro.build.display.id)
807 if [[ "$MID" == "ev"* ]]; then
808 AOSP=".aosp-ever"
809 else
810 pac_check
813 echo $AOSP
816 pac_check() {
817 MID=$(getbuildprop ro.build.romversion)
818 if [[ "$MID" == "pac"* ]] || [[ "$MID" == "PAC"* ]]; then
819 AOSP=".aosp-pac"
820 else
821 MID=$(getbuildprop ro.build.display.id)
822 if [[ "$MID" == "pac"* ]] || [[ "$MID" == "PAC"* ]]; then
823 AOSP=".aosp-pac"
824 else
825 slim_check
830 slim_check() {
831 SLMID=$(getbuildprop ro.modversion)
832 SLMMID=$(getbuildprop updateme.name)
833 if [[ "$SLMMID" == "Slim"* ]] || [[ $SLMMID == "slim"* ]]; then
834 AOSP=".aosp-slim"
835 elif [[ "$SLMID" == "Slim"* ]] || [[ $SLMID == "slim"* ]]; then
836 AOSP=".aosp-slim"
837 else
838 if [[ "$ANDR" == "4.1" ]]; then
839 AOSP=.aosp-mod
840 else
841 AOSP="aosp"
846 pa_check() {
847 CMID=$(getbuildprop ro.modversion)
848 PAID=$(getbuildprop ro.pa.version)
849 MID=$(getbuildprop ro.build.display.id)
850 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
851 DID=$(getbuildprop ro.product.device)
852 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
853 if [[ -n $PAID ]]; then
854 RID=pa
855 else
856 case $CMID in
857 [Pp][Aa]*)
858 RID=pa;
861 RID=cm;
863 esac
867 romtype_set () {
868 case $RID in
870 ROMTYPE="cm"
872 aokp*)
873 ROMTYPE="aokp"
876 ROMTYPE="pa"
879 ROMTYPE="aosp"
881 esac
884 proberom () {
885 VID=$(getbuildprop ro.build.version.release)
886 if [ ${#VID} -lt 4 ]; then # in case of non-standard versioning in build.prop (defy!)
887 ANDR=$VID
888 else
889 ANDR="${VID%.*}" # Cut to 1 significant digit to cover specific range or release.
891 if [ "$ANDR" == "2.3" ]; then
892 FLAVR=gingerbread
893 API=10
894 RID=cm;
895 elif [ "$ANDR" == "4.0" ]; then
896 FLAVR=ics
897 API=15
898 MID=$(getbuildprop ro.rommanager.developerid)
899 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.modversion))
900 DID=$(getbuildprop ro.product.device)
901 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
903 case "$MID" in
904 pa|cm9|cm|cyanogenmod*)
905 RID=cm;
907 aokp|teamkang)
908 RID=aokp;
910 aosp*)
911 RID=aosp;
914 echo "!!! $MID is not supported yet, trying aosp !!!"
915 RID=aosp
917 esac
918 elif [ "$ANDR" == "4.1" ]; then
919 FLAVR=jellybean
920 API=16
921 CMID=$(getbuildprop ro.cm.version)
922 if [[ -n $CMID ]]; then
923 pa_check
924 else
925 MID=$(getbuildprop ro.build.display.id)
926 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
927 DID=$(getbuildprop ro.product.device)
928 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
929 case "$MID" in
930 cm10|cm*|cyanogenmod*)
931 RID=cm;
933 aokp*|teamkang)
934 RID=aokp;
936 pa*)
937 RID=pa;
939 ev*)
940 RID=".aosp-ever";
943 RID=$(aosp_mod_check);
945 esac
947 elif [ "$ANDR" == "4.2" ]; then
948 FLAVR=jellybean
949 API=17
950 CMID=$(getbuildprop ro.cm.version)
951 MID=$(getbuildprop ro.build.display.id)
952 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
953 DID=$(getbuildprop ro.product.device)
954 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
956 case "$MID" in
957 cm10|cm*|cyanogenmod*)
958 RID=cm;
960 aokp*|teamkang)
961 RID=aokp;
963 [Pp][Aa]*)
964 if [[ "$MID" == "pac"* ]] || [[ "$MID" == "PAC"* ]]; then
965 RID=".aosp-pac"
966 else
967 RID=pa;
970 ev*|Ever*)
971 RID=".aosp-ever";
974 RID="$(ever_check)";
976 esac
977 else
978 print_error "unknown ROM version $VID: generally means cannot find/read build.prop"
980 # romtype_set allows hiding ".aosp-*" types from users while leaving them as options on CLI
981 romtype_set
982 echo "... result of ROM check: version= $VID rom= $ROMTYPE ..."
986 # Advanced build date query
987 # This should set the patch date automatically.
989 build_query() {
990 UTC=$(getbuildprop ro.build.date.utc)
992 # Difference in how OS X and Linux/Cygwin handles 'date' utility
993 case $(uname -s) in
994 [Dd]arwin)
995 BDID=$(date -r $UTC +%Y%m%d)
996 echo "#### Darwin Build Query used ####" >> "$LOG"
999 BDID=$(date -d "1970-01-01 UTC $UTC seconds" +"%Y%m%d")
1000 echo "#### Standard Build Query ####" >> "$LOG"
1002 esac
1004 # If patch date is specified on CLI, use that patch date
1005 if [ $# -gt 3 ]; then
1006 BID=${4//,/ };
1007 BDID=$BID
1008 else
1009 case $ANDR in
1010 2.3)
1011 # CM7 roms do not have UTC time stamp- so no build query.
1012 BID=latest;
1013 echo "*** CM7 roms default to latest patches. If using an older rom ***"
1014 echo "*** specify patch date on command line. Use -h to see available patches ***"
1017 for P in ${PID[@]}; do
1018 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1019 [ -d patches/$P/$A/"$RID" ] && R=$RID || R=generic
1020 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1021 PAR=patches/$P/$A/$R
1022 PARB=patches/$P/$A/$R/$B
1023 DATES=$(ls patches/$P/$A/"$R" | grep '201*')
1024 # Intialize variable - an upperbound to determine lowest in first loop.
1025 BID=20201231
1026 # find earliest available patch date
1027 for i in $DATES; do
1028 if [[ $i -lt $BID ]]; then
1029 BID=$i
1031 done
1032 # Check if earliest patches are from before build date. Else use earliest
1034 # If rom is newer than earliest patch set, find best match
1035 if [[ $(($BID-$BDID)) -lt 0 ]]; then
1036 for g in $DATES; do
1037 # use any patch that matches $UTC
1038 if [[ $(($BDID-$g)) -eq 0 ]]; then
1039 BID=$g
1040 break
1041 # Set highest $BID w/o going over $UTC
1042 elif [[ $(($BDID-$g)) -gt 0 ]] && [[ $g -gt $BID ]]; then
1043 BID=$g
1045 done
1047 # Error catch if query fails.
1048 [[ $BID == "20201231" ]] && BID=latest && echo "Build Query Failed!! Default to latest!" >> "$LOG"
1049 echo "... $PID patch date has been set to: $BID ..."
1050 B=$BID
1051 break
1052 done
1054 esac
1058 proberil () {
1059 RIL=$(getbuildprop ro.telephony.ril_class)
1060 [[ -n $RIL ]] && printtask "... result of ROM check: RIL= $RIL"
1063 rominfo () {
1064 echo "# VER= $VERSION" >> "$LOG"
1065 echo "# OS= $OSTYPE ${BIT}bit" >> "$LOG"
1066 echo "# VID= $VID" >> "$LOG"
1067 echo "# PID= ${PID[@]}" >> "$LOG"
1068 echo "# MID= $MID" >> "$LOG"
1069 echo "# RID= $RID" >> "$LOG"
1070 echo "# ANDR= $ANDR" >> "$LOG"
1071 echo "# BDID= $BDID" >> "$LOG"
1072 echo "# DID= $DID" >> "$LOG"
1073 echo "# BID= $BID" >> "$LOG"
1074 echo "Patches are $PID/$ANDR/$RID/$BID" >> "$LOG"
1076 if [ -d ../".git" ]; then
1077 echo "" >> "$LOG"
1078 echo -n "Current HEAD: " >> "$LOG"
1079 git log --pretty=oneline HEAD^..HEAD >> "$LOG"
1080 echo "" >> "$LOG"
1085 if [[ $1 == -h ]]; then
1086 if [ $# -gt 1 ]; then
1087 PID=$2
1088 mods_info
1089 echo ""
1090 echo "The Auto-Patcher $VERSION by Mateorod and Pastime1971"
1091 echo "*************************************************"
1092 echo ""
1093 echo "Mod Name: $PID"
1094 echo ""
1095 echo " $DESC"
1096 if [[ $DESC1 ]]; then # test to see is there is a second DESC line
1097 echo " $DESC1"
1099 if [[ $DESC2 ]]; then
1100 echo -n "$DESC2"
1102 echo ""
1103 echo "Developer: $DEV"
1104 echo "Dependancies: $DEPENDENCY"
1105 if [[ $WEBSITE ]]; then
1106 echo "Website: $WEBSITE"
1108 echo ""
1109 echo "Works on ROMs from Android $FLOOR -> $CEILING"
1110 echo
1111 brief_help
1112 exit
1116 [[ $# -lt 1 || -z $1 ]] && PID="mods" && mods_info
1117 [[ $1 == "-h" ]] && usage_help | less && display_help
1119 echo ""
1120 echo "The Auto-Patcher $VERSION"
1121 # by pastime1971 and mateorod
1122 if [[ -n "$AUTO_PATCHER_WAS_UPDATED" ]]; then
1123 echo " (auto-updated from $AUTO_PATCHER_OLD_VERSION)"
1124 print_changelog
1126 echo ""
1128 ROOT="$(abspath "$(dirname "$(abspath "$(type -p "$0")")")")"
1129 TOOL="$ROOT/patch_tools.tgz"
1130 PTCH="$ROOT/patch_patches.tgz"
1131 cleanup
1132 # set temporaray directory
1133 DATE=$(date +%Y%m%d%H%M%S)
1134 TEMP="$ROOT/tmp$DATE"
1135 TMP="$ROOT/tmp$DATE"
1136 TMPDIR="$ROOT/tmp$DATE"
1137 mkdir "$TEMP"
1138 ROM=$(abspath "$1")
1139 ROMX=$(extpath "$1")
1141 if [[ $OSTYPE == "cygwin" ]]; then
1142 EXE=".exe"
1143 PGFORM="0x"
1144 AUTO_UPDATE=false # CYGWIN AUTO_UPDATE TESTERS COMMENT THIS LINE HERE!
1147 LOG=$(abspath ./log$DATE.txt)
1148 #echo $ROOT $TOOL $ROM $TEMP "$LOG"
1149 echo "ROOT= $ROOT" >> "$LOG"
1150 echo "TOOL= $TOOL" >> "$LOG"
1151 echo "ROM= $ROM" >> "$LOG"
1152 echo "ROMX= $ROMX" >> "$LOG"
1155 # Auto-Update # excluding ApG/cygwin for now until I talk with kobik.
1156 # To turn off auto updating, set AUTO_UPDATE in .config to false
1158 # Check for git
1159 (which git >> "$LOG" && GIT=true) || (miss_git_error "Missing \"git\" utility" && GIT=false)
1161 # If program was updated, merge the logs
1162 if [[ -n "$AUTO_PATCHER_WAS_UPDATED" ]]; then
1163 cat .updated.log >> "$LOG"
1164 rm -If .updated.log
1167 if [[ "$AUTO_UPDATE" == true ]] && [[ "$GIT" == true ]]; then
1168 ping -c1 www.github.com > /dev/null 2>&1 && NETWORK=true || no_network_access
1169 if [[ "$NETWORK" == true ]]; then
1170 printtask "### checking for updates ###"
1172 # establish the repo if not already present- one time operation.
1173 if [ ! -d ".git" ]; then
1174 printtask "... initial setup to allow automatic updating ..."
1175 backup_script && warn_of_overwrite
1176 establish_repo && export_log_and_variables
1177 printtask "### rerunning script with latest version ###"
1178 $0 "$@"
1179 exit 0
1182 # Here is the regular update process
1183 git fetch origin 2>&1 >> "$LOG" || no_network_access
1184 if !("$NETWORK"); then
1185 printtask "Updater: not able to run auto_update."
1186 else
1187 COMMITS_BEHIND=$(git rev-list HEAD..origin/master --count)
1188 case "$COMMITS_BEHIND" in
1190 printtask "Updater: Auto-Patcher is already up to date"
1193 ORIGINAL_HEAD=$(git rev-parse HEAD)
1194 printtask "... Updater: update found ..."
1195 backup_script
1196 printtask "... Updating Auto-Patcher ..."
1197 git merge --no-edit origin/master 2>&1 >> "$LOG" || auto_update_error
1198 export_log_and_variables
1199 printtask "### updated, now rerunning script with latest version ###"
1200 $0 "$@"
1201 exit 0
1203 esac
1204 echo ""
1209 if [[ -n "$AUTO_PATCHER_WAS_UPDATED" ]]; then
1210 if [[ $PATCHES_VERSION -gt $AUTO_PATCHER_OLD_PATCHES_VERSION ]]; then
1211 echo "... integrating new patches ..."
1212 sh batch.sh >> /dev/null 2>> "$LOG"
1216 #remove old zips, if built under identical parameters.
1217 \rm -f $RESTORE.zip $UPDATE.zip
1219 CHK=$(getconf LONG_BIT)
1220 if [[ $CHK = "64" ]]; then
1221 BIT=64
1222 else [[ $BIT = "32" ]];
1223 BIT=32
1226 printtask "### verify tools ###"
1227 which patch >> "$LOG" || misstools_error "Missing \"patch\" utility."
1228 which tar >> "$LOG" || misstools_error "Missing \"tar\" utility"
1229 which jar >> "$LOG" || misstools_error "Missing \"Java Development Kit\" (JDK)"
1230 which java >> "$LOG" || misstools_error "Missing \"Java Development Kit\" (JDK)"
1231 which cpio >> "$LOG" || misstools_error "Missing \"cpio\" utility"
1232 [ -f "$TOOL" ] || misspatch_error "patch_tool.tgz is missing"
1233 [ -f "$PTCH" ] || misspatch_error "patch_patches.tgz is missing"
1234 printtask "### verify ROM ###"
1235 [ -f "$ROM" ] || print_error "Cannot find $1!! Make sure you have the location and name right"
1236 echo "### running $0 $@" >> "$LOG"
1237 cd "$TEMP"
1239 PATH="$TEMP:$PATH"
1240 export PATH
1241 echo "PATH= $PATH" >> "$LOG"
1243 printtask "### unzip patch tools ###"
1244 tar xzf "$TOOL" > /dev/null || print_error "failed extracting tools !!!"
1246 # Get OS specific tools
1247 case $(uname -s) in
1248 CYGWIN*)
1249 \mv cygwin/aapt.exe .
1250 \mv cygwin/*.exe boot/
1251 \rm -rf cygwin # why? If you want to we can keep/add it to mac/linux, though.
1253 [Dd]arwin)
1254 \mv mac/aapt .
1256 [Ll]inux)
1257 \mv linux/aapt .
1260 \mv linux/aapt .
1262 esac
1263 # Ensure aapt permissions - possibly to one day be expanded to all tools in a function.
1264 chmod a+x aapt$EXE
1266 printtask "### unzip patch patches ###"
1267 tar xzf "$PTCH" > /dev/null || print_error "failed extracting patches !!!"
1269 # we need build.prop for both RIL probing and ROM probing
1270 jar -xvf "$ROMX" system/build.prop 2>> "$LOG" || print_error "failed extracting build.prop from $ROMX !!!"
1272 # rom + ril type
1273 proberil
1274 printtask "### probe rom type ###"
1275 proberom
1277 # rom type
1278 if [ $# -gt 1 ]; then
1279 PIT=$2
1280 if [[ "$PIT" = "-h" ]]; then
1281 display_help
1285 if [ $# -gt 2 ]; then
1286 RID=$3
1287 case "$RID" in
1288 cm*|cyanogenmod*)
1289 RID=cm;
1291 aokp*|teamkang)
1292 RID=aokp;
1294 pa*)
1295 RID=pa;
1297 .aosp-ever)
1298 RID=".aosp-ever";
1300 .aosp-slim)
1301 RID=".aosp-slim"
1303 .aosp-pac)
1304 RID=".aosp-pac"
1306 aosp*)
1307 case "ANDR" in
1308 4.1)
1309 RID=$(aosp_mod_check);
1312 RID=$(ever_check)
1314 esac
1316 201*)
1317 date_error "You must specify ROMTYPE if designating a patch date!!"
1320 rom_error "$RID is not a valid ROMTYPE!!"
1322 esac
1323 romtype_set
1324 echo "... Using $ROMTYPE patches ..."
1325 else
1326 echo "... Using results of ROM check ..."
1329 # patch type
1330 if [ $# -gt 1 ]; then
1331 PIL=${2//,/ } # If more than one mod, make string separated by spaces
1332 else
1333 PIL="openpdroid"
1334 echo "No mods selected. Defaulting to openpdroid, since that's what you probably want..."
1337 # Ensure only 1 Pdroid mod at a time; PDroid first, so provisionals do not overwrite other mods...
1339 PID=(${PIL// / }) # turn string of requested mods into array
1340 COPYPID=("${PID[@]}") # working copy to iterate over
1341 MODS_NUMBER=${#COPYPID[@]} # number of elements (mods)
1343 if [[ $MODS_NUMBER > 1 ]]; then # because if only one mod, not needed
1344 INDEX=0 # 'pd2.0' didn't work with unset; regex use bars multiple 'pdroid's
1345 for p in ${COPYPID[@]}; do
1346 if [ "$p" = "pdroid" ] || [ "$p" = "pd2.0" ] ||[ "$p" = "openpdroid" ]; then
1347 SPID[0]=$p #set pdroid first
1348 unset COPYPID["$INDEX"]
1349 break
1350 else
1351 INDEX=$((INDEX + 1)) # if (!pdroid), set as 1, 2...
1353 done
1354 for p in ${COPYPID[@]}; do
1355 if [ "$p" = "pdroid" ] || [ $p = "pd2.0" ] ||[ $p = "openpdroid" ]; then
1356 conflict_error "Those mods conflict! Only one pdroid mod at a time!"
1357 else
1358 i=${#SPID[@]}
1359 SPID[i]=$p
1360 i+=1
1362 done
1363 else
1364 SPID=${COPYPID[@]}
1366 for P in ${PIL[@]}; do
1367 [[ ${PID[@]} =~ $P ]] || PID=(${PID[@]} $P)
1368 done
1370 # Check if selected mods are available for rom's Android version.
1371 compat_check
1373 # Make sure mod and rom don't conflict (e.g. pa and tabletUI)
1374 if [[ $ROM_CONFLICTS != "None" ]]; then
1375 rom_compat_check
1378 # Build date
1379 if [ $# -gt 3 ]; then # if a date is specified on command line...
1380 # Set date to match argument and ensure that patches with that date exist
1381 BID=$4
1382 [ -d patches/$P/$ANDR/$RID/$BID ] || print_error "No $P patches for $RID on $BID!! Try the help menu!!"
1383 # Run build_query- this overrides the above but gets useful info
1384 build_query
1385 # Reset patch date to argument (basically undo the effects of the build_query call)
1386 BID=$4
1387 echo "... $PID patch date set manually to: $BID ..."
1388 else
1389 build_query # if no date specified, use one from build_query
1392 # echo ROM info
1393 rominfo
1395 if [[ ( "$PID" == "-h" || "$RID" == "-h" || "$BID" == "-h" ) ]]; then
1396 #Although this placement may be perfect for romfilter. although it throws the scheme...
1397 display_help
1399 #Begin cycle
1401 for P in ${PID[@]}; do
1402 [ -d patches/$P ] || print_error "$P is not available"
1403 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1404 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1405 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1407 unset FILES
1408 [ -f patches/$P/files.txt ] && FILES=$(cat patches/$P/files.txt)
1409 [ -f patches/$P/$A/files.txt ] && FILES=$(cat patches/$P/$A/files.txt)
1410 [ -f patches/$P/$A/$R/files.txt ] && FILES=$(cat patches/$P/$A/$R/files.txt)
1411 [ -f patches/$P/$A/$R/$B/files.txt ] && FILES=$(cat patches/$P/$A/$R/$B/files.txt)
1412 for FILE in ${FILES[@]}; do
1413 case "$FILE" in
1414 +system/*)
1415 [[ ${CID[@]} =~ ${FILE:1} ]] && print_error "${FILE:1} is already being copied" || CID=(${CID[@]} ${FILE:1})
1417 -system/*)
1418 [[ ${EID[@]} =~ ${FILE:1} ]] || EID=(${EID[@]} ${FILE:1})
1420 system/*.jar)
1421 [[ ${JID[@]} =~ $FILE ]] || JID=(${JID[@]} $FILE)
1422 echo "set_perm(0, 0, 0644, \"/$FILE\");" >> UPDATE.txt
1424 # added for the use-case of apktool failure
1425 ~system/*apk) # apks to decompile with smali binaries instead of apktool
1426 [[ ${JID[@]} =~ ${FILE:1} ]] || JID=(${JID[@]} ${FILE:1})
1427 FORMATTED_FILE=${FILE:1}
1428 echo "set_perm(0, 0, 0644, \"/$FORMATTED_FILE\");" >> UPDATE.txt
1430 system/*.apk)
1431 [[ ${AID[@]} =~ $FILE ]] || AID=(${AID[@]} $FILE)
1432 echo "set_perm(0, 0, 0644, \"/$FILE\");" >> UPDATE.txt
1433 # $APKID will have elements removed sometimes--$AID is the master list for the update.zip
1434 declare -a APKID=( "${AID[@]}" )
1436 *.img)
1437 [[ ${IID[@]} =~ $FILE ]] || IID=(${IID[@]} $FILE)
1439 system/*)
1440 [[ ${TID[@]} =~ $FILE ]] || TID=(${TID[@]} $FILE)
1442 esac
1443 done
1444 done
1445 echo "### DELETE FILES= ${EID[@]}" >> "$LOG"
1446 echo "### COPY FILES= ${CID[@]}" >> "$LOG"
1447 echo "### JAR FILES= ${JID[@]}" >> "$LOG"
1448 echo "### APK FILES= ${AID[@]}" >> "$LOG"
1449 echo "### IMG FILES= ${IID[@]}" >> "$LOG"
1450 echo "### TXT FILES= ${TID[@]}" >> "$LOG"
1452 # extract system files
1453 printtask "### unzip rom ###"
1454 jar -xvf "$ROMX" ${JID[@]} ${AID[@]} ${IID[@]} ${TID[@]} 2>> "$LOG" || print_error "failed extracting ${JID[@]} ${AID[@]} ${IID[@]} from $ROMX !!!"
1457 # Update/Restore.zip scripts and prep
1458 printtask "### create updater script ###"
1459 UPDATER_LOC=META-INF/com/google/android
1460 UPDS=updater-script
1461 UPDATE="update-$ROMTYPE-$DID-$BDID-${PIL// /-}"
1462 RESTORE="restore-$ROMTYPE-$DID-$BDID"
1464 jar -xvf "$ROMX" $UPDATER_LOC/$UPDS $UPDATER_LOC/update-binary
1465 jar -xvf "$ROMX" $UPDATER_LOC/update-binary-installer 1> /dev/null 2> /dev/null
1467 # Determine Installer- Aroma or ClockworkMod
1468 if [ -f $UPDATER_LOC/update-binary-installer ]; then
1469 printtask "... using Aroma installer ..."
1470 \mv $UPDATER_LOC/update-binary-installer $UPDATER_LOC/update-binary
1471 else
1472 printtask "... using Clockworkmod installer ..."
1475 # Create updater scripts
1476 cat patches/.common/updater-message.txt >> $UPDS
1477 cat $UPDATER_LOC/$UPDS | grep ^mount | grep "/system" | head -n 1 >> $UPDS
1478 [ -s $UPDS ] || echo "run_program(\"/sbin/busybox\", \"mount\", \"/system\");" >> $UPDS
1479 # restore the original
1480 for FILE in ${EID[@]}; do
1481 jar -xvf "$ROMX" $FILE 2> /dev/null || printtask "!!! warning $FILE cannot be restored !!!"
1482 done
1483 # replace with the original or delete it
1484 for FILE in ${CID[@]}; do
1485 jar -xvf "$ROMX" $FILE 2> /dev/null || echo "delete(\"/$FILE\");" >> $UPDS
1486 done
1487 echo "package_extract_dir(\"system\", \"/system\");" >> $UPDS
1488 # permission management for files that need specific perms
1489 cat $UPDATER_LOC/$UPDS | grep set_perm | grep "/system" >> $UPDS
1490 for P in ${PID[@]}; do
1491 if [ -s patches/$P/$A/set_perm.txt ]; then
1492 echo "...setting permissions..."
1493 cat patches/$P/$A/set_perm.txt >> $UPDS
1495 done
1496 cat $UPDATER_LOC/$UPDS | grep ^unmount | grep "/system" | head -n 1 >> $UPDS
1497 [[ ${IID[@]} =~ boot.img ]] && cat $UPDATER_LOC/$UPDS | grep "boot.img" >> $UPDS
1498 echo "ui_print(\" .\");" >> $UPDS
1499 echo "ui_print(\" .\");" >> $UPDS
1500 echo "ui_print(\" done!\");" >> $UPDS
1501 cat $UPDS > $UPDATER_LOC/$UPDS
1502 echo "# generated $UPDS" >> "$LOG"
1503 cat $UPDS >> "$LOG"
1505 printtask "### create restore.zip ###"
1506 jar -cvf tmp.zip ${JID[@]} ${AID[@]} ${IID[@]} META-INF > /dev/null 2>> "$LOG"
1507 java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip signed.zip 2>> "$LOG"
1508 \mv signed.zip $RESTORE.zip
1509 \rm -f tmp.zip
1512 # Begin patching process
1514 # decompile system files
1515 printtask "### decompile system files ###"
1516 for FILE in ${JID[@]}; do
1517 JAR=${FILE##*/}
1518 printtask "... decompile $JAR ..."
1519 java -jar baksmali.jar -b -a $API -o tmp/${FILE}.out/smali ${FILE} >> "$LOG" 2>> "$LOG"
1520 if [ $FILE == "system/framework/framework.jar" ]; then
1521 printtask "... extract preloaded-classes ..."
1522 jar -xvf ${FILE} preloaded-classes >> "$LOG" 2>> "$LOG"
1523 \mv preloaded-classes tmp/${FILE}.out/
1525 done
1527 # install framework-files for APK...
1528 if [ ${#AID[@]} -gt 0 ]; then
1529 jar -xvf "$ROMX" system/framework/framework-res.apk >> "$LOG"
1530 printtask "... installing framework files ..."
1531 java -jar apktool.jar if system/framework/framework-res.apk
1532 # Decompile APKs
1533 for FILE in ${AID[@]}; do
1534 APK=${FILE##*/}
1535 if [ -f $FILE ]; then
1536 printtask "... decompile $APK ..."
1537 java -jar apktool.jar d -f $FILE tmp/$FILE.out 2>> "$LOG"
1539 done
1542 # Unpack image files {boot.img only so far...}
1543 for FILE in ${IID[@]}; do
1544 printtask "### unpacking $FILE ###"
1545 case "$FILE" in
1546 boot.img)
1547 if [ -f boot.img ]; then
1548 cd boot
1549 ./unpackbootimg$EXE -i ../boot.img >> "$LOG" 2>> "$LOG"
1550 mkdir ramdisk
1551 cd ramdisk
1552 gzip -dc ../boot.img-ramdisk.gz | cpio -i >> "$LOG" 2>> "$LOG"
1553 cd ../../
1554 else
1555 print_error "A mod needs to patch boot.img! This rom does not contains boot.img."
1559 print_error "cannot process $FILE"
1561 esac
1562 done
1564 # apply system modification
1566 for P in ${PID[@]}; do
1567 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1568 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1569 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1570 PAR=patches/$P/$A/$R
1571 PARB=patches/$P/$A/$R/$B
1573 unset FILES COPY DELS JARS APKS IMGS TXTS
1574 [ -f patches/$P/files.txt ] && FILES=$(cat patches/$P/files.txt)
1575 [ -f patches/$P/$A/files.txt ] && FILES=$(cat patches/$P/$A/files.txt)
1576 [ -f patches/$P/$A/$R/files.txt ] && FILES=$(cat patches/$P/$A/$R/files.txt)
1577 [ -f patches/$P/$A/$R/$B/files.txt ] && FILES=$(cat patches/$P/$A/$R/$B/files.txt)
1578 for FILE in ${FILES[@]}; do
1579 case $FILE in
1580 +system/*)
1581 COPY=(${COPY[@]} ${FILE:1})
1583 -system/*)
1584 DELS=(${DELS[@]} ${FILE:1})
1586 system/*.jar)
1587 JARS=(${JARS[@]} $FILE)
1589 ~system/*)
1590 JARS=(${JARS[@]} ${FILE:1})
1592 system/*.apk)
1593 APKS=(${APKS[@]} $FILE)
1595 *.img)
1596 IMGS=(${IMGS[@]} $FILE)
1598 system/*)
1599 TXTS=(${TXTS[@]} $FILE)
1601 esac
1602 done
1604 [[ -n ${COPY[@]} ]] && echo "### copy patch $P/$A/$ROMTYPE/$B ###"
1605 echo "### copy patch $P/$A/$R/$B ###" >> "$LOG"
1606 for FILE in ${COPY[@]}; do
1607 printtask "... copying $FILE ..."
1608 DEST=${FILE%/*}
1609 mkdir -p ./$DEST
1610 if [ -e patches/$P/$A/$R/$B/$FILE ]; then
1611 printtask "... overwriting $FILE from $P ..."
1612 \cp -av patches/$P/$A/$R/$B/$FILE ./$DEST >> "$LOG" 2>&1
1613 elif [ -e patches/$P/common/$FILE ]; then
1614 printtask "... overwriting $FILE from $P ..."
1615 echo " ### SOMETHING WENT WRONG!! Could not find file-- using common. ###" >> "$LOG"
1616 \cp -av patches/$P/common/$FILE ./$DEST >> "$LOG" 2>&1
1617 else
1618 print_error "$FILE is missing in the patch. Please upload your logfile to the support thread!"
1620 done
1622 # unconditional smali copying- For particularly troublesome files
1623 [ -f patches/$P/smali.txt ] && SMALI=$(cat patches/$P/smali.txt)
1624 [ -f patches/$P/$A/smali.txt ] && SMALI=$(cat patches/$P/$A/smali.txt)
1625 [ -f patches/$P/$A/$R/smali.txt ] && SMALI=$(cat patches/$P/$A/$R/smali.txt)
1626 [ -f patches/$P/$A/$R/$B/smali.txt ] && SMALI=$(cat patches/$P/$A/$R/$B/smali.txt)
1627 MOVE=${SMALI##*/}
1628 for SMALI in ${SMALI[@]}; do
1629 if [ -f patches/$P/$A/$R/$B/$SMALI ]; then
1630 printtask "... overwriting $MOVE ..."
1631 \cp -a patches/$P/$ANDR/$R/$B/$SMALI tmp/$SMALI >> "$LOG" 2>&1
1632 # This lower area should be deprecated now...wait and see. Each BID has own link to provisionals now.
1633 elif [ -f patches/$P/$A/.provisionals/$SMALI ]; then
1634 printtask "... overwriting $MOVE ..."
1635 \cp -a patches/$P/$ANDR/.provisionals/$SMALI tmp/$SMALI >> "$LOG"
1637 done
1639 [[ -n ${DELS[@]} ]] && echo "### delete patch $P/$A/$ROMTYPE/$B ###"
1640 echo "### delete patch $P/$A/$R/$B ###" >> "$LOG"
1641 for FILE in ${DELS[@]}; do
1642 printtask "... deleting $FILE ..."
1643 \rm -rf ./$FILE
1644 done
1645 [[ -n ${JARS[@]} ]] && echo "### jar patch $P/$A/$ROMTYPE/$B ###"
1646 echo "### jar patch $P/$A/$R/$B ###" >> "$LOG"
1648 # Iterate through jars and patch. If fails, try prepatched provisionals or look for alternative patch.
1649 ALT_PATCH_NUMBER=2
1650 for (( current_jar=0; current_jar < ${#JARS[@]}; current_jar++)); do
1651 FILE=${JARS[$current_jar]}
1652 JAR=${FILE##*/}
1653 if [[ $FILE == *".jar" ]]; then # allows for *.apks to be decompiled by baksmali
1654 NAME=${JAR%.jar}
1655 else
1656 NAME=$JAR # TODO: Maybe rename this, since it now encompases apks at times
1658 printtask "... apply $NAME.patch ..."
1659 patch -Nls -p1 -d tmp/${FILE}.out < $PARB/${NAME}.patch 2>&1 > ${JAR}.log
1660 for INCREMENTAL in $(ls $PARB/${NAME}-*.patch 2>/dev/null); do
1661 printtask "... apply $(basename $INCREMENTAL) ..."
1662 patch -Nls -p1 -d tmp/${FILE}.out < $INCREMENTAL 2>&1 > ${JAR}.log
1663 done
1664 cat ${JAR}.log >> "$LOG"
1665 case "$NAME" in
1666 framework)
1667 # patch preloaded-classes only if a patch exists
1668 if [ -f $PARB/preloaded.patch ]; then
1669 printtask "... apply preloaded.patch ..."
1670 patch -Nls -p1 -d tmp/${FILE}.out < $PARB/preloaded.patch 2>&1 > preloaded.log
1671 cat preloaded.log >> "$LOG"
1672 [[ $(grep FAILED preloaded.log) != "" ]] && print_error "failed preloaded.patch"
1676 echo -n "" # do nothing else
1678 esac
1679 # substitute failed smali with provisional (a prepatched smali file)
1680 unset FAILS
1681 FAILS=($(grep FAILED ${JAR}.log | sed -e 's/.*smali\///' | sed -e 's/\.rej//'))
1682 if [[ -n ${FAILS[@]} ]]; then
1683 print_to_log "!!! PATCHING FAILED FOR ${FAILS[@]} !!!"
1684 echo "### replace ${FAILS[@]} ###" > ${JAR}.log
1685 for FAIL in ${FAILS[@]}; do
1686 PROVISIONAL="patches/$P/$ANDR/.provisionals/${FILE}.out/smali/${FAIL}"
1687 ALTERNATIVE_PATCH=$(ls $PARB/${NAME}$ALT_PATCH_NUMBER*.patch 2>/dev/null)
1688 if [ ! -f "$PROVISIONAL" ]; then
1689 if [ -f "$ALTERNATIVE_PATCH" ]; then
1690 printtask "## trying alternative ${NAME} patch ###"
1691 prep_alternate_patch
1692 else
1693 print_error "failed $FAIL in $JAR cannot be remedied"
1695 else
1696 echo "!!! patch error for $FAIL !!!" >> "$LOG"
1697 [[ ${SID[@]} =~ $FAIL ]] && print_error "$FAIL was already replaced before"
1698 copy_prepatched_provisional
1700 done
1702 [[ $(grep FAILED ${JAR}.log) != "" ]] && print_error "failed $NAME.patch"
1703 garbage tmp/${FILE}.out
1705 # run special $JAR.sh scripts if any JAR needs special attention
1706 if [ -f patches/$P/$A/$R/$B/${JAR}.sh ]; then
1707 printtask "... apply $JAR.sh ..."
1708 . patches/$P/$A/$R/$B/${JAR}.sh 2>&1 > ${JAR}.log
1709 cat ${JAR}.log | tee -a "$LOG"
1711 done
1713 [[ -n ${APKS[@]} ]] && echo "### apk patch $P/$A/$ROMTYPE/$B ###"
1714 echo "### apk patch $P/$A/$R/$B ###" >> "$LOG"
1715 for FILE in ${APKS[@]}; do
1716 APK=${FILE##*/}
1717 if [ -d "tmp/${FILE}.out" ] ; then
1718 printtask "... apply $APK.patch ..."
1719 patch -Nls -p2 -d tmp/${FILE}.out < $PARB/${APK}.patch 2>&1 > ${APK}.log
1720 cat ${APK}.log >> "$LOG"
1722 if [[ $(grep FAILED ${APK}.log) != "" ]]; then
1723 apk_copy
1724 declare -a APKID=( ${APKID[@]/$FILE/} )
1726 garbage tmp/${FILE}.out
1727 else
1728 echo "No $APK in your ROM. Not able to patch this file."
1729 echo "## No $APK in ROM ###" >> "$LOG"
1731 done
1732 [[ -n ${IMGS[@]} ]] && echo "### img patch $P/$A/$ROMTYPE/$B ###"
1733 echo "### img patch $P/$A/$R/$B ###" >> "$LOG"
1734 for FILE in ${IMGS[@]}; do
1735 IMG=${FILE##*/}
1736 printtask "... applying $IMG.patch ..."
1737 patch -Nls -p1 -d boot/ramdisk < $PARB/${IMG}.patch >> "$LOG" || print_error "failed patching $FILE"
1738 done
1740 # Text Editing Functions --this can really do just about anything. Needs a working restore!
1741 [[ -n ${TXTS[@]} ]] && echo "### text patch $P/$A/$ROMTYPE/$B ###"
1742 echo "### text patch $P/$A/$R/$B ###" >> "$LOG"
1743 for FILE in ${TXTS[@]}; do
1744 TXT=${FILE##*/}
1745 if [[ -f $PARB/${TXT}.patch ]]; then
1746 printtask "... apply $TXT.patch ..."
1747 patch -Nls -p2 -d system/ < $PARB/${TXT}.patch 2>&1 > ${TXT}.log
1748 #cat ${TXT}.log | tee -a "$LOG"
1749 [[ $(grep FAILED ${TXT}.log) != "" ]] && print_error "failed $TXT.patch"
1751 if [[ -f $PAR/${TXT}.awk ]]; then
1752 printtask "... apply $TXT.awk ..."
1753 awk -f $PAR/${TXT}.awk $FILE > text || print_error "failed $TXT.awk"
1754 mv text $FILE
1756 if [[ -f $PAR/${TXT}.sed ]]; then
1757 printtask "... apply $TXT.sed ..."
1758 sed -f $PAR/${TXT}.sed $FILE > text || print_error "failed $TXT.sed"
1759 mv text $FILE
1761 if [[ -f $PAR/${TXT}.sh ]]; then
1762 printtask "... apply $TXT.sh ..."
1763 . $PAR/${TXT}.sh 2>&1 >> ${TXT}.log || print_error "failed $TXT.sh"
1765 garbage system/
1766 done
1767 done
1769 # Device specific scripts- Placement is up-for-review
1770 if [ -f patches/.devices/$DID/$DID.sh ]; then
1771 . patches/.devices/$DID/$DID.sh
1774 # Replace updater-script for CM7- it formats system -Testing
1775 if [ "$ANDR" == "gingerbread" ]; then
1776 replace_updater
1779 # Rebuilding system files
1781 [[ -n ${JID[@]} ]] && printtask "### rebuild jar ###"
1782 for FILE in ${JID[@]}; do
1783 JAR=${FILE##*/}
1784 printtask "... rebuild $JAR ..."
1785 java -Xmx512M -jar smali.jar -a $API tmp/${FILE}.out/smali -o tmp/${FILE}.out/classes.dex >> "$LOG" 2>> "$LOG"
1786 [ -f tmp/${FILE}.out/classes.dex ] || smali_error "failed compiling $JAR !!!"
1787 jar -ufv ${FILE} -C tmp/${FILE}.out/ classes.dex >> "$LOG" 2>> "$LOG"
1788 if [ $FILE == "system/framework/framework.jar" ]; then
1789 jar -ufv ${FILE} -C tmp/${FILE}.out/ preloaded-classes >> "$LOG" 2>> "$LOG"
1791 done
1793 [[ -n ${APKID[@]} ]] && printtask "### rebuild apk ###"
1794 for FILE in ${APKID[@]}; do
1795 APK=${FILE##*/}
1796 if [ -d tmp/${FILE}.out ]; then
1797 apk_was_copied=false
1798 printtask "... rebuild $APK ..."
1799 java -jar apktool.jar b tmp/${FILE}.out >> "$LOG" 2>> "$LOG" || apk_copy
1800 if !("$apk_was_copied"); then
1801 jar -uvf $FILE -C tmp/${FILE}.out/build/apk/ . > /dev/null 2>> "$LOG"
1804 done
1806 [[ -n ${IID[@]} ]] && printtask "### rebuild img ###"
1807 for FILE in ${IID[@]}; do
1808 printtask "### rebuild $FILE ###"
1809 case $FILE in
1810 boot.img)
1811 # Rebuilding boot.img
1812 cd boot
1813 printtask "... rebuilding ramdisk ..."
1814 ./mkbootfs$EXE ./ramdisk | gzip > ramdisk-new.gz
1815 printtask "... composing boot.img ..."
1816 BASE=$(cat boot.img-base)
1817 # hex to decimal in cygwin prefixing "0x" w/ C arithmetic
1818 PGSIZE=$((${PGFORM}$(cat boot.img-pagesize)))
1819 CMDLINE=$(cat boot.img-cmdline)
1820 echo "cmdline = no_console_suspend=1 console=null $CMDLINE" >> "$LOG"
1821 echo "pagesize = $PGSIZE" >> "$LOG"
1822 echo "base = $BASE" >> "$LOG"
1823 printtask "... rebuilding boot.img ..."
1824 ./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"
1825 cd ..
1828 print_error "cannot process $FILE"
1830 esac
1831 done
1833 printtask "### create $UPDATE.zip ###"
1834 jar -cfv tmp.zip ${IID[@]} ${JID[@]} ${AID[@]} ${CID[@]} ${TID[@]} META-INF >> "$LOG" 2>> "$LOG"
1835 java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip $UPDATE.zip 2>> "$LOG"
1837 \mv $RESTORE.zip $UPDATE.zip ..
1838 printtask "### finished ###"
1839 printtask ""
1840 printtask "$(colorize_bold ${red}Congratulations), the patching was $(colorize_bold ${red}successful)."
1841 printtask "Any errors you may have seen were succesfully handled!"
1842 printtask ""
1843 printtask "!!! Only file a bug report if the software is $(colorize_bold ${grn}not) behaving as expected !!!"
1844 printtask ""
1845 echo "to install patched files, flash:"
1846 printtask "---$(colorize_bold ${grn}$UPDATE.zip)"
1847 echo ""
1848 printtask "to restore original system, flash:"
1849 printtask "---$(colorize_bold ${grn}$RESTORE.zip)"
1850 echo ""
1852 # add announcement- optional.
1853 for P in ${PID[@]}; do
1854 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1855 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1856 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1857 if [ -f patches/$P/$A/$R/$B/README.txt ]; then
1858 cat patches/$P/$A/$R/$B/README.txt
1859 elif [ -f patches/$P/$A/$R/README.txt ]; then
1860 cat patches/$P/$A/$R/README.txt
1861 elif [ -f patches/$P/$A/README.txt ]; then
1862 cat patches/$P/$A/README.txt
1864 done
1866 cd ..
1867 \rm -rf "$TEMP"