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