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