versioning to 2.9.89
[auto-patcher.git] / auto_patcher
blob6d1eebeca502b8dcf003a7b7b47ef29f69a8ccdf
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)
143 # SHELL PROGRAMMING NOTES:
144 # [ -s FILE ]
145 # [[ -n STRING ]] or [[ -z STRING ]]
147 VERSION="v2.9.89"
148 # PATCHES_VERSION needs to be incremented every time ANY changes occur to patches.
149 PATCHES_VERSION="20130628"
150 CURRENT_ANDROID="4.2.2"
152 # Available ROMTYPES.
153 # ROMTYPES that are hidden can be forced on the command line. But they are best left
154 # blank to be automatically parsed by our romprobe or by just entering the parent...usually AOSP.
156 #Non-obvious ROMTYPE legend
157 # @.aosp-slim: SlimRom @.aosp-pac: PAC-man
158 # @.aosp-ever: Evervolv @pa: ParanoidAndroid (official jellybean branch only for now)
159 declare -a AVAILABLE_ROMTYPES=('aokp' 'aosp' 'cm' 'pa' '.aosp-slim' '.aosp-pac' '.aosp-ever')
161 # pass variables to children
162 set -a
164 # Set any environmental variables
165 LANG=C
167 # Config file: For now hosting AUTO_UPDATE and PRODUCTION(currently unused). Not under version control.
168 if [ ! -f .config ]; then
169 cp -a ap_scripts/config_template .config
171 source .config
173 # Colorize and add text parameters
174 red=$(tput setaf 1) # red
175 grn=$(tput setaf 2) # green
176 cyan=$(tput setaf 6) # cyan
177 txtBold=$(tput bold) # Bold
178 txtReset=$(tput sgr0) # Reset
180 colorize () {
181 # pass color and then reset
182 echo -e $@${txtReset}
185 colorize_bold () {
186 echo -e ${txtBold}$@${txtReset}
189 printusage_help () {
190 PID="openpdroid,3gdongle" # default example
191 brief_help
194 brief_help () {
195 echo " usage: ./auto_patcher <ROM> <MODS> <ROMTYPE>"
196 echo " example: ./auto_patcher CM10.zip $PID cm"
197 echo ""
198 echo "Use ./auto_patcher -h for the help menu"
199 echo ""
200 cleanup
201 exit
204 usage_help () {
205 PID=mods
206 mods_display
207 echo "Multiple MODS can be combined by separating them with a comma and NO SPACES!!!"
208 echo ""
209 echo " usage: ./auto_patcher <ROM> <MODS> <ROMTYPE>"
210 echo ""
211 echo " example: ./auto_patcher CM10.zip openpdroid,3gdongle cm"
212 echo ""
213 usage_more_help
216 usage_more_help () {
217 echo "* press 'q' available patches or CTRL-c to quit the help menu *"
220 display_help () {
221 cd patches
222 echo ""
223 echo "AVAILABLE PATCHES"
224 echo ""
225 echo "*******************************************************************"
226 echo "Note: There are ONLY 4 ROMTYPES: [pa, cm, aokp, and aosp]."
227 echo ""
228 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
229 echo ""
230 echo "!!! Do not put Android Version number on command line !!!!"
231 echo "*****************************************************************"
232 echo "Specific auto_patcher script options"
233 echo " ./auto_patcher -h mods Lists mods"
234 echo " -h <MODNAME> Specific <MOD> info"
235 echo " -h advanced Advanced usage+lists all available patch dates"
236 echo ""
237 cleanup
238 exit
241 romtype_help () {
242 # From rom_error (bad romtype) and date_error (patch date w/o specifying romtype)
243 echo ""
244 echo "!!!There are only four supported ROMTYPES: 1) cm 2) aokp 3) aosp 4) pa"
245 echo ""
246 echo "Find out which of the above ROMTYPES your rom is based on and try again!"
247 echo "**********************************************"
248 echo ""
249 cleanup
250 brief_help
253 advanced_help () {
254 echo ""
255 echo "The Auto-Patcher Advanced Usage"
256 echo "*********************************"
257 echo ""
258 echo "For those of you determined to try everything..."
259 echo ""
260 echo "You can also try adding a patch date as a final argument."
261 echo ""
262 echo " ./auto_patcher <ROM> <MOD> <ROMTYPE> <DATE>"
263 echo ""
264 echo "Please note: There are only four ROMTYPES: {pa, aokp, aosp and cm}"
265 echo " -The various appellations after that are for internal use only!"
266 echo ""
267 echo "The Auto-Patcher has a pretty great rom probe, specifying the date is"
268 echo " deprecated...you don't need to, we promise."
269 echo ""
272 cleanup () {
273 [[ -n $ROOT ]] && \rm -rf "$ROOT"/tmp*
276 garbage () {
277 unset GARBAGE
278 GARBAGE=($(find $@ -name "*.orig")) && rm -rf ${GARBAGE[@]} && echo "GARBAGE= ${GARBAGE[@]}" >> "$LOG"
279 GARBAGE=($(find $@ -name "*.rej")) && rm -rf ${GARBAGE[@]} && echo "GARBAGE= ${GARBAGE[@]}" >> "$LOG"
283 print_error () {
284 # General purpose error. Used for errors in main, as opposed to probe or set-up.
285 echo ""
286 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
287 printtask "!!! error: $@"
288 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
289 echo ""
290 brief_help
293 smali_error () {
294 # Smali binary error. Problem often goes away on second run.
295 echo ""
296 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
297 printtask "!!! error: $@"
298 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
299 echo ""
300 if [[ $(grep 'method index is too large' "$LOG") != "" ]]; then
301 printtask "!!! Problem with method cap !!!"
302 printtask "... attempting fix ..."
303 . patches/.common/framework.jar.sh 2>&1 > ${JAR}.log
304 printtask "... rebuild framework.jar ..."
305 java -Xmx512M -jar smali.jar -a $API tmp/${FILE}.out/smali -o tmp/${FILE}.out/classes.dex >> "$LOG" 2>> "$LOG"
306 [ -f tmp/${FILE}.out/classes.dex ] || print_error "Could not resolve method cap issue- please submit log"
307 else
308 printtask "!!! This error is generally due to an unknown bug in the smali binary!"
309 echo "In our experience, it goes away if you run the patcher a second time."
310 echo " Please run the Auto-Patcher with the same command once again."
311 echo ""
312 echo "If after the third attempt the same thing happens,"
313 echo " please upload your logfile to our support thread!"
314 echo ""
315 cleanup
316 exit
320 unknown_mod_error () {
321 echo ""
322 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
323 printtask "!!! error: $@"
324 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
325 echo ""
326 cleanup
327 printusage_help
330 mismatch_error () {
331 # Function that exposes attempts to apply a mod to an upsupported Android version
332 echo ""
333 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
334 printtask "!!! error: $@"
335 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
336 echo ""
337 cleanup
338 brief_help
341 date_error () {
342 # Remind users to include a romtype if they are going to specify a patch date
343 echo ""
344 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
345 printtask "!!! error: $@"
346 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
347 echo ""
348 echo "Please put a ROMTYPE before the patch date and run again!!"
349 romtype_help
352 rom_error () {
353 # For when an unsupported romtype is manually entered on the command-line
354 echo ""
355 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
356 printtask "!!! error: $@"
357 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
358 romtype_help
361 conflict_error () {
362 # For conflicting packages
363 echo ""
364 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
365 printtask "!!! error: $@"
366 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
367 cleanup
368 PID=mods
369 mods_info
372 misspatch_error () {
373 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
374 printtask "!! error: $@ "
375 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
376 echo ""
377 printtask "!! The Auto-Patcher could not find its patches and/or tools!"
378 echo ""
379 echo "* Did you run ./batch.sh first?"
380 echo ""
381 echo "The patch_patches.tgz and patch_tools.tgz need to be in this directory,"
382 echo " one way or another..."
383 echo ""
384 cleanup
385 brief_help
388 misstools_error () {
389 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
390 printtask "!! error: $@ "
391 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
392 printtask "Your set-up is missing a dependency."
393 echo "We require JDK, tar, patch and cpio."
394 echo ""
395 echo ""
396 echo "Each distro is different"
397 echo "but ensure you have them all installed and try again."
398 echo ""
399 cleanup
400 brief_help
403 miss_git_error () {
404 printtask "Updater: disabled"
405 echo ""
406 printtask "You will not be able to get automatic updates because we could not find 'git'."
407 printtask "Find out how to install git for your system and that feature should work automatically"
408 echo ""
411 printtask () {
412 echo "" >> "$LOG"
413 echo -e $@ | tee -a "$LOG"
416 print_to_log () {
417 echo "$@" >> "$LOG"
420 copy_prepatched_provisional () {
421 print_to_log "File for which patching failed:"
422 print_to_log "---------------------------------------------"
423 print_to_log ""
424 print_to_log "${FAIL##*/}"
425 print_to_log ""
426 print_to_log "---------------------------------------------"
427 print_to_log ""
428 print_to_log "We are adding a pre-patched copy of those files."
429 print_to_log ""
430 print_to_log "Please only file a bug report if running the program gives you problems!!!"
431 print_to_log "... replace $FAIL ..."
432 \rm -rf tmp/${FILE}.out/smali/${FAIL} tmp/${FILE}.out/smali/${FAIL}.orig tmp/${FILE}.out/smali/${FAIL}.rej
433 \cp -av "$PROVISIONAL" tmp/${FILE}.out/smali/${FAIL} >> "$LOG" 2>&1
434 SID=(${SID[@]} $FAIL)
435 print_to_log "... failed patch sucessfully resolved ..."
438 prep_alternate_patch () {
439 # Use alt.patch, if exists. Increment in case there are multiple alternates.
440 mv -v $ALTERNATIVE_PATCH $PARB/${NAME}.patch >> "$LOG"
441 ALT_PATCH_NUMBER=$((PATCH_NUMBER + 1))
443 # Get fresh files/variables + decompile again (use rm b/c privacy files wouldn't get overwritten)
444 rm -rf tmp/${FILE}.out/smali
445 java -jar baksmali.jar -b -a $API -o tmp/${FILE}.out/smali ${FILE} >> "$LOG" 2>> "$LOG"
446 unset FAILS && unset SID
447 current_jar=$(($current_jar - 1))
448 break
451 no_network_access () {
452 ping -c1 www.github.com >> "$LOG" 2>&1 && NETWORK=true # second try and check github
453 ping -c1 www.google.com >> "$LOG" 2>&1 # test for internet in general
454 if [[ "$NETWORK" == true ]]; then
455 return
456 else
457 printtask "Check for update failed, probably because of no internet access."
458 echo "The autopatcher will continue with current local version: $VERSION"
459 NETWORK=false
460 echo ""
461 sleep 2
465 auto_update_error () {
466 echo ""
467 printtask "### Update failed ###"
468 printtask ""
469 printtask "It appears you may have made some changes to the script that prevent automatic updating."
470 printtask "You could run 'git reset --hard' to return the autopatcher to its original form"
471 printtask " or set AUTO_UPDATE to false in the .config file to stop getting this message."
472 echo ""
473 printusage_help
476 backup_script () {
477 printtask "... backing up auto_patcher to auto_patcher.bak ..."
478 cp -av auto_patcher auto_patcher.bak >> "$LOG" #backup for user in case of changes
479 echo ""
482 warn_of_overwrite () {
483 # Only seen once, by users without ".git" directories
484 # Only users who got program @ download page see this, all others (ApG included) use git
485 echo "This is a one time set-up process that will overwrite all local changes!"
486 echo "If this is not ok with you press ctrl-C and set AUTO_UPDATE to false in .config"
487 echo ""
490 establish_repo() {
491 printtask "### establishing the repo ###"
492 echo "... please be patient, this should only be needed once ..."
493 echo ""
494 git clone https://github.com/mateor/auto-patcher >> "$LOG" || no_network_access
495 if ($NETWORK); then
496 mv -v auto-patcher/".git" . >> "$LOG"
497 rm -rf auto-patcher
498 git checkout -q master || auto_update_error
499 git reset --hard 2>&1 >> "$LOG"
500 echo ""
504 export_log_and_variables () {
505 cp -a "$LOG" .updated.log
506 rm -If "$LOG"
507 AUTO_PATCHER_OLD_VERSION=$VERSION
508 AUTO_PATCHER_OLD_PATCHES_VERSION=$PATCHES_VERSION
509 AUTO_PATCHER_WAS_UPDATED=true
512 print_changelog () {
513 CHANGELOG="changelog.txt"
514 echo "" > "$CHANGELOG"
515 CURRENT_HEAD=$(git rev-parse HEAD)
516 echo "Changelog from Autopatcher$AUTO_PATCHER_OLD_VERSION to Autopatcher$VERSION" >> "$CHANGELOG"
517 echo "---------------------------------------------------------------------------" >> "$CHANGELOG"
518 echo "" >> "$CHANGELOG"
519 echo " Get more info about any individual commit by entering 'git show \$NUMBER'" >> "$CHANGELOG"
520 echo "" >> "$CHANGELOG"
521 git log --pretty=oneline $ORIGINAL_HEAD...$CURRENT_HEAD >> changelog.txt
522 printtask "... "$CHANGELOG" has been updated ..."
525 replace_updater () {
527 # Function for devices that use SDcard installs. Also to be tested for CM7
528 # since CM7 seems to use an updater-script that wipes EMMC. Testing
530 \rm $UPDATER_LOC/$UPDS 2>&1
531 \cp patches/.common/$UPDATER_LOC/$UPDS $UPDATER_LOC >> "$LOG" 2>&1
532 echo "run_program(\"/sbin/busybox\", \"umount\", \"/system\");" >> UPDATE.txt
533 cat UPDATE.txt >> $UPDATER_LOC/$UPDS
534 echo ""
535 echo "New updater-script being used:" >> "$LOG"
536 echo "-----------------------------" >> "$LOG"
537 cat $UPDATER_LOC/$UPDS >> "$LOG"
540 abspath () {
541 case $(uname -s) in
542 CYGWIN*)
543 echo $(cygpath -ua "$1") | sed 's:/$::g'
545 Darwin)
546 #[[ $(echo $1 | awk '/^\//') == $1 ]] && echo "$1" || echo "$PWD/$1"
547 [[ ${1:0:1} == "/" ]] && echo "$1" || echo "$PWD/$1"
549 Linux)
550 echo $(readlink -f "$1")
553 if [[ ${1:0:1} == "/" ]]; then
554 echo "$1"
555 elif [[ ${1:0:2} == "./" ]]; then
556 echo "$PWD/${1:2}"
557 else
558 echo "$PWD/$1"
561 esac
564 mods_display () {
565 echo ""
566 echo "The Auto-Patcher $VERSION"
567 echo "*******************************"
568 echo ""
569 echo "The available mods are"
570 echo "****************************************************"
571 echo "* pdroid openpdroid voice v6supercharger *"
572 echo "* voice insecure secure external_internal *"
573 echo "* tabletUI 3gdongle pd2.0 *"
574 echo "****************************************************"
575 echo ""
576 echo "To find out more about any mod, simply enter:"
577 echo " ./auto_patcher -h <MODNAME>"
578 echo ""
579 cleanup
582 mods_info () {
583 # Defaults
584 DEPENDENCY="None"
585 DEV="Unknown"
586 CEILING=$CURRENT_ANDROID
587 ROM_CONFLICTS="None"
588 UNKNOWN_MOD=false
589 case $PID in
590 mods)
591 mods_display
592 exit
594 auto*)
595 echo ""
596 echo "**************************************"
597 echo "The Auto-Patcher ate a kitten once..."
598 echo "**************************************"
599 echo ""
600 DEV="mateor and Caldair"
601 WEBSITE="https://github.com/mateor/auto-patcher"
602 printusage_help
604 advanced)
605 cd patches/
606 (advanced_help && find -H * -name 201*) | more -d
607 echo ""
608 brief_help
610 voice)
611 FLOOR=4.0.0
612 DESC="Use on wifi-only tablets to have the software register as 'voice-enabled'. Allows VOIP like Google Voice to function."
613 DESC="bongostl's setup method can be seen at the link."
614 WEBSITE="http://forum.xda-developers.com/showthread.php?t=1823701"
615 DEV="bongostl"
617 v6 | v6supercharger)
618 FLOOR=4.0.0
619 CEILING=4.2.2
620 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."
621 DEV="Zeppelinrox"
622 DEPENDENCY="The V6 Supercharger Script. Get it at the link"
623 WEBSITE="http://forum.xda-developers.com/showthread.php?t=991276"
625 PID="v6supercharger" # allows shorthand 'v6' to find patches.
627 pdroid)
628 FLOOR=2.3.7
629 CEILING=4.1.2
630 DESC="Security Software that manages access to personal data w/o causing FC's. No longer under development."
631 DESC1="Try the open-source expansion of this program, OpenPdroid."
632 DESC2="(It's the 'openpdroid' mod within the Auto-Patcher)."
633 DEV="Svyat"
634 DEPENDENCY="The Pdroid app. You can get it at the link"
635 WEBSITE="http://forum.xda-developers.com/showthread.php?t=1923576"
638 pd2.0)
639 FLOOR=4.1.2
640 CEILING=4.1.2
641 DESC="An expansion of the PDroid application/framework."
642 DEV="CollegeDev"
643 DEPENDENCY="The free PDroid2.0 app available at the link"
644 WEBSITE="http://forum.xda-developers.com/showthread.php?t=1923576"
646 openpdroid)
647 FLOOR=4.1.2
648 CEILING=4.2.2
649 DESC="A fork of the open-source PDroid and Pdroid2.0 framework."
650 DEV="CollegeDev/FFU5y/wbedard/mateorod/Community"
651 DEPENDENCY="PDroidManager(opensource) or PDroid2.0(CollegeDev)"
652 WEBSITE="http://forum.xda-developers.com/showthread.php?t=1994860"
654 opendroid)
655 echo ""
656 echo "No mod named 'opendroid'. You probably mean 'openpdroid'. Try again."
657 PID="mods"
658 mods_info
660 external_internal)
661 FLOOR=2.3.3
662 CEILING=4.1.2
663 DESC="Swap internal and external storage."
665 insecure)
666 FLOOR=2.3.3
667 DESC="Make any boot.img insecure and allow remount as well as adb push/pull of system files. True root."
669 secure)
670 FLOOR=2.3.3
671 DESC="Make any boot.img secure."
673 3gdongle)
674 FLOOR=4.1.0
675 CEILING=4.2.2
676 DESC="Allows 3gdongles to work on wifi tablets w/o 3rd party applications."
677 DEV="trevd"
678 DEPENDENCY="None, but read the troubleshooting guide at the link"
679 WEBSITE="http://forum.xda-developers.com/showthread.php?t=1798631"
681 tabletUI)
682 FLOOR=4.1.0
683 CEILING=4.2.2
684 if [[ $ANDR == "4.2" ]]; then
685 ROM_CONFLICTS=(pa .aosp-ever aokp)
686 else
687 ROM_CONFLICTS=(pa .aosp-slim)
689 DESC="Changes the user interface of Phones and Phablets to the popular Tablet UI."
690 DEV="barmullio/Caldair"
691 WEBSITE="http://forum.xda-developers.com/showthread.php?t=2154075"
694 UNKNOWN_MOD=true
695 FLOOR=?????
696 CEILING=?????
697 DESC="??? Unknown modtype ??? Check your spelling or the mod list!"
698 DESC1=" Try: \"./auto_patcher -h mods\""
699 esac
701 # strip decimals from android version (i.e. 2.3.7 becomes 237) so we can do math
702 NVID=${VID//[.]/}
703 COMPATF=${FLOOR//[.]/}
704 COMPATC=${CEILING//[.]/}
707 apk_copy () {
708 if [ -f patches/$P/$A/$R/$B/$FILE ]; then
709 \cp -av patches/$P/$A/$R/$B/$FILE $FILE >> "$LOG" 2>&1
710 echo "... Patching $APK failed, but we have successfuly copied over a prepatched file ..."
711 apk_was_copied=true
712 else
713 print_error "failed patching $APK!!!"
717 no_mod_selected_error () {
718 echo ""
719 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
720 printtask "!!! error: $@"
721 printtask "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
722 echo ""
723 printtask "You need to enter a MOD before you try and specify the ROMTYPE."
724 printtask "Check the help menu for the list of available MODS"
725 echo ""
726 printusage_help
729 check_against_rom_types () {
730 # this checks to see if the user has entered a ROMTYPE in the MOD spot and outputs advice if so.
731 NUMBER_OF_AVAILABLE_ROMTYPES=${#AVAILABLE_ROMTYPES[@]}
732 for ((i=0; i < $NUMBER_OF_AVAILABLE_ROMTYPES; i++)); do
733 if [[ ${AVAILABLE_ROMTYPES[i]} == "$P" ]]; then
734 no_mod_selected_error "\"$P\" is a ROMTYPE not a MOD"
736 done
739 compat_check () {
740 for P in ${PID[@]}; do
741 mods_info
742 if ($UNKNOWN_MOD); then
743 check_against_rom_types
744 unknown_mod_error "\"$P\" is not a valid mod. Check your spelling or the mod list!!!"
745 elif [[ "$NVID" -lt "$COMPATF" ]]; then
746 mismatch_error "Your Android $VID rom is too old! The minimum for $P is \n !!! Android $FLOOR!"
747 elif [[ "$NVID" -gt "$COMPATC" ]]; then
748 mismatch_error "Sorry, $P has not been made available for Android $VID yet!"
750 done
753 rom_compat_check () {
754 for P in ${PID[@]}; do
755 N=${#ROM_CONFLICTS[@]}
756 for ((i=0; i < $N; i++)); do
757 if [[ $RID == ${ROM_CONFLICTS[$i]} ]]; then
758 rom_compat_error
760 done
761 done
764 rom_compat_error () {
765 print_error "$RID is incompatible with $PID!!!"
768 extpath () {
769 case $(uname -s) in
770 CYGWIN*)
771 echo $(cygpath -da "$1")
774 echo $(abspath "$1")
776 esac
779 #contains () { for e in "${@:2}"; do [[ "$e" = "$1" ]] && return 0; done; return 1; }
781 parse () { echo "${1%%_*}"; }
783 getbuildprop () {
784 if [ -f system/build.prop ]; then
785 result=($(grep $1 system/build.prop | tr -d '\r' | tr '=' ' '))
786 echo "${result[1]}"
787 else
788 echo ""
793 aosp_mod_check() {
794 jar -xvf "$ROMX" system/framework/framework2.jar >> "$LOG"
795 if [ -s system/framework/framework2.jar ]; then
796 ever_check
797 else
798 AOSP=aosp
800 echo $AOSP
803 ever_check() {
804 MID=$(getbuildprop ro.build.romversion)
805 if [[ $MID == "Evervolv"* ]]; then
806 AOSP=".aosp-ever"
807 else
808 MID=$(getbuildprop ro.build.display.id)
809 if [[ "$MID" == "ev"* ]]; then
810 AOSP=".aosp-ever"
811 else
812 pac_check
815 echo $AOSP
818 pac_check() {
819 MID=$(getbuildprop ro.build.romversion)
820 if [[ "$MID" == "pac"* ]] || [[ "$MID" == "PAC"* ]]; then
821 AOSP=".aosp-pac"
822 else
823 MID=$(getbuildprop ro.build.display.id)
824 if [[ "$MID" == "pac"* ]] || [[ "$MID" == "PAC"* ]]; then
825 AOSP=".aosp-pac"
826 else
827 slim_check
832 slim_check() {
833 SLMID=$(getbuildprop ro.modversion)
834 SLMMID=$(getbuildprop updateme.name)
835 if [[ "$SLMMID" == "Slim"* ]] || [[ $SLMMID == "slim"* ]]; then
836 AOSP=".aosp-slim"
837 elif [[ "$SLMID" == "Slim"* ]] || [[ $SLMID == "slim"* ]]; then
838 AOSP=".aosp-slim"
839 else
840 if [[ "$ANDR" == "4.1" ]]; then
841 AOSP=.aosp-mod
842 else
843 AOSP="aosp"
848 pa_check() {
849 CMID=$(getbuildprop ro.modversion)
850 PAID=$(getbuildprop ro.pa.version)
851 MID=$(getbuildprop ro.build.display.id)
852 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
853 DID=$(getbuildprop ro.product.device)
854 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
855 if [[ -n $PAID ]]; then
856 RID=pa
857 else
858 case $CMID in
859 [Pp][Aa]*)
860 RID=pa;
863 RID=cm;
865 esac
869 romtype_set () {
870 case $RID in
872 ROMTYPE="cm"
874 aokp*)
875 ROMTYPE="aokp"
878 ROMTYPE="pa"
881 ROMTYPE="aosp"
883 esac
886 proberom () {
887 VID=$(getbuildprop ro.build.version.release)
888 if [ ${#VID} -lt 4 ]; then # in case of non-standard versioning in build.prop (defy!)
889 ANDR=$VID
890 else
891 ANDR="${VID%.*}" # Cut to 1 significant digit to cover specific range or release.
893 if [ "$ANDR" == "2.3" ]; then
894 FLAVR=gingerbread
895 API=10
896 RID=cm;
897 elif [ "$ANDR" == "4.0" ]; then
898 FLAVR=ics
899 API=15
900 MID=$(getbuildprop ro.rommanager.developerid)
901 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.modversion))
902 DID=$(getbuildprop ro.product.device)
903 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
905 case "$MID" in
906 pa|cm9|cm|cyanogenmod*)
907 RID=cm;
909 aokp|teamkang)
910 RID=aokp;
912 aosp*)
913 RID=aosp;
916 echo "!!! $MID is not supported yet, trying aosp !!!"
917 RID=aosp
919 esac
920 elif [ "$ANDR" == "4.1" ]; then
921 FLAVR=jellybean
922 API=16
923 CMID=$(getbuildprop ro.cm.version)
924 if [[ -n $CMID ]]; then
925 pa_check
926 else
927 MID=$(getbuildprop ro.build.display.id)
928 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
929 DID=$(getbuildprop ro.product.device)
930 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
931 case "$MID" in
932 cm10|cm*|cyanogenmod*)
933 RID=cm;
935 aokp*|teamkang)
936 RID=aokp;
938 pa*)
939 RID=pa;
941 ev*)
942 RID=".aosp-ever";
945 RID=$(aosp_mod_check);
947 esac
949 elif [ "$ANDR" == "4.2" ]; then
950 FLAVR=jellybean
951 API=17
952 CMID=$(getbuildprop ro.cm.version)
953 MID=$(getbuildprop ro.build.display.id)
954 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
955 DID=$(getbuildprop ro.product.device)
956 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
958 case "$MID" in
959 cm10|cm*|cyanogenmod*)
960 RID=cm;
962 aokp*|teamkang)
963 RID=aokp;
965 [Pp][Aa]*)
966 if [[ "$MID" == "pac"* ]] || [[ "$MID" == "PAC"* ]]; then
967 RID=".aosp-pac"
968 else
969 RID=pa;
972 ev*|Ever*)
973 RID=".aosp-ever";
976 RID="$(ever_check)";
978 esac
979 else
980 print_error "unknown ROM version $VID: generally means cannot find/read build.prop"
982 # romtype_set allows hiding ".aosp-*" types from users while leaving them as options on CLI
983 romtype_set
984 echo "... result of ROM check: version= $VID rom= $ROMTYPE ..."
988 # Advanced build date query
989 # This should set the patch date automatically.
991 build_query() {
992 UTC=$(getbuildprop ro.build.date.utc)
994 # Difference in how OS X and Linux/Cygwin handles 'date' utility
995 case $(uname -s) in
996 [Dd]arwin)
997 BDID=$(date -r $UTC +%Y%m%d)
998 echo "#### Darwin Build Query used ####" >> "$LOG"
1001 BDID=$(date -d "1970-01-01 UTC $UTC seconds" +"%Y%m%d")
1002 echo "#### Standard Build Query ####" >> "$LOG"
1004 esac
1006 # If patch date is specified on CLI, use that patch date
1007 if [ $# -gt 3 ]; then
1008 BID=${4//,/ };
1009 BDID=$BID
1010 else
1011 case $ANDR in
1012 2.3)
1013 # CM7 roms do not have UTC time stamp- so no build query.
1014 BID=latest;
1015 echo "*** CM7 roms default to latest patches. If using an older rom ***"
1016 echo "*** specify patch date on command line. Use -h to see available patches ***"
1019 for P in ${PID[@]}; do
1020 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1021 [ -d patches/$P/$A/"$RID" ] && R=$RID || R=generic
1022 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1023 PAR=patches/$P/$A/$R
1024 PARB=patches/$P/$A/$R/$B
1025 DATES=$(ls patches/$P/$A/"$R" | grep '201*')
1026 # Intialize variable - an upperbound to determine lowest in first loop.
1027 BID=20201231
1028 # find earliest available patch date
1029 for i in $DATES; do
1030 if [[ $i -lt $BID ]]; then
1031 BID=$i
1033 done
1034 # Check if earliest patches are from before build date. Else use earliest
1036 # If rom is newer than earliest patch set, find best match
1037 if [[ $(($BID-$BDID)) -lt 0 ]]; then
1038 for g in $DATES; do
1039 # use any patch that matches $UTC
1040 if [[ $(($BDID-$g)) -eq 0 ]]; then
1041 BID=$g
1042 break
1043 # Set highest $BID w/o going over $UTC
1044 elif [[ $(($BDID-$g)) -gt 0 ]] && [[ $g -gt $BID ]]; then
1045 BID=$g
1047 done
1049 # Error catch if query fails.
1050 [[ $BID == "20201231" ]] && BID=latest && echo "Build Query Failed!! Default to latest!" >> "$LOG"
1051 echo "... $PID patch date has been set to: $BID ..."
1052 B=$BID
1053 break
1054 done
1056 esac
1060 proberil () {
1061 RIL=$(getbuildprop ro.telephony.ril_class)
1062 [[ -n $RIL ]] && printtask "... result of ROM check: RIL= $RIL"
1065 rominfo () {
1066 echo "# VER= $VERSION" >> "$LOG"
1067 echo "# OS= $OSTYPE ${BIT}bit" >> "$LOG"
1068 echo "# VID= $VID" >> "$LOG"
1069 echo "# PID= ${PID[@]}" >> "$LOG"
1070 echo "# MID= $MID" >> "$LOG"
1071 echo "# RID= $RID" >> "$LOG"
1072 echo "# ANDR= $ANDR" >> "$LOG"
1073 echo "# BDID= $BDID" >> "$LOG"
1074 echo "# DID= $DID" >> "$LOG"
1075 echo "# BID= $BID" >> "$LOG"
1076 echo "Patches are $PID/$ANDR/$RID/$BID" >> "$LOG"
1078 if [ -d ../".git" ]; then
1079 echo "" >> "$LOG"
1080 echo -n "Current HEAD: " >> "$LOG"
1081 git log --pretty=oneline HEAD^..HEAD >> "$LOG"
1082 echo "" >> "$LOG"
1087 if [[ $1 == -h ]]; then
1088 if [ $# -gt 1 ]; then
1089 PID=$2
1090 mods_info
1091 echo ""
1092 echo "The Auto-Patcher $VERSION by Mateorod and Pastime1971"
1093 echo "*************************************************"
1094 echo ""
1095 echo "Mod Name: $PID"
1096 echo ""
1097 echo " $DESC"
1098 if [[ $DESC1 ]]; then # test to see is there is a second DESC line
1099 echo " $DESC1"
1101 if [[ $DESC2 ]]; then
1102 echo -n "$DESC2"
1104 echo ""
1105 echo "Developer: $DEV"
1106 echo "Dependancies: $DEPENDENCY"
1107 if [[ $WEBSITE ]]; then
1108 echo "Website: $WEBSITE"
1110 echo ""
1111 echo "Works on ROMs from Android $FLOOR -> $CEILING"
1112 echo
1113 brief_help
1114 exit
1118 [[ $# -lt 1 || -z $1 ]] && PID="mods" && mods_info
1119 [[ $1 == "-h" ]] && usage_help | less && display_help
1121 echo ""
1122 echo "The Auto-Patcher $VERSION"
1123 # by pastime1971 and mateorod
1124 if [[ -n "$AUTO_PATCHER_WAS_UPDATED" ]]; then
1125 echo " (auto-updated from $AUTO_PATCHER_OLD_VERSION)"
1126 print_changelog
1128 echo ""
1130 ROOT="$(abspath "$(dirname "$(abspath "$(type -p "$0")")")")"
1131 TOOL="$ROOT/patch_tools.tgz"
1132 PTCH="$ROOT/patch_patches.tgz"
1133 cleanup
1134 # set temporaray directory
1135 DATE=$(date +%Y%m%d%H%M%S)
1136 TEMP="$ROOT/tmp$DATE"
1137 TMP="$ROOT/tmp$DATE"
1138 TMPDIR="$ROOT/tmp$DATE"
1139 mkdir "$TEMP"
1140 ROM=$(abspath "$1")
1141 ROMX=$(extpath "$1")
1143 if [[ $OSTYPE == "cygwin" ]]; then
1144 EXE=".exe"
1145 PGFORM="0x"
1146 AUTO_UPDATE=false # CYGWIN AUTO_UPDATE TESTERS COMMENT THIS LINE HERE!
1149 LOG=$(abspath ./log$DATE.txt)
1150 #echo $ROOT $TOOL $ROM $TEMP "$LOG"
1151 echo "ROOT= $ROOT" >> "$LOG"
1152 echo "TOOL= $TOOL" >> "$LOG"
1153 echo "ROM= $ROM" >> "$LOG"
1154 echo "ROMX= $ROMX" >> "$LOG"
1157 # Auto-Update # excluding ApG/cygwin for now until I talk with kobik.
1158 # To turn off auto updating, set AUTO_UPDATE in .config to false
1161 # Check for git
1162 if [ $(which git) ]; then
1163 GIT=true
1164 else
1165 miss_git_error "Missing \"git\" utility"
1166 GIT=false
1169 # If program was updated, merge the logs
1170 if [[ -n "$AUTO_PATCHER_WAS_UPDATED" ]]; then
1171 cat .updated.log >> "$LOG"
1172 rm -If .updated.log
1175 if [[ "$AUTO_UPDATE" == true ]] && [[ "$GIT" == true ]]; then
1176 ping -c1 www.github.com > /dev/null 2>&1 && NETWORK=true || no_network_access
1177 if [[ "$NETWORK" == true ]]; then
1178 printtask "### checking for updates ###"
1180 # establish the repo if not already present- one time operation.
1181 if [ ! -d ".git" ]; then
1182 printtask "... initial setup to allow automatic updating ..."
1183 backup_script && warn_of_overwrite
1184 establish_repo && export_log_and_variables
1185 printtask "### rerunning script with latest version ###"
1186 $0 "$@"
1187 exit 0
1190 # Here is the regular update process
1191 git fetch origin 2>&1 >> "$LOG" || no_network_access
1192 if !("$NETWORK"); then
1193 printtask "Updater: not able to run auto_update."
1194 else
1195 COMMITS_BEHIND=$(git rev-list HEAD..origin/master --count)
1196 case "$COMMITS_BEHIND" in
1198 printtask "Updater: Auto-Patcher is already up to date"
1201 ORIGINAL_HEAD=$(git rev-parse HEAD)
1202 printtask "... Updater: update found ..."
1203 backup_script
1204 printtask "... Updating Auto-Patcher ..."
1205 git merge --no-edit origin/master 2>&1 >> "$LOG" || auto_update_error
1206 export_log_and_variables
1207 printtask "### updated, now rerunning script with latest version ###"
1208 $0 "$@"
1209 exit 0
1211 esac
1212 echo ""
1217 if [[ -n "$AUTO_PATCHER_WAS_UPDATED" ]]; then
1218 if [[ $PATCHES_VERSION -gt $AUTO_PATCHER_OLD_PATCHES_VERSION ]]; then
1219 echo "... integrating new patches ..."
1220 sh batch.sh >> /dev/null 2>> "$LOG"
1224 #remove old zips, if built under identical parameters.
1225 \rm -f $RESTORE.zip $UPDATE.zip
1227 CHK=$(getconf LONG_BIT)
1228 if [[ $CHK = "64" ]]; then
1229 BIT=64
1230 else [[ $BIT = "32" ]];
1231 BIT=32
1234 printtask "### verify tools ###"
1235 which patch >> "$LOG" || misstools_error "Missing \"patch\" utility."
1236 which tar >> "$LOG" || misstools_error "Missing \"tar\" utility"
1237 which jar >> "$LOG" || misstools_error "Missing \"Java Development Kit\" (JDK)"
1238 which java >> "$LOG" || misstools_error "Missing \"Java Development Kit\" (JDK)"
1239 which cpio >> "$LOG" || misstools_error "Missing \"cpio\" utility"
1240 [ -f "$TOOL" ] || misspatch_error "patch_tool.tgz is missing"
1241 [ -f "$PTCH" ] || misspatch_error "patch_patches.tgz is missing"
1242 printtask "### verify ROM ###"
1243 [ -f "$ROM" ] || print_error "Cannot find $1!! Make sure you have the location and name right"
1244 echo "### running $0 $@" >> "$LOG"
1245 cd "$TEMP"
1247 PATH="$TEMP:$PATH"
1248 export PATH
1249 echo "PATH= $PATH" >> "$LOG"
1251 printtask "### unzip patch tools ###"
1252 tar xzf "$TOOL" > /dev/null || print_error "failed extracting tools !!!"
1254 # Get OS specific tools
1255 case $(uname -s) in
1256 CYGWIN*)
1257 \mv cygwin/aapt.exe .
1258 \mv cygwin/*.exe boot/
1259 \rm -rf cygwin # why? If you want to we can keep/add it to mac/linux, though.
1261 [Dd]arwin)
1262 \mv mac/aapt .
1264 [Ll]inux)
1265 \mv linux/aapt .
1268 \mv linux/aapt .
1270 esac
1271 # Ensure aapt permissions - possibly to one day be expanded to all tools in a function.
1272 chmod a+x aapt$EXE
1274 printtask "### unzip patch patches ###"
1275 tar xzf "$PTCH" > /dev/null || print_error "failed extracting patches !!!"
1277 # we need build.prop for both RIL probing and ROM probing
1278 jar -xvf "$ROMX" system/build.prop 2>> "$LOG" || print_error "failed extracting build.prop from $ROMX !!!"
1280 # rom + ril type
1281 proberil
1282 printtask "### probe rom type ###"
1283 proberom
1285 # rom type
1286 if [ $# -gt 1 ]; then
1287 PIT=$2
1288 if [[ "$PIT" = "-h" ]]; then
1289 display_help
1293 if [ $# -gt 2 ]; then
1294 RID=$3
1295 case "$RID" in
1296 cm*|cyanogenmod*)
1297 RID=cm;
1299 aokp*|teamkang)
1300 RID=aokp;
1302 pa*)
1303 RID=pa;
1305 .aosp-ever)
1306 RID=".aosp-ever";
1308 .aosp-slim)
1309 RID=".aosp-slim"
1311 .aosp-pac)
1312 RID=".aosp-pac"
1314 aosp*)
1315 case "ANDR" in
1316 4.1)
1317 RID=$(aosp_mod_check);
1320 RID=$(ever_check)
1322 esac
1324 201*)
1325 date_error "You must specify ROMTYPE if designating a patch date!!"
1328 rom_error "$RID is not a valid ROMTYPE!!"
1330 esac
1331 romtype_set
1332 echo "... Using $ROMTYPE patches ..."
1333 else
1334 echo "... Using results of ROM check ..."
1337 # patch type
1338 if [ $# -gt 1 ]; then
1339 PIL=${2//,/ } # If more than one mod, make string separated by spaces
1340 else
1341 PIL="openpdroid"
1342 echo "No mods selected. Defaulting to openpdroid, since that's what you probably want..."
1345 # Ensure only 1 Pdroid mod at a time; PDroid first, so provisionals do not overwrite other mods...
1347 PID=(${PIL// / }) # turn string of requested mods into array
1348 COPYPID=("${PID[@]}") # working copy to iterate over
1349 MODS_NUMBER=${#COPYPID[@]} # number of elements (mods)
1351 if [[ $MODS_NUMBER > 1 ]]; then # because if only one mod, not needed
1352 INDEX=0 # 'pd2.0' didn't work with unset; regex use bars multiple 'pdroid's
1353 for p in ${COPYPID[@]}; do
1354 if [ "$p" = "pdroid" ] || [ "$p" = "pd2.0" ] ||[ "$p" = "openpdroid" ]; then
1355 SPID[0]=$p #set pdroid first
1356 unset COPYPID["$INDEX"]
1357 break
1358 else
1359 INDEX=$((INDEX + 1)) # if (!pdroid), set as 1, 2...
1361 done
1362 for p in ${COPYPID[@]}; do
1363 if [ "$p" = "pdroid" ] || [ $p = "pd2.0" ] ||[ $p = "openpdroid" ]; then
1364 conflict_error "Those mods conflict! Only one pdroid mod at a time!"
1365 else
1366 i=${#SPID[@]}
1367 SPID[i]=$p
1368 i+=1
1370 done
1371 else
1372 SPID=${COPYPID[@]}
1374 for P in ${PIL[@]}; do
1375 [[ ${PID[@]} =~ $P ]] || PID=(${PID[@]} $P)
1376 done
1378 # Check if selected mods are available for rom's Android version.
1379 compat_check
1381 # Make sure mod and rom don't conflict (e.g. pa and tabletUI)
1382 if [[ $ROM_CONFLICTS != "None" ]]; then
1383 rom_compat_check
1386 # Build date
1387 if [ $# -gt 3 ]; then # if a date is specified on command line...
1388 # Set date to match argument and ensure that patches with that date exist
1389 BID=$4
1390 [ -d patches/$P/$ANDR/$RID/$BID ] || print_error "No $P patches for $RID on $BID!! Try the help menu!!"
1391 # Run build_query- this overrides the above but gets useful info
1392 build_query
1393 # Reset patch date to argument (basically undo the effects of the build_query call)
1394 BID=$4
1395 echo "... $PID patch date set manually to: $BID ..."
1396 else
1397 build_query # if no date specified, use one from build_query
1400 # echo ROM info
1401 rominfo
1403 if [[ ( "$PID" == "-h" || "$RID" == "-h" || "$BID" == "-h" ) ]]; then
1404 #Although this placement may be perfect for romfilter. although it throws the scheme...
1405 display_help
1407 #Begin cycle
1409 for P in ${PID[@]}; do
1410 [ -d patches/$P ] || print_error "$P is not available"
1411 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1412 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1413 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1415 unset FILES
1416 [ -f patches/$P/files.txt ] && FILES=$(cat patches/$P/files.txt)
1417 [ -f patches/$P/$A/files.txt ] && FILES=$(cat patches/$P/$A/files.txt)
1418 [ -f patches/$P/$A/$R/files.txt ] && FILES=$(cat patches/$P/$A/$R/files.txt)
1419 [ -f patches/$P/$A/$R/$B/files.txt ] && FILES=$(cat patches/$P/$A/$R/$B/files.txt)
1420 for FILE in ${FILES[@]}; do
1421 case "$FILE" in
1422 +system/*)
1423 [[ ${CID[@]} =~ ${FILE:1} ]] && print_error "${FILE:1} is already being copied" || CID=(${CID[@]} ${FILE:1})
1425 -system/*)
1426 [[ ${EID[@]} =~ ${FILE:1} ]] || EID=(${EID[@]} ${FILE:1})
1428 system/*.jar)
1429 [[ ${JID[@]} =~ $FILE ]] || JID=(${JID[@]} $FILE)
1430 echo "set_perm(0, 0, 0644, \"/$FILE\");" >> UPDATE.txt
1432 # added for the use-case of apktool failure
1433 ~system/*apk) # apks to decompile with smali binaries instead of apktool
1434 [[ ${JID[@]} =~ ${FILE:1} ]] || JID=(${JID[@]} ${FILE:1})
1435 FORMATTED_FILE=${FILE:1}
1436 echo "set_perm(0, 0, 0644, \"/$FORMATTED_FILE\");" >> UPDATE.txt
1438 system/*.apk)
1439 [[ ${AID[@]} =~ $FILE ]] || AID=(${AID[@]} $FILE)
1440 echo "set_perm(0, 0, 0644, \"/$FILE\");" >> UPDATE.txt
1441 # $APKID will have elements removed sometimes--$AID is the master list for the update.zip
1442 declare -a APKID=( "${AID[@]}" )
1444 *.img)
1445 [[ ${IID[@]} =~ $FILE ]] || IID=(${IID[@]} $FILE)
1447 system/*)
1448 [[ ${TID[@]} =~ $FILE ]] || TID=(${TID[@]} $FILE)
1450 esac
1451 done
1452 done
1453 echo "### DELETE FILES= ${EID[@]}" >> "$LOG"
1454 echo "### COPY FILES= ${CID[@]}" >> "$LOG"
1455 echo "### JAR FILES= ${JID[@]}" >> "$LOG"
1456 echo "### APK FILES= ${AID[@]}" >> "$LOG"
1457 echo "### IMG FILES= ${IID[@]}" >> "$LOG"
1458 echo "### TXT FILES= ${TID[@]}" >> "$LOG"
1460 # extract system files
1461 printtask "### unzip rom ###"
1462 jar -xvf "$ROMX" ${JID[@]} ${AID[@]} ${IID[@]} ${TID[@]} 2>> "$LOG" || print_error "failed extracting ${JID[@]} ${AID[@]} ${IID[@]} from $ROMX !!!"
1465 # Update/Restore.zip scripts and prep
1466 printtask "### create updater script ###"
1467 UPDATER_LOC=META-INF/com/google/android
1468 UPDS=updater-script
1469 UPDATE="update-$ROMTYPE-$DID-$BDID-${PIL// /-}"
1470 RESTORE="restore-$ROMTYPE-$DID-$BDID"
1472 jar -xvf "$ROMX" $UPDATER_LOC/$UPDS $UPDATER_LOC/update-binary
1473 jar -xvf "$ROMX" $UPDATER_LOC/update-binary-installer 1> /dev/null 2> /dev/null
1475 # Determine Installer- Aroma or ClockworkMod
1476 if [ -f $UPDATER_LOC/update-binary-installer ]; then
1477 printtask "... using Aroma installer ..."
1478 \mv $UPDATER_LOC/update-binary-installer $UPDATER_LOC/update-binary
1479 else
1480 printtask "... using Clockworkmod installer ..."
1483 # Create updater scripts
1484 cat patches/.common/updater-message.txt >> $UPDS
1485 cat $UPDATER_LOC/$UPDS | grep ^mount | grep "/system" | head -n 1 >> $UPDS
1486 [ -s $UPDS ] || echo "run_program(\"/sbin/busybox\", \"mount\", \"/system\");" >> $UPDS
1487 # restore the original
1488 for FILE in ${EID[@]}; do
1489 jar -xvf "$ROMX" $FILE 2> /dev/null || printtask "!!! warning $FILE cannot be restored !!!"
1490 done
1491 # replace with the original or delete it
1492 for FILE in ${CID[@]}; do
1493 jar -xvf "$ROMX" $FILE 2> /dev/null || echo "delete(\"/$FILE\");" >> $UPDS
1494 done
1495 echo "package_extract_dir(\"system\", \"/system\");" >> $UPDS
1496 # permission management for files that need specific perms
1497 cat $UPDATER_LOC/$UPDS | grep set_perm | grep "/system" >> $UPDS
1498 for P in ${PID[@]}; do
1499 if [ -s patches/$P/$A/set_perm.txt ]; then
1500 echo "...setting permissions..."
1501 cat patches/$P/$A/set_perm.txt >> $UPDS
1503 done
1504 cat $UPDATER_LOC/$UPDS | grep ^unmount | grep "/system" | head -n 1 >> $UPDS
1505 [[ ${IID[@]} =~ boot.img ]] && cat $UPDATER_LOC/$UPDS | grep "boot.img" >> $UPDS
1506 echo "ui_print(\" .\");" >> $UPDS
1507 echo "ui_print(\" .\");" >> $UPDS
1508 echo "ui_print(\" done!\");" >> $UPDS
1509 cat $UPDS > $UPDATER_LOC/$UPDS
1510 echo "# generated $UPDS" >> "$LOG"
1511 cat $UPDS >> "$LOG"
1513 printtask "### create restore.zip ###"
1514 jar -cvf tmp.zip ${JID[@]} ${AID[@]} ${IID[@]} META-INF > /dev/null 2>> "$LOG"
1515 java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip signed.zip 2>> "$LOG"
1516 \mv signed.zip $RESTORE.zip
1517 \rm -f tmp.zip
1520 # Begin patching process
1522 # decompile system files
1523 printtask "### decompile system files ###"
1524 for FILE in ${JID[@]}; do
1525 JAR=${FILE##*/}
1526 printtask "... decompile $JAR ..."
1527 java -jar baksmali.jar -b -a $API -o tmp/${FILE}.out/smali ${FILE} >> "$LOG" 2>> "$LOG"
1528 if [ $FILE == "system/framework/framework.jar" ]; then
1529 printtask "... extract preloaded-classes ..."
1530 jar -xvf ${FILE} preloaded-classes >> "$LOG" 2>> "$LOG"
1531 \mv preloaded-classes tmp/${FILE}.out/
1533 done
1535 # install framework-files for APK...
1536 if [ ${#AID[@]} -gt 0 ]; then
1537 jar -xvf "$ROMX" system/framework/framework-res.apk >> "$LOG"
1538 printtask "... installing framework files ..."
1539 java -jar apktool.jar if system/framework/framework-res.apk
1540 # Decompile APKs
1541 for FILE in ${AID[@]}; do
1542 APK=${FILE##*/}
1543 if [ -f $FILE ]; then
1544 printtask "... decompile $APK ..."
1545 java -jar apktool.jar d -f $FILE tmp/$FILE.out 2>> "$LOG"
1547 done
1550 # Unpack image files {boot.img only so far...}
1551 for FILE in ${IID[@]}; do
1552 printtask "### unpacking $FILE ###"
1553 case "$FILE" in
1554 boot.img)
1555 if [ -f boot.img ]; then
1556 cd boot
1557 ./unpackbootimg$EXE -i ../boot.img >> "$LOG" 2>> "$LOG"
1558 mkdir ramdisk
1559 cd ramdisk
1560 gzip -dc ../boot.img-ramdisk.gz | cpio -i >> "$LOG" 2>> "$LOG"
1561 cd ../../
1562 else
1563 print_error "A mod needs to patch boot.img! This rom does not contains boot.img."
1567 print_error "cannot process $FILE"
1569 esac
1570 done
1572 # apply system modification
1574 for P in ${PID[@]}; do
1575 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1576 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1577 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1578 PAR=patches/$P/$A/$R
1579 PARB=patches/$P/$A/$R/$B
1581 unset FILES COPY DELS JARS APKS IMGS TXTS
1582 [ -f patches/$P/files.txt ] && FILES=$(cat patches/$P/files.txt)
1583 [ -f patches/$P/$A/files.txt ] && FILES=$(cat patches/$P/$A/files.txt)
1584 [ -f patches/$P/$A/$R/files.txt ] && FILES=$(cat patches/$P/$A/$R/files.txt)
1585 [ -f patches/$P/$A/$R/$B/files.txt ] && FILES=$(cat patches/$P/$A/$R/$B/files.txt)
1586 for FILE in ${FILES[@]}; do
1587 case $FILE in
1588 +system/*)
1589 COPY=(${COPY[@]} ${FILE:1})
1591 -system/*)
1592 DELS=(${DELS[@]} ${FILE:1})
1594 system/*.jar)
1595 JARS=(${JARS[@]} $FILE)
1597 ~system/*)
1598 JARS=(${JARS[@]} ${FILE:1})
1600 system/*.apk)
1601 APKS=(${APKS[@]} $FILE)
1603 *.img)
1604 IMGS=(${IMGS[@]} $FILE)
1606 system/*)
1607 TXTS=(${TXTS[@]} $FILE)
1609 esac
1610 done
1612 [[ -n ${COPY[@]} ]] && echo "### copy patch $P/$A/$ROMTYPE/$B ###"
1613 echo "### copy patch $P/$A/$R/$B ###" >> "$LOG"
1614 for FILE in ${COPY[@]}; do
1615 printtask "... copying $FILE ..."
1616 DEST=${FILE%/*}
1617 mkdir -p ./$DEST
1618 if [ -e patches/$P/$A/$R/$B/$FILE ]; then
1619 printtask "... overwriting $FILE from $P ..."
1620 \cp -av patches/$P/$A/$R/$B/$FILE ./$DEST >> "$LOG" 2>&1
1621 elif [ -e patches/$P/common/$FILE ]; then
1622 printtask "... overwriting $FILE from $P ..."
1623 echo " ### SOMETHING WENT WRONG!! Could not find file-- using common. ###" >> "$LOG"
1624 \cp -av patches/$P/common/$FILE ./$DEST >> "$LOG" 2>&1
1625 else
1626 print_error "$FILE is missing in the patch. Please upload your logfile to the support thread!"
1628 done
1630 # unconditional smali copying- For particularly troublesome files
1631 [ -f patches/$P/smali.txt ] && SMALI=$(cat patches/$P/smali.txt)
1632 [ -f patches/$P/$A/smali.txt ] && SMALI=$(cat patches/$P/$A/smali.txt)
1633 [ -f patches/$P/$A/$R/smali.txt ] && SMALI=$(cat patches/$P/$A/$R/smali.txt)
1634 [ -f patches/$P/$A/$R/$B/smali.txt ] && SMALI=$(cat patches/$P/$A/$R/$B/smali.txt)
1635 MOVE=${SMALI##*/}
1636 for SMALI in ${SMALI[@]}; do
1637 if [ -f patches/$P/$A/$R/$B/$SMALI ]; then
1638 printtask "... overwriting $MOVE ..."
1639 \cp -a patches/$P/$ANDR/$R/$B/$SMALI tmp/$SMALI >> "$LOG" 2>&1
1640 # This lower area should be deprecated now...wait and see. Each BID has own link to provisionals now.
1641 elif [ -f patches/$P/$A/.provisionals/$SMALI ]; then
1642 printtask "... overwriting $MOVE ..."
1643 \cp -a patches/$P/$ANDR/.provisionals/$SMALI tmp/$SMALI >> "$LOG"
1645 done
1647 [[ -n ${DELS[@]} ]] && echo "### delete patch $P/$A/$ROMTYPE/$B ###"
1648 echo "### delete patch $P/$A/$R/$B ###" >> "$LOG"
1649 for FILE in ${DELS[@]}; do
1650 printtask "... deleting $FILE ..."
1651 \rm -rf ./$FILE
1652 done
1653 [[ -n ${JARS[@]} ]] && echo "### jar patch $P/$A/$ROMTYPE/$B ###"
1654 echo "### jar patch $P/$A/$R/$B ###" >> "$LOG"
1656 # Iterate through jars and patch. If fails, try prepatched provisionals or look for alternative patch.
1657 ALT_PATCH_NUMBER=2
1658 for (( current_jar=0; current_jar < ${#JARS[@]}; current_jar++)); do
1659 FILE=${JARS[$current_jar]}
1660 JAR=${FILE##*/}
1661 if [[ $FILE == *".jar" ]]; then # allows for *.apks to be decompiled by baksmali
1662 NAME=${JAR%.jar}
1663 else
1664 NAME=$JAR # TODO: Maybe rename this, since it now encompases apks at times
1666 printtask "... apply $NAME.patch ..."
1667 patch -Nls -p1 -d tmp/${FILE}.out < $PARB/${NAME}.patch 2>&1 > ${JAR}.log
1668 for INCREMENTAL in $(ls $PARB/${NAME}-*.patch 2>/dev/null); do
1669 printtask "... apply $(basename $INCREMENTAL) ..."
1670 patch -Nls -p1 -d tmp/${FILE}.out < $INCREMENTAL 2>&1 > ${JAR}.log
1671 done
1672 cat ${JAR}.log >> "$LOG"
1673 case "$NAME" in
1674 framework)
1675 # patch preloaded-classes only if a patch exists
1676 if [ -f $PARB/preloaded.patch ]; then
1677 printtask "... apply preloaded.patch ..."
1678 patch -Nls -p1 -d tmp/${FILE}.out < $PARB/preloaded.patch 2>&1 > preloaded.log
1679 cat preloaded.log >> "$LOG"
1680 [[ $(grep FAILED preloaded.log) != "" ]] && print_error "failed preloaded.patch"
1684 echo -n "" # do nothing else
1686 esac
1687 # substitute failed smali with provisional (a prepatched smali file)
1688 unset FAILS
1689 FAILS=($(grep FAILED ${JAR}.log | sed -e 's/.*smali\///' | sed -e 's/\.rej//'))
1690 if [[ -n ${FAILS[@]} ]]; then
1691 print_to_log "!!! PATCHING FAILED FOR ${FAILS[@]} !!!"
1692 echo "### replace ${FAILS[@]} ###" > ${JAR}.log
1693 for FAIL in ${FAILS[@]}; do
1694 PROVISIONAL="patches/$P/$ANDR/.provisionals/${FILE}.out/smali/${FAIL}"
1695 ALTERNATIVE_PATCH=$(ls $PARB/${NAME}$ALT_PATCH_NUMBER*.patch 2>/dev/null)
1696 if [ ! -f "$PROVISIONAL" ]; then
1697 if [ -f "$ALTERNATIVE_PATCH" ]; then
1698 printtask "## trying alternative ${NAME} patch ###"
1699 prep_alternate_patch
1700 else
1701 print_error "failed $FAIL in $JAR cannot be remedied"
1703 else
1704 echo "!!! patch error for $FAIL !!!" >> "$LOG"
1705 [[ ${SID[@]} =~ $FAIL ]] && print_error "$FAIL was already replaced before"
1706 copy_prepatched_provisional
1708 done
1710 [[ $(grep FAILED ${JAR}.log) != "" ]] && print_error "failed $NAME.patch"
1711 garbage tmp/${FILE}.out
1713 # run special $JAR.sh scripts if any JAR needs special attention
1714 if [ -f patches/$P/$A/$R/$B/${JAR}.sh ]; then
1715 printtask "... apply $JAR.sh ..."
1716 . patches/$P/$A/$R/$B/${JAR}.sh 2>&1 > ${JAR}.log
1717 cat ${JAR}.log | tee -a "$LOG"
1719 done
1721 [[ -n ${APKS[@]} ]] && echo "### apk patch $P/$A/$ROMTYPE/$B ###"
1722 echo "### apk patch $P/$A/$R/$B ###" >> "$LOG"
1723 for FILE in ${APKS[@]}; do
1724 APK=${FILE##*/}
1725 if [ -d "tmp/${FILE}.out" ] ; then
1726 printtask "... apply $APK.patch ..."
1727 patch -Nls -p2 -d tmp/${FILE}.out < $PARB/${APK}.patch 2>&1 > ${APK}.log
1728 cat ${APK}.log >> "$LOG"
1730 if [[ $(grep FAILED ${APK}.log) != "" ]]; then
1731 apk_copy
1732 declare -a APKID=( ${APKID[@]/$FILE/} )
1734 garbage tmp/${FILE}.out
1735 else
1736 echo "No $APK in your ROM. Not able to patch this file."
1737 echo "## No $APK in ROM ###" >> "$LOG"
1739 done
1740 [[ -n ${IMGS[@]} ]] && echo "### img patch $P/$A/$ROMTYPE/$B ###"
1741 echo "### img patch $P/$A/$R/$B ###" >> "$LOG"
1742 for FILE in ${IMGS[@]}; do
1743 IMG=${FILE##*/}
1744 printtask "... applying $IMG.patch ..."
1745 patch -Nls -p1 -d boot/ramdisk < $PARB/${IMG}.patch >> "$LOG" || print_error "failed patching $FILE"
1746 done
1748 # Text Editing Functions --this can really do just about anything. Needs a working restore!
1749 [[ -n ${TXTS[@]} ]] && echo "### text patch $P/$A/$ROMTYPE/$B ###"
1750 echo "### text patch $P/$A/$R/$B ###" >> "$LOG"
1751 for FILE in ${TXTS[@]}; do
1752 TXT=${FILE##*/}
1753 if [[ -f $PARB/${TXT}.patch ]]; then
1754 printtask "... apply $TXT.patch ..."
1755 patch -Nls -p2 -d system/ < $PARB/${TXT}.patch 2>&1 > ${TXT}.log
1756 #cat ${TXT}.log | tee -a "$LOG"
1757 [[ $(grep FAILED ${TXT}.log) != "" ]] && print_error "failed $TXT.patch"
1759 if [[ -f $PAR/${TXT}.awk ]]; then
1760 printtask "... apply $TXT.awk ..."
1761 awk -f $PAR/${TXT}.awk $FILE > text || print_error "failed $TXT.awk"
1762 mv text $FILE
1764 if [[ -f $PAR/${TXT}.sed ]]; then
1765 printtask "... apply $TXT.sed ..."
1766 sed -f $PAR/${TXT}.sed $FILE > text || print_error "failed $TXT.sed"
1767 mv text $FILE
1769 if [[ -f $PAR/${TXT}.sh ]]; then
1770 printtask "... apply $TXT.sh ..."
1771 . $PAR/${TXT}.sh 2>&1 >> ${TXT}.log || print_error "failed $TXT.sh"
1773 garbage system/
1774 done
1775 done
1777 # Device specific scripts- Placement is up-for-review
1778 if [ -f patches/.devices/$DID/$DID.sh ]; then
1779 . patches/.devices/$DID/$DID.sh
1782 # Replace updater-script for CM7- it formats system -Testing
1783 if [ "$ANDR" == "gingerbread" ]; then
1784 replace_updater
1787 # Rebuilding system files
1789 [[ -n ${JID[@]} ]] && printtask "### rebuild jar ###"
1790 for FILE in ${JID[@]}; do
1791 JAR=${FILE##*/}
1792 printtask "... rebuild $JAR ..."
1793 java -Xmx512M -jar smali.jar -a $API tmp/${FILE}.out/smali -o tmp/${FILE}.out/classes.dex >> "$LOG" 2>> "$LOG"
1794 [ -f tmp/${FILE}.out/classes.dex ] || smali_error "failed compiling $JAR !!!"
1795 jar -ufv ${FILE} -C tmp/${FILE}.out/ classes.dex >> "$LOG" 2>> "$LOG"
1796 if [ $FILE == "system/framework/framework.jar" ]; then
1797 jar -ufv ${FILE} -C tmp/${FILE}.out/ preloaded-classes >> "$LOG" 2>> "$LOG"
1799 done
1801 [[ -n ${APKID[@]} ]] && printtask "### rebuild apk ###"
1802 for FILE in ${APKID[@]}; do
1803 APK=${FILE##*/}
1804 if [ -d tmp/${FILE}.out ]; then
1805 apk_was_copied=false
1806 printtask "... rebuild $APK ..."
1807 java -jar apktool.jar b tmp/${FILE}.out >> "$LOG" 2>> "$LOG" || apk_copy
1808 if !("$apk_was_copied"); then
1809 jar -uvf $FILE -C tmp/${FILE}.out/build/apk/ . > /dev/null 2>> "$LOG"
1812 done
1814 [[ -n ${IID[@]} ]] && printtask "### rebuild img ###"
1815 for FILE in ${IID[@]}; do
1816 printtask "### rebuild $FILE ###"
1817 case $FILE in
1818 boot.img)
1819 # Rebuilding boot.img
1820 cd boot
1821 printtask "... rebuilding ramdisk ..."
1822 ./mkbootfs$EXE ./ramdisk | gzip > ramdisk-new.gz
1823 printtask "... composing boot.img ..."
1824 BASE=$(cat boot.img-base)
1825 # hex to decimal in cygwin prefixing "0x" w/ C arithmetic
1826 PGSIZE=$((${PGFORM}$(cat boot.img-pagesize)))
1827 CMDLINE=$(cat boot.img-cmdline)
1828 echo "cmdline = no_console_suspend=1 console=null $CMDLINE" >> "$LOG"
1829 echo "pagesize = $PGSIZE" >> "$LOG"
1830 echo "base = $BASE" >> "$LOG"
1831 printtask "... rebuilding boot.img ..."
1832 ./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"
1833 cd ..
1836 print_error "cannot process $FILE"
1838 esac
1839 done
1841 printtask "### create $UPDATE.zip ###"
1842 jar -cfv tmp.zip ${IID[@]} ${JID[@]} ${AID[@]} ${CID[@]} ${TID[@]} META-INF >> "$LOG" 2>> "$LOG"
1843 java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip $UPDATE.zip 2>> "$LOG"
1845 \mv $RESTORE.zip $UPDATE.zip ..
1846 printtask "### finished ###"
1847 printtask ""
1848 printtask "$(colorize_bold ${red}Congratulations), the patching was $(colorize_bold ${red}successful)."
1849 printtask "Any errors you may have seen were succesfully handled!"
1850 printtask ""
1851 printtask "!!! Only file a bug report if the software is $(colorize_bold ${grn}not) behaving as expected !!!"
1852 printtask ""
1853 echo "to install patched files, flash:"
1854 printtask "---$(colorize_bold ${grn}$UPDATE.zip)"
1855 echo ""
1856 printtask "to restore original system, flash:"
1857 printtask "---$(colorize_bold ${grn}$RESTORE.zip)"
1858 echo ""
1860 # add announcement- optional.
1861 for P in ${PID[@]}; do
1862 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
1863 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
1864 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
1865 if [ -f patches/$P/$A/$R/$B/README.txt ]; then
1866 cat patches/$P/$A/$R/$B/README.txt
1867 elif [ -f patches/$P/$A/$R/README.txt ]; then
1868 cat patches/$P/$A/$R/README.txt
1869 elif [ -f patches/$P/$A/README.txt ]; then
1870 cat patches/$P/$A/README.txt
1872 done
1874 cd ..
1875 \rm -rf "$TEMP"