Chirayu Desai | 39cb878 | 2012-10-13 16:10:45 +0530 | [diff] [blame^] | 1 | #!/bin/bash |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 2 | # |
| 3 | # Squish a CM otapackage for distribution |
| 4 | # cyanogen |
| 5 | # |
| 6 | |
Chirayu Desai | 39cb878 | 2012-10-13 16:10:45 +0530 | [diff] [blame^] | 7 | . $ANDROID_BUILD_TOP/vendor/cm/tools/functions |
| 8 | |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 9 | OUT_TARGET_HOST=`uname -a | grep Darwin` |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 10 | if [ -z "$OUT_TARGET_HOST" ] |
| 11 | then |
| 12 | OUT_TARGET_HOST=linux-x86 |
| 13 | MD5=md5sum |
Takuo Kitame | 9db7666 | 2010-10-29 09:55:59 +0900 | [diff] [blame] | 14 | XARGS="xargs --max-args=1 --max-procs `grep 'processor' /proc/cpuinfo|wc -l`" |
| 15 | SED=sed |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 16 | else |
| 17 | OUT_TARGET_HOST=darwin-x86 |
| 18 | MD5=md5 |
Takuo Kitame | 9db7666 | 2010-10-29 09:55:59 +0900 | [diff] [blame] | 19 | XARGS="xargs -n 1 -P `sysctl hw.ncpu | awk '{print $2}'`" |
| 20 | SED=gsed |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 21 | fi |
| 22 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 23 | if [ -z "$OUT" -o ! -d "$OUT" ]; then |
Chirayu Desai | 39cb878 | 2012-10-13 16:10:45 +0530 | [diff] [blame^] | 24 | echo -e $CL_RED"ERROR: $0 only works with a full build environment. $OUT should exist."$CL_RST |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 25 | exit 1 |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 26 | fi |
| 27 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 28 | if [ ! -f "$OTAPACKAGE" ]; then |
Chirayu Desai | 39cb878 | 2012-10-13 16:10:45 +0530 | [diff] [blame^] | 29 | echo -e $CL_RED"$OTAPACKAGE doesn't exist!"$CL_RST; |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 30 | exit 1 |
| 31 | fi |
| 32 | |
Ricardo Cerqueira | e1f3738 | 2011-11-27 19:56:54 +0000 | [diff] [blame] | 33 | OPTICHARGER=$ANDROID_BUILD_TOP/vendor/cm/tools/opticharger |
Pat Thoyts | 304457f | 2010-07-11 02:42:36 -0400 | [diff] [blame] | 34 | QUIET=-q |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 35 | DELETE_BINS="applypatch applypatch_static check_prereq recovery updater" |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 36 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 37 | REPACK=$OUT/repack.d |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 38 | printf "Sanitizing environment..." |
| 39 | rm -rf $REPACK |
| 40 | mkdir -p $REPACK |
| 41 | echo |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 42 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 43 | |
| 44 | # Unpack the otapackage and opticharge all apks |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 45 | mkdir $REPACK/ota |
| 46 | ( |
| 47 | cd $REPACK/ota |
| 48 | printf "Unpacking $OTAPACKAGE..." |
Pat Thoyts | 304457f | 2010-07-11 02:42:36 -0400 | [diff] [blame] | 49 | unzip $QUIET $OTAPACKAGE |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 50 | echo |
Jorge Ruesga | 547bd46 | 2012-08-12 20:42:54 +0200 | [diff] [blame] | 51 | |
| 52 | # Move all apks to the same directory so xargs can |
| 53 | # use also with framework-res.apk. This allow process |
| 54 | # framework-res.apk in parallel with other apks |
| 55 | mkdir -p $REPACK/parallel |
| 56 | cd $REPACK/parallel |
| 57 | cp $REPACK/ota/system/framework/framework-res.apk . |
| 58 | cp $REPACK/ota/system/app/*.apk . |
| 59 | |
| 60 | # Do optimization in parallel |
Takuo Kitame | 9db7666 | 2010-10-29 09:55:59 +0900 | [diff] [blame] | 61 | find ./ -name \*.apk | $XARGS $OPTICHARGER |
Jorge Ruesga | 547bd46 | 2012-08-12 20:42:54 +0200 | [diff] [blame] | 62 | |
| 63 | # Move optimized apks to repack directory |
| 64 | mv -f $REPACK/parallel/framework-res.apk $REPACK/ota/system/framework/framework-res.apk |
| 65 | mv -f $REPACK/parallel/*.apk $REPACK/ota/system/app/ |
| 66 | |
| 67 | # Return to directory |
| 68 | cd $REPACK/ota |
| 69 | rm -rf $REPACK/parallel |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 70 | ) |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 71 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 72 | # Fix build.prop |
Takuo Kitame | 9db7666 | 2010-10-29 09:55:59 +0900 | [diff] [blame] | 73 | $SED -i \ |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 74 | -e '/ro\.kernel\.android\.checkjni/d' \ |
| 75 | -e '/ro\.build\.type/s/eng/user/' \ |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 76 | $REPACK/ota/system/build.prop |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 77 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 78 | |
| 79 | # Delete unnecessary binaries |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 80 | ( cd $REPACK/ota/system/bin; echo $DELETE_BINS | xargs rm -f; ) |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 81 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 82 | # No need for recovery |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 83 | rm -rf $REPACK/ota/recovery |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 84 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 85 | # Strip modules |
Pat Thoyts | 8ed18b5 | 2011-08-03 16:14:31 +0100 | [diff] [blame] | 86 | [ -d $REPACK/ota/system/lib/modules ] && \ |
| 87 | find $REPACK/ota/system/lib/modules -name "*.ko" -print0 | xargs -0 arm-eabi-strip --strip-unneeded |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 88 | |
| 89 | # Determine what to name the new signed package |
Warren Togami | 2128e2f | 2012-05-06 19:49:33 -1000 | [diff] [blame] | 90 | MODVERSION=`sed -n -e'/ro\.cm\.version/s/^.*=//p' $REPACK/ota/system/build.prop` |
| 91 | OUTFILE=$OUT/cm-$MODVERSION.zip |
Chirayu Desai | 39cb878 | 2012-10-13 16:10:45 +0530 | [diff] [blame^] | 92 | echo -e $CL_CYN"MODVERSION: $MODVERSION"$CL_RST |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 93 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 94 | # Pack it up and sign |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 95 | printf "Zipping package..." |
| 96 | ( cd $REPACK/ota; zip $QUIET -r $REPACK/update.zip . ) |
| 97 | echo |
| 98 | printf "Signing package..." |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 99 | SECURITYDIR=$ANDROID_BUILD_TOP/build/target/product/security |
Pavel Valenta | 1af866c | 2012-04-18 01:06:51 +0800 | [diff] [blame] | 100 | java -Xmx1024m \ |
Chirayu Desai | c10f6d5 | 2012-08-11 16:34:32 +0530 | [diff] [blame] | 101 | -jar $OUT/../../../host/$OUT_TARGET_HOST/framework/signapk.jar \ |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 102 | -w $SECURITYDIR/testkey.x509.pem $SECURITYDIR/testkey.pk8 \ |
| 103 | $REPACK/update.zip $OUTFILE |
| 104 | echo |
| 105 | printf "Cleaning up..." |
| 106 | rm -rf $REPACK |
| 107 | echo |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 108 | |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 109 | # Create a md5 checksum image of the repacked package |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 110 | ( |
| 111 | img=`basename $OUTFILE` |
| 112 | cd `dirname $OUTFILE` |
| 113 | $MD5 $img >$img.md5sum |
| 114 | echo |
Chirayu Desai | 39cb878 | 2012-10-13 16:10:45 +0530 | [diff] [blame^] | 115 | echo -e $CL_GRN"Package complete: $OUTFILE"$CL_RST |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 116 | cat $img.md5sum |
| 117 | echo |
| 118 | ) |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 119 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 120 | exit 0 |