Bump vesion to 2.2.0.2
[auto-patcher.git] / auto_patcher
blob25b7d0b5b0f63635ad258c73c47998ec09ad2977
1 #!/bin/bash
3 # version: beta v2.2.02, patches 2012.010.20.
5 # PDroid created by svyat. Official PDroid thread is
6 # http://forum.xda-developers.com/showthread.php?t=1357056
8 # The Auto-Patcher created by pastime1971 and mateorod
9 # Thread and support for the Auto-Patcher can be found at
10 # http://forum.xda-developers.com/showthread.php?p=27589651#post27589651
12 # ChangeLog
13 # 2012.05.00. (v0.1)
14 # ...........
15 # 2012.05.12. (v0.2) allows user to specify a different version of patches
16 # 2012.05.13. (v0.3.0) force "patch -N", remove temp upon failure, generate log output
17 # 2012.05.13. (v0.3.1) revised the generation of updater-script (SGS2)
18 # 2012.05.15. added AOSP patches
19 # 2012.05.15. added crespo-aosp patches, added device-specific patching if patch exists
20 # 2012.05.15. remove restore.zip upon failure
21 # 2012.05.15. (v0.4.1) added CM7 (GB) patches
22 # 2012.05.18. (v0.4.2) added checking for tool commands
23 # 2012.05.21. (v0.4.3) apply device-specific patche only when it is specified
24 # 2012.05.26. added task title to log
25 # 2012.05.31. (v0.4.4) CM9 patches updated, crespo-aosp added
26 # 2012.06.04. (v0.4.5) added checking tools and rom, added aroma installer support, 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. (1.9.6) Conditional support for Official cm10 and aokp-jb builds
57 # 2012.08.23. (1.9.7) Final/confirmed pdroid support for Official CM10 and AOKP-JB
58 # 2012.09.04 (1.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. (2.0.0) Added .apk patching
62 # Added 3G Dongle support for Nexus 7
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
68 # 2012.09.11. (2.0.1) Cygwin support fixes
69 # 2012.09.11. (2.0.2) Bugfix for 3gdongle (all)
70 # 2012.09.16. (2.1.0) Significant restructuring of core operations; added edit text file
71 # fix for "method-cap" errors in pdroid.
72 # 2012.09.20. (2.1.1) Fix for Phone FC's; OSX support finalized; ContentResolver resolved
73 # 2012.09.28. (2.1.2) Hotfix for failed pdroid patching. Logging improvements.
74 # 2012.10.07. (2.1.5) Final pdroid support for CM7.2 Official Releases
75 # Added aosp-mod patches for pdroid patching of AOSP kangs
76 # Switched to Chainfire's (f)aapt for speed/space reasons
77 # 2012.10.13. (2.1.6) New PDroid patches for aokp-jb and cm10 4.1.2
78 # Revert (f)aapt- temporary due to reported issues
79 # 2012.10.15. (2.17) New (again) CM10 pdroid patches.
80 # Move files to be copied into $p/$R/$B
81 # -This required a bunch of file moving-report broken symlinks.
82 # Some error check on the old RIL delete functions (thanks bundrik)
83 # 2012.10.16. (2.1.7.5) Fix FC on phone with CM10 pdroid patches
84 # 2012.10.19. (2.1.9) Testing CM10 support for PDroid Extension by CollegeDev.
85 # 2012.10.22. (2.2.0) aosp/aokp and cm10 support for pdroid extension by CollegeDev
86 # MAJOR reworking of patches and improved query. only 4 mod types:
87 # cm, aokp, aosp, and pa. See our OP for details.
88 # 2012.10.23. (2.2.0.1) Some fixes for the breakage due to update.
89 # Adjust aapt permissions and add fix_aapt.sh script.
90 # Fix for aosp probing and mod/jb determining. Test Update.
91 # 2012.10.23. (2.2.03) Add the '-h' menu back, bump version for log purposes.
93 # SHELL PROGRAMMING NOTES:
94 # [ -s FILE ]
95 # [[ -n STRING ]] or [[ -z STRING ]]
97 VERSION="Auto-Patcher v2.2.02"
99 echo ""
100 echo "The $VERSION"
101 echo ""
102 # by pastime1971 and mateorod
105 # pass variables to children
106 set -a
108 # function for converting hex to binary- for testing
109 #function h2b { echo "obase=2; ibase=16; $( echo "$*" | sed -e 's/0x//g' -e 's/\([a-z]\)/\u\1/g' )" | bc; }
111 printusage () {
112 echo " The $VERSION"
113 echo " pdroid 1.32 patches 2012.09.13."
114 echo " v6supercharger patches 2012.08.17."
115 echo ""
116 echo "usage: $0 ROM.ZIP MODS [ROMTYPE] [PATCHDATE]"
117 echo ""
118 echo "MODS can be pdroid,v6supercharger or pdroid or v6supercharger"
119 echo "optional [ROMTYPE] can be cm9, aokp, etc."
120 echo "optional [PATCHDATE] can be specified to use older patch versions."
121 echo "try \"$0 ROM.ZIP -h\" to see what is available"
122 echo ""
123 exit
126 debug () {
127 echo "! please refer to $LOG for any debugging"
128 echo ""
129 echo "! patching failed."
130 echo "! it may be possible to patch $ROM using other patch version"
131 echo ""
132 [ -d "$TEMP" ] && \rm -rf "$TEMP"
133 printusage
136 printerror () {
137 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
138 echo "!!! error: $@"
139 echo "!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"
140 echo ""
141 debug
144 printtask () {
145 echo "" >> "$LOG"
146 echo $@ | tee -a "$LOG"
149 copyfailed () {
150 echo ""
151 echo "File for which patching failed:"
152 echo "---------------------------------------------"
153 echo ""
154 echo "${FAIL##*/}"
155 echo ""
156 echo "---------------------------------------------"
157 echo ""
158 echo "We can try to add a premade copy of those files."
159 echo "This sometimes works."
160 echo ""
161 echo "But IT MAY NOT WORK!!!"
162 echo ""
163 echo ""
164 askconsent && return 0 || return 1
167 askconsent () {
168 sleep 1
169 echo -n "Do you want to proceed ? (YES/no) "
170 read PROCEED
171 echo "askconsent intial = ${PROCEED}" >> "$LOG"
172 case $PROCEED in
173 [Yy] | [Yy][Ee][Ss])
174 echo ""
177 return 1; # error
179 esac
180 echo -n "Are you sure ? (YES/no) "
181 read PROCEED
182 echo "askconsent final = ${PROCEED}: for $FAIL" >> "$LOG"
183 case $PROCEED in
184 [Yy] | [Yy][Ee][Ss])
185 return 0; # successful
188 return 1; # error
190 esac
193 abspath () {
194 case `uname -s` in
195 CYGWIN*)
196 echo $(cygpath -ua "$1")
198 Darwin)
199 #[[ $(echo $1 | awk '/^\//') == $1 ]] && echo "$1" || echo "$PWD/$1"
200 [[ ${1:0:1} == "/" ]] && echo "$1" || echo "$PWD/$1"
202 Linux)
203 echo $(readlink -f "$1")
206 if [[ ${1:0:1} == "/" ]]; then
207 echo "$1"
208 elif [[ ${1:0:2} == "./" ]]; then
209 echo "$PWD/${1:2}"
210 else
211 echo "$PWD/$1"
214 esac
217 extpath () {
218 case `uname -s` in
219 CYGWIN*)
220 echo $(cygpath -da "$1")
223 echo $(abspath "$1")
225 esac
228 #contains () { for e in "${@:2}"; do [[ "$e" = "$1" ]] && return 0; done; return 1; }
230 parse () { echo "${1%%_*}"; }
232 getbuildprop () {
233 if [ -f system/build.prop ]; then
234 result=(`grep $1 system/build.prop | tr -d '\r' | tr '=' ' '`)
235 echo "${result[1]}"
236 else
237 echo ""
242 aosp_mod_check() {
243 jar -xvf "$ROMX" system/framework/framework2.jar >> $LOG
244 if [ -s system/framework/framework2.jar ]; then
245 AOSP=aosp-mod
246 else
247 AOSP=aosp-jb
249 echo $AOSP
252 proberom () {
253 VID=$(getbuildprop ro.build.version.release)
255 if [ "${VID%.*}" == "2.3" ]; then
256 ANDR=gingerbread
257 RID=cm;
258 elif [ "${VID%.*}" == "4.0" ]; then
259 ANDR=ics
260 MID=$(getbuildprop ro.rommanager.developerid)
261 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.modversion))
262 DID=$(getbuildprop ro.product.device)
263 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
265 case "$MID" in
266 pa|cm9|cm|cyanogenmod*)
267 RID=cm;
269 aokp|teamkang)
270 RID=aokp;
272 # aosp|AOSP) # AOSP probing does not work yet
273 # RID=aosp;
274 # ;;
276 RID=aosp;
277 echo "!!! $MID is not supported yet, trying generic latest !!!"
279 esac
280 elif [ "${VID%.*}" == "4.1" ]; then
281 ANDR=jellybean
282 MID=$(getbuildprop ro.build.display.id)
283 [[ "$MID" == "" ]] && MID=$(parse $(getbuildprop ro.build.display.id))
284 DID=$(getbuildprop ro.product.device)
285 [[ "$DID" == "" ]] && DID=$(getbuildprop ro.build.product)
287 case "$MID" in
288 cm10|cm*|cyanogenmod*)
289 RID=cm;
291 aokp*|teamkang)
292 RID=aokp;
294 pa*)
295 RID=pa;
298 RID=`aosp_mod_check`;
300 esac
301 else
302 printerror "unknown ROM version $VID"
304 echo "... result of ROM check: version= $ANDR rom= $RID ..."
307 # NEW # Advanced build date query
308 # This should set the patch date automatically.
310 buildquery() {
312 if [ $# -gt 3 ]; then
313 BID=${4//,/ };
314 elif
315 [[ ${#PID[@]} -gt 1 ]]; then
316 BID=latest;
317 else
318 for P in ${PID[@]}; do
319 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
320 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
321 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
322 PAR=patches/$P/$A/$R
323 PARB=patches/$P/$A/$R/$B
324 UTC=$(getbuildprop ro.build.date.utc)
325 BDID=`date -d "1970-01-01 UTC $UTC seconds" +"%Y%m%d"`
326 DATES=`ls patches/$P/$A/$R/ | grep '201*'`
327 # attempt to set builds before extant patches to earliest
328 for i in $DATES; do
329 if [[ $i -lt $BID ]]; then
330 BID=$i
332 if [[ $(($BID-$BDID)) -lt 0 ]]; then
333 BID=$i
334 else
335 for g in $DATES; do
336 if [[ $(($BDID-$g)) -eq 0 ]]; then
337 BID=$g
338 break
339 elif [[ $(($BDID-$g)) -gt 0 ]] && [[ $g -gt $BID ]]; then
340 BID=$g
342 done
344 done
345 echo "... $PID patch date has been set to: $BID..."
346 B=$BID
347 done
351 proberil () {
352 RIL=$(getbuildprop ro.telephony.ril_class)
353 [[ -n $RIL ]] && printtask "... result of ROM check: RIL= $RIL"
356 garbage () {
357 unset GARBAGE
358 GARBAGE=($(find $@ -name "*.orig")) && rm -rf ${GARBAGE[@]} && echo "GARBAGE= ${GARBAGE[@]}" >> "$LOG"
359 GARBAGE=($(find $@ -name "*.rej")) && rm -rf ${GARBAGE[@]} && echo "GARBAGE= ${GARBAGE[@]}" >> "$LOG"
362 rominfo () {
363 echo "# VER= $VERSION" >> "$LOG"
364 echo "# OS= $OSTYPE ${BIT}bit" >> "$LOG"
365 echo "# VID= $VID" >> "$LOG"
366 echo "# PID= ${PID[@]}" >> "$LOG"
367 echo "# MID= $MID" >> "$LOG"
368 echo "# RID= $RID" >> "$LOG"
369 echo "# ANDR= $ANDR" >> "$LOG"
370 echo "# BDID= $BDID" >> "$LOG"
371 echo "# DID= $DID" >> "$LOG"
372 echo "# BID= $BID" >> "$LOG"
376 [[ $# -lt 1 || $1 == "-h" || -z $1 ]] && printusage
378 ROOT=$(abspath `dirname "$0"`)
379 TOOL="$ROOT/patch_tools.tgz"
380 PTCH="$ROOT/patch_patches.tgz"
381 ROM=$(abspath "$1")
382 ROMX=$(extpath "$1")
384 if [[ $OSTYPE == "cygwin" ]]; then
385 EXE=".exe"
386 PGFORM="0x"
389 DATE=`date +%Y%m%d%H%M%S`
390 TEMP=$(abspath ./tmp$DATE)
391 LOG=$(abspath ./log$DATE.txt)
392 #echo $ROOT $TOOL $ROM $TEMP "$LOG"
393 echo "ROOT= $ROOT" >> "$LOG"
394 echo "TOOL= $TOOL" >> "$LOG"
395 echo "ROM= $ROM" >> "$LOG"
396 echo "ROMX= $ROMX" >> "$LOG"
398 \rm -f restore.zip update.zip
400 CHK=$(getconf LONG_BIT)
401 if [[ $CHK = "64" ]]; then
402 BIT=64
403 else [[ $BIT = "32" ]];
404 BIT=32
408 printtask "### verify tools ###"
409 which patch >> "$LOG" || printerror "Missing \"patch diff command\""
410 which tar >> "$LOG" || printerror "Missing \"tar archive command\""
411 which jar >> "$LOG" || printerror "Missing \"jar (JDK)\""
412 which java >> "$LOG" || printerror "Missing \"java (JRE)\""
413 which cpio >> "$LOG" || printerror "Missing \"cpio archive command\""
414 [ -f "$TOOL" ] || printerror "patch tool is missing"
415 [ -f "$PTCH" ] || printerror "patch patches are missing"
416 printtask "### verify ROM ###"
417 [ -f "$ROM" ] || printerror "Cannot find $ROM"
418 echo "### running $0 $@" >> "$LOG"
419 mkdir "$TEMP"
420 cd "$TEMP"
422 PATH="$TEMP:$PATH"
423 export PATH
424 echo "PATH= $PATH" >> "$LOG"
426 printtask "### unzip patch tools ###"
427 tar xvzf "$TOOL" > /dev/null || printerror "failed extracting tools !!!"
429 # Get OS specific tools
430 case `uname -s` in
431 CYGWIN*)
432 \mv cygwin/aapt.exe .
433 \mv cygwin/*.exe boot/
434 \rm -rf cygwin # why? If you want to we can keep/add it to mac/linux, though.
436 [Dd]arwin)
437 \mv mac/aapt .
439 [Ll]inux)
440 \mv linux/aapt .
443 \mv linux/aapt .
445 esac
447 printtask "### unzip patch patches ###"
448 tar xvzf "$PTCH" > /dev/null || printerror "failed extracting patches !!!"
450 # we need build.prop for both RIL probing and ROM probing
451 jar -xvf "$ROMX" system/build.prop 2>> "$LOG" || printerror "failed extracting build.prop from $ROMX !!!"
453 # rom + ril type
454 proberil
455 printtask "### probe rom type ###"
456 proberom
458 # rom type
459 if [ $# -gt 2 ]; then
460 RID=$3
461 case "$RID" in
462 cm10|cm*|cyanogenmod*)
464 aokp*|teamkang)
465 RID=aokp;
467 pa*)
468 RID=pa;
471 RID=`aosp_mod_check`;
473 esac
474 echo "... Using $RID patches ..."
475 else
476 echo "... Using results of ROM check ..."
479 # patch type
480 if [ $# -gt 1 ]; then
481 PIL=${2//,/ }
482 else
483 #PIL=`ls patches/`
484 PIL="pdroid v6supercharger"
485 echo "No mods selected. Defaulting to the v6 and Pdroid, just because we can."
487 # a hack to make sure pdroid is the first mod
488 [[ ${PIL[@]} =~ pdroid ]] && PID=(pdroid)
489 for P in ${PIL[@]}; do
490 [[ ${PID[@]} =~ $P ]] || PID=(${PID[@]} $P)
491 done
493 # Build date
494 if [ $# -gt 3 ]; then
495 BID=$4
496 echo "... $PID patch date set manually to $BID ..."
497 else
498 buildquery
501 # echo ROM info
502 rominfo
504 if [[ ( "$PID" == "-h" || "$ANDR" == "-h" || "$RID" == "-h" || "$BID" == "-h" ) ]]; then
505 echo "### supported patch candidates ###"
506 MODS=$(ls patches)
507 #echo ${MODS[@]}
509 for M in ${MODS[@]}; do
510 AND=$(ls --ignore="common" --ignore="*.txt" patches/$M)
511 #echo $M: ${AND[@]}
512 for A in ${AND[@]}; do
513 RID=$(ls --ignore="common" --ignore="*.sh" --ignore "provisionals" --ignore="*.txt" patches/$M/$A)
514 #echo $M: $A: ${RID[@]}
515 for R in ${RID[@]}; do
516 BID=$(ls --ignore "common" --ignore="*.sh" --ignore="*.txt" --ignore=".awk" -v patches/$M/$A/$R)
517 echo $M: $A: $R: ${BID[@]}
518 done
519 done
520 done
521 echo ""
522 echo "*****************************************************************"
523 echo ""
524 echo "Note: There are ONLY 4 ROMTYPES: [pa, cm, aokp, and aosp]."
525 echo "The Auto-Patcher will automatically slot if you need aosp-jb or aosp-mod"
526 echo ""
528 else
529 for P in ${PID[@]}; do
530 [ -d patches/$P ] || printerror "$P is not available"
531 [ -d patches/$P/$ANDR ] && R=$ANDR || A=all
532 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
533 #[ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
535 unset FILES
536 [ -f patches/$P/files.txt ] && FILES=$(cat patches/$P/files.txt)
537 [ -f patches/$P/$A/files.txt ] && FILES=$(cat patches/$P/$A/files.txt)
538 [ -f patches/$P/$A/$R/files.txt ] && FILES=$(cat patches/$P/$A/$R/files.txt)
539 for FILE in ${FILES[@]}; do
540 case "$FILE" in
541 +system/*)
542 [[ ${CID[@]} =~ ${FILE:1} ]] && printerror "${FILE:1} is already being copied" || CID=(${CID[@]} ${FILE:1})
544 -system/*)
545 [[ ${EID[@]} =~ ${FILE:1} ]] || EID=(${EID[@]} ${FILE:1})
547 system/*.jar)
548 [[ ${JID[@]} =~ $FILE ]] || JID=(${JID[@]} $FILE)
550 system/*.apk)
551 [[ ${AID[@]} =~ $FILE ]] || AID=(${AID[@]} $FILE)
553 *.img)
554 [[ ${IID[@]} =~ $FILE ]] || IID=(${IID[@]} $FILE)
556 system/*)
557 [[ ${TID[@]} =~ $FILE ]] || TID=(${TID[@]} $FILE)
559 esac
560 done
561 done
562 echo "### DELETE FILES= ${EID[@]}" >> "$LOG"
563 echo "### COPY FILES= ${CID[@]}" >> "$LOG"
564 echo "### JAR FILES= ${JID[@]}" >> "$LOG"
565 echo "### APK FILES= ${AID[@]}" >> "$LOG"
566 echo "### IMG FILES= ${IID[@]}" >> "$LOG"
567 echo "### TXT FILES= ${TID[@]}" >> "$LOG"
569 printtask "### unzip rom ###"
570 # extract system files
571 jar -xvf "$ROMX" ${JID[@]} ${AID[@]} ${IID[@]} ${TID[@]} 2>> "$LOG" || printerror "failed extracting ${JID[@]} ${AID[@]} ${IID[@]} from $ROMX !!!"
572 #\cp -a system/ backup # only for debugging purpose
574 printtask "### create updater script ###"
575 jar -xvf "$ROMX" META-INF/com/google/android/updater-script META-INF/com/google/android/update-binary
576 jar -xvf "$ROMX" META-INF/com/google/android/update-binary-installer 1> /dev/null 2> /dev/null
577 if [ -f META-INF/com/google/android/update-binary-installer ]; then
578 printtask "... using Aroma installer ..."
579 \mv META-INF/com/google/android/update-binary-installer META-INF/com/google/android/update-binary
580 else
581 printtask "... using Clockworkmod installer ..."
583 if [ -f META-INF/com/google/android/update-binary ]; then
584 #echo "# original updater-script" >> "$LOG"
585 #cat META-INF/com/google/android/updater-script >> "$LOG"
587 cat META-INF/com/google/android/updater-script | grep ^mount | grep "/system" | head -n 1 > updater-script
588 [ -s updater-script ] || echo "run_program(\"/sbin/busybox\", \"mount\", \"/system\");" > updater-script
590 for FILE in ${EID[@]}; do
591 # restore the original
592 jar -xvf "$ROMX" $FILE 2> /dev/null || printtask "!!! warning $FILE cannot be restored !!!"
593 done
594 for FILE in ${CID[@]}; do
595 # replace with the original or delete it
596 jar -xvf "$ROMX" $FILE 2> /dev/null || echo "delete(\"/$FILE\");" >> updater-script
597 done
599 echo "package_extract_dir(\"system\", \"/system\");" >> updater-script
600 # add permission management
601 cat META-INF/com/google/android/updater-script | grep set_perm | grep "/system" >> updater-script
602 # TODO: remove if we don't need it any more
603 for P in ${PID[@]}; do
604 if [ -s patches/$P/$A/set_perm.txt ]; then
605 echo "...adding permissions..."
606 cat patches/$P/$A/set_perm.txt >> updater-script
608 done
610 cat META-INF/com/google/android/updater-script | grep ^unmount | grep "/system" | head -n 1 >> updater-script
612 [[ ${IID[@]} =~ boot.img ]] && cat META-INF/com/google/android/updater-script | grep "boot.img" >> updater-script
614 cat updater-script > META-INF/com/google/android/updater-script
616 echo "# generated updater-script" >> "$LOG"
617 cat updater-script >> "$LOG"
618 else
619 # this is not enough any more
620 jar -xvf update-template.zip META-INF/com/google/android/update-binary META-INF/com/google/android/updater-script
623 printtask "### create restore.zip ###"
624 jar -cfv tmp.zip ${JID[@]} ${AID[@]} ${IID[@]} META-INF > /dev/null 2>> "$LOG"
625 java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip signed.zip 2>> "$LOG"
626 \mv signed.zip restore.zip
627 \rm -f tmp.zip
629 printtask "### decompile system files ###"
631 # decompile system files
632 for FILE in ${JID[@]}; do
633 JAR=${FILE##*/}
634 printtask "... decompile $JAR ..."
635 java -jar baksmali.jar -b -a 15 -o tmp/${FILE}.out/smali ${FILE} >> "$LOG" 2>> "$LOG"
636 if [ $FILE == "system/framework/framework.jar" ]; then
637 printtask "... extract preloaded-classes ..."
638 jar -xvf ${FILE} preloaded-classes >> "$LOG" 2>> "$LOG"
639 \mv preloaded-classes tmp/${FILE}.out/
641 done
642 for FILE in ${AID[@]}; do
643 APK=${FILE##*/}
644 printtask "... decompile $APK ..."
645 if [ $FILE == "system/framework/framework-res.apk" ]; then
646 printtask "... installing framework files ..."
647 java -jar apktool.jar if $FILE
649 java -jar apktool.jar d -f $FILE tmp/$FILE.out
651 done
652 for FILE in ${IID[@]}; do
653 printtask "### unpacking $FILE ###"
654 case "$FILE" in
655 boot.img)
656 cd boot
657 ./unpackbootimg$EXE -i ../boot.img >> "$LOG" 2>> "$LOG"
659 mkdir ramdisk
660 cd ramdisk
661 gzip -dc ../boot.img-ramdisk.gz | cpio -i >> "$LOG" 2>> "$LOG"
662 cd ../../
665 printerror "cannot process $FILE"
667 esac
668 done
671 # apply system modification
673 for P in ${PID[@]}; do
674 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
675 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
676 [ -d patches/$P/$A/$R/$BID ] && B=$BID || B=latest
677 PAR=patches/$P/$A/$R
678 PARB=patches/$P/$A/$R/$B
680 unset FILES COPY DELS JARS APKS IMGS TXTS
681 [ -f patches/$P/$A/files.txt ] && FILES=$(cat patches/$P/$A/files.txt)
682 [ -f patches/$P/$A/$R/files.txt ] && FILES=$(cat patches/$P/$A/$R/files.txt)
683 for FILE in ${FILES[@]}; do
684 case $FILE in
685 +system/*)
686 COPY=(${COPY[@]} ${FILE:1})
688 -system/*)
689 DELS=(${DELS[@]} ${FILE:1})
691 system/*.jar)
692 JARS=(${JARS[@]} $FILE)
694 system/*.apk)
695 APKS=(${APKS[@]} $FILE)
697 *.img)
698 IMGS=(${IMGS[@]} $FILE)
700 system/*)
701 TXTS=(${TXTS[@]} $FILE)
703 esac
704 done
706 [[ -n ${COPY[@]} ]] && printtask "### copy patch $P/$A/$R/$B ###"
707 for FILE in ${COPY[@]}; do
708 printtask "... copying $FILE ..."
709 DEST=${FILE%/*}
710 mkdir -p ./$DEST
711 if [ -e patches/$P/$A/$R/$B/$FILE ]; then
712 [ -e $FILE ] && printtask "... overwriting $FILE from $P ..."
713 \cp -av patches/$P/$A/$R/$B/$FILE ./$DEST >> "$LOG"
714 else
715 printerror "$FILE is missing in the patch"
717 done
719 # unconditional smali copying
720 [ -f patches/$P/smali.txt ] && SMALI=$(cat patches/$P/smali.txt)
721 [ -f patches/$P/$A/smali.txt ] && SMALI=$(cat patches/$P/$A/smali.txt)
722 [ -f patches/$P/$A/$R/smali.txt ] && SMALI=$(cat patches/$P/$A/$R/smali.txt)
723 [ -f patches/$P/$A/$R/$B/smali.txt ] && SMALI=$(cat patches/$P/$A/$R/$B/smali.txt)
724 MOVE=${SMALI##*/}
725 for SMALI in ${SMALI[@]}; do
726 printtask "... overwriting $MOVE ..."
727 \cp -av patches/$P/$ANDR/provisionals/$SMALI tmp/$SMALI >> "$LOG"
728 done
731 [[ -n ${DELS[@]} ]] && printtask "### delete patch $P/$A/$R/$B ###"
732 for FILE in ${DELS[@]}; do
733 printtask "... deleting $FILE ..."
734 \rm -rf ./$FILE
735 done
737 [[ -n ${JARS[@]} ]] && printtask "### jar patch $P/$A/$R/$B ###"
738 for FILE in ${JARS[@]}; do
739 JAR=${FILE##*/}
740 NAME=${JAR%.jar}
741 printtask "... apply $NAME.patch ..."
742 patch -Nls -p1 -d tmp/${FILE}.out < $PARB/${NAME}.patch 2>&1 > ${JAR}.log
743 cat ${JAR}.log | tee -a "$LOG"
744 case "$NAME" in
745 framework)
746 # patch preloaded-classes only if a patch exists
747 if [ -f $PARB/preloaded.patch ]; then
748 printtask "... apply preloaded.patch ..."
749 patch -Nls -p1 -d tmp/${FILE}.out < $PARB/preloaded.patch 2>&1 > preloaded.log
750 cat preloaded.log | tee -a "$LOG"
751 [[ `grep FAILED preloaded.log` != "" ]] && printerror "failed preloaded.patch"
755 echo -n "" # do nothing else
757 esac
758 # substitute failed smali with premade jar
759 unset FAILS
760 FAILS=(`grep FAILED ${JAR}.log | sed -e 's/.*smali\///' | sed -e 's/\.rej//'`)
761 if [[ -n ${FAILS[@]} ]]; then
762 printtask "!!! PATCHING FAILED FOR ${FAILS[@]} !!!"
763 echo "### replace ${FAILS[@]} ###" > ${JAR}.log
764 for FAIL in ${FAILS[@]}; do
765 echo "!!! patch error for $FAIL !!!" >> "$LOG"
766 #cat tmp/$FILE.out/smali/${FAIL}.rej >> "$LOG"
767 [[ ${SID[@]} =~ $FAIL ]] && printerror "$FAIL was already replaced before"
768 [ -f patches/$P/$ANDR/provisionals/${FILE}.out/smali/${FAIL} ] || printerror "failed $FAIL in $JAR cannot be remedied"
769 copyfailed || printerror "failed $NAME.patch"
770 printtask "... replace $FAIL ..."
771 \rm -rf tmp/${FILE}.out/smali/${FAIL} tmp/${FILE}.out/smali/${FAIL}.orig tmp/${FILE}.out/smali/${FAIL}.rej
772 \cp -av patches/$P/$ANDR/provisionals/${FILE}.out/smali/${FAIL} tmp/${FILE}.out/smali/${FAIL} >> "$LOG" || echo "FAILED to cp $FAIL" >> ${JAR}.log
773 SID=(${SID[@]} $FAIL)
774 done
776 [[ `grep FAILED ${JAR}.log` != "" ]] && printerror "failed $NAME.patch"
777 garbage tmp/${FILE}.out
778 if [ -f patches/$P/$A/$R/$B/{JAR}.sh ]; then
779 printtask "... apply $JAR.sh ..."
780 . patches/$P/$A/$R/$B/{JAR}.sh 2>&1 > ${JAR}.log
781 cat ${JAR}.log | tee -a "$LOG"
783 done
785 [[ -n ${APKS[@]} ]] && printtask "### apk patch $P/$R/$B ###"
786 for FILE in ${APKS[@]}; do
787 APK=${FILE##*/}
788 if [ -s tmp/${FILE}.out ] ; then
789 printtask "... apply $APK.patch ..."
790 patch -Nls -p2 -d tmp/${FILE}.out < $PARB/${APK}.patch 2>&1 >> ${APK}.log
791 cat ${APK}.log | tee -a "$LOG"
792 [[ `grep FAILED ${APK}.log` != "" ]] && printerror "failed $APK.patch"
793 garbage tmp/${FILE}.out
794 else
795 echo "No $APK in your ROM. Not able to patch this file."
796 echo "## No $APK in ROM ###" >> "$LOG"
798 done
799 [[ -n ${IMGS[@]} ]] && printtask "### img patch $P/$A/$R/$B ###"
800 for FILE in ${IMGS[@]}; do
801 IMG=${FILE##*/}
802 #NAME=${IMG%.img}
803 echo "... applying $IMG.patch ..."
804 patch -Nls -p1 -d boot/ramdisk < $PARB/${IMG}.patch >> "$LOG" || printerror "failed patching $FILE"
805 # Special Instructions- married to boot.img patching by necessity, not design. When
806 # added to it's own section, it only runs for one mod. WIP.
807 #if [ -f patches/$P/$R/special_instructions.sh ]; then
808 # . patches/$P/$R/special_instructions.sh
809 #elif [ -f patches/$P/special_instruction.sh ]; then
810 # . patches/$P/special_instructions.sh
812 done
814 [[ -n ${TXTS[@]} ]] && printtask "### text patch $P/$A/$R/$B ###"
815 for FILE in ${TXTS[@]}; do
816 TXT=${FILE##*/}
817 if [[ -f $PARB/${TXT}.patch ]]; then
818 printtask "... apply $TXT.patch ..."
819 patch -Nls -p2 -d system/ < $PARB/${TXT}.patch 2>&1 > ${TXT}.log
820 #cat ${TXT}.log | tee -a "$LOG"
821 [[ `grep FAILED ${TXT}.log` != "" ]] && printerror "failed $TXT.patch"
823 if [[ -f $PAR/${TXT}.awk ]]; then
824 printtask "... apply $TXT.awk ..."
825 awk -f $PAR/${TXT}.awk $FILE > text || printerror "failed $TXT.awk"
826 mv text $FILE
828 if [[ -f $PAR/${TXT}.sed ]]; then
829 printtask "... apply $TXT.sed ..."
830 sed -f $PAR/${TXT}.sed $FILE > text || printerror "failed $TXT.sed"
831 mv text $FILE
833 if [[ -f $PAR/${TXT}.sh ]]; then
834 printtask "... apply $TXT.sh ..."
835 . $PAR/${TXT}.sh 2>&1 >> ${TXT}.log || printerror "failed $TXT.sh"
837 garbage system/
838 done
839 done
841 # Rebuilding system files
843 [[ -n ${JID[@]} ]] && printtask "### rebuild jar ###"
844 for FILE in ${JID[@]}; do
845 JAR=${FILE##*/}
846 printtask "... rebuild $JAR ..."
847 java -Xmx512M -jar smali.jar -a 15 tmp/${FILE}.out/smali -o tmp/${FILE}.out/classes.dex >> "$LOG" 2>> "$LOG"
848 [ -f tmp/${FILE}.out/classes.dex ] || printerror "failed compiling $JAR !!!"
849 jar -ufv ${FILE} -C tmp/${FILE}.out/ classes.dex >> "$LOG" 2>> "$LOG"
850 if [ $FILE == "system/framework/framework.jar" ]; then
851 jar -ufv ${FILE} -C tmp/${FILE}.out/ preloaded-classes >> "$LOG" 2>> "$LOG"
853 done
855 [[ -n ${AID[@]} ]] && printtask "### rebuild apk ###"
856 for FILE in ${AID[@]}; do
857 APK=${FILE##*/}
858 printtask "... rebuild $APK ..."
859 java -jar apktool.jar b tmp/${FILE}.out >> "$LOG" 2>> "$LOG" || printerror "failed compiling $FILE !!!"
860 jar -ufv $FILE -C tmp/${FILE}.out/build/apk/ . > /dev/null 2>> "$LOG"
861 #\rm -r tmp/${FILE}.out
862 done
864 [[ -n ${IID[@]} ]] && printtask "### rebuild img ###"
865 for FILE in ${IID[@]}; do
866 printtask "### rebuild $FILE ###"
867 case $FILE in
868 boot.img)
869 # Rebuilding boot.img
870 cd boot
871 printtask "... rebuilding ramdisk ..."
872 ./mkbootfs$EXE ./ramdisk | gzip > ramdisk-new.gz
874 printtask "... composing boot.img ..."
875 BASE=$(cat boot.img-base)
876 # convert hex to decimal in cygwin by prefixing "0x" and C-style arithmetic
877 PGSIZE=$((${PGFORM}$(cat boot.img-pagesize)))
878 CMDLINE=$(cat boot.img-cmdline)
879 echo "cmdline = no_console_suspend=1 console=null $CMDLINE" >> "$LOG"
880 echo "pagesize = $PGSIZE" >> "$LOG"
881 echo "base = $BASE" >> "$LOG"
883 printtask "... rebuilding boot.img ..."
884 ./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 || printerror "failed building boot.img"
885 cd ..
888 printerror "cannot process $FILE"
890 esac
891 done
893 printtask "### create update.zip ###"
894 jar -cfv tmp.zip ${IID[@]} ${JID[@]} ${AID[@]} ${CID[@]} ${TID[@]} META-INF >> "$LOG" 2>> "$LOG"
895 java -jar signapk.jar updatecert.pem updatekey.pk8 tmp.zip update.zip 2>> "$LOG"
896 #\rm -f tmp.zip
898 #echo "# miscellaneous log" >> "$LOG"
900 \mv restore.zip update.zip ..
901 echo "### finished ###"
902 echo "flash update.zip to install the modified"
903 echo "flash restore.zip to restore the original"
905 # add announcement
906 for P in ${PID[@]}; do
907 [ -d patches/$P/$ANDR ] && A=$ANDR || A=all
908 [ -d patches/$P/$A/$RID ] && R=$RID || R=generic
909 if [ -f patches/$P/$A/$R/README.txt ]; then
910 cat patches/$P/$A/$R/README.txt
911 elif [ -f patches/$P/$A/README.txt ]; then
912 cat patches/$P/$A/README.txt
914 done
916 cd ..
917 \rm -rf "$TEMP"