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 |
| 56 | cd $REPACK/ota/system/framework |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 57 | $OPTICHARGER framework-res.apk |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 58 | cd $REPACK/ota/system/app |
Takuo Kitame | 9db7666 | 2010-10-29 09:55:59 +0900 | [diff] [blame] | 59 | find ./ -name \*.apk | $XARGS $OPTICHARGER |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 60 | ) |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 61 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 62 | # Fix build.prop |
Takuo Kitame | 9db7666 | 2010-10-29 09:55:59 +0900 | [diff] [blame] | 63 | $SED -i \ |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 64 | -e '/ro\.kernel\.android\.checkjni/d' \ |
| 65 | -e '/ro\.build\.type/s/eng/user/' \ |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 66 | $REPACK/ota/system/build.prop |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 67 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 68 | |
| 69 | # Delete unnecessary binaries |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 70 | ( cd $REPACK/ota/system/bin; echo $DELETE_BINS | xargs rm -f; ) |
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 | # No need for recovery |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 73 | rm -rf $REPACK/ota/recovery |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 74 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 75 | # Strip modules |
Pat Thoyts | 8ed18b5 | 2011-08-03 16:14:31 +0100 | [diff] [blame] | 76 | [ -d $REPACK/ota/system/lib/modules ] && \ |
| 77 | 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] | 78 | |
| 79 | # Determine what to name the new signed package |
Warren Togami | 2128e2f | 2012-05-06 19:49:33 -1000 | [diff] [blame] | 80 | MODVERSION=`sed -n -e'/ro\.cm\.version/s/^.*=//p' $REPACK/ota/system/build.prop` |
| 81 | OUTFILE=$OUT/cm-$MODVERSION.zip |
| 82 | echo MODVERSION: $MODVERSION |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 83 | |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 84 | # Pack it up and sign |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 85 | printf "Zipping package..." |
| 86 | ( cd $REPACK/ota; zip $QUIET -r $REPACK/update.zip . ) |
| 87 | echo |
| 88 | printf "Signing package..." |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 89 | SECURITYDIR=$ANDROID_BUILD_TOP/build/target/product/security |
Pavel Valenta | 1af866c | 2012-04-18 01:06:51 +0800 | [diff] [blame] | 90 | java -Xmx1024m \ |
Chirayu Desai | c10f6d5 | 2012-08-11 16:34:32 +0530 | [diff] [blame^] | 91 | -jar $OUT/../../../host/$OUT_TARGET_HOST/framework/signapk.jar \ |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 92 | -w $SECURITYDIR/testkey.x509.pem $SECURITYDIR/testkey.pk8 \ |
| 93 | $REPACK/update.zip $OUTFILE |
| 94 | echo |
| 95 | printf "Cleaning up..." |
| 96 | rm -rf $REPACK |
| 97 | echo |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 98 | |
Chris Cosby | 2d0feb5 | 2010-07-16 16:28:46 -0400 | [diff] [blame] | 99 | # Create a md5 checksum image of the repacked package |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 100 | ( |
| 101 | img=`basename $OUTFILE` |
| 102 | cd `dirname $OUTFILE` |
| 103 | $MD5 $img >$img.md5sum |
| 104 | echo |
| 105 | echo "Package complete: $OUTFILE" |
| 106 | cat $img.md5sum |
| 107 | echo |
| 108 | ) |
Steve Kondik | ae76c84 | 2010-06-28 11:47:26 -0400 | [diff] [blame] | 109 | |
Chris Cosby | 972e003 | 2010-07-16 11:13:35 -0400 | [diff] [blame] | 110 | exit 0 |