blob: 552929ffc887067db58d5789cdb7b6b41418d48d [file] [log] [blame]
Steve Kondikae76c842010-06-28 11:47:26 -04001#!/bin/sh
2#
3# Squish a CM otapackage for distribution
4# cyanogen
5#
6
Chris Cosby2d0feb52010-07-16 16:28:46 -04007OUT_TARGET_HOST=`uname -a | grep Darwin`
Steve Kondikae76c842010-06-28 11:47:26 -04008if [ -z "$OUT_TARGET_HOST" ]
9then
10 OUT_TARGET_HOST=linux-x86
11 MD5=md5sum
Takuo Kitame9db76662010-10-29 09:55:59 +090012 XARGS="xargs --max-args=1 --max-procs `grep 'processor' /proc/cpuinfo|wc -l`"
13 SED=sed
Steve Kondikae76c842010-06-28 11:47:26 -040014else
15 OUT_TARGET_HOST=darwin-x86
16 MD5=md5
Takuo Kitame9db76662010-10-29 09:55:59 +090017 XARGS="xargs -n 1 -P `sysctl hw.ncpu | awk '{print $2}'`"
18 SED=gsed
Steve Kondikae76c842010-06-28 11:47:26 -040019fi
20
Chris Cosby972e0032010-07-16 11:13:35 -040021if [ -z "$OUT" -o ! -d "$OUT" ]; then
22 echo "ERROR: $0 only works with a full build environment. $OUT should exist."
23 exit 1
Steve Kondikae76c842010-06-28 11:47:26 -040024fi
25
David Kohen61848e42011-02-06 20:29:33 +020026if [ "$TARGET_BUILD_TYPE" = "debug" ]; then
Ladios Jonquil1f765132011-09-25 02:11:08 +080027 OTAPACKAGE=$OUT/${TARGET_PRODUCT}_debug-ota-$TARGET_BUILD_VARIANT.$USER.zip
Ricardo Cerqueirae1f37382011-11-27 19:56:54 +000028elif [ "$TARGET_BUILD_VARIANT" = "userdebug" ]; then
29 OTAPACKAGE=$OUT/$TARGET_PRODUCT-ota-eng.$USER.zip
David Kohen61848e42011-02-06 20:29:33 +020030else
Ladios Jonquil1f765132011-09-25 02:11:08 +080031 OTAPACKAGE=$OUT/$TARGET_PRODUCT-ota-$TARGET_BUILD_VARIANT.$USER.zip
David Kohen61848e42011-02-06 20:29:33 +020032fi
Chris Cosby972e0032010-07-16 11:13:35 -040033if [ ! -f "$OTAPACKAGE" ]; then
34 echo "$OTAPACKAGE doesn't exist!";
35 exit 1
36fi
37
Ricardo Cerqueirae1f37382011-11-27 19:56:54 +000038OPTICHARGER=$ANDROID_BUILD_TOP/vendor/cm/tools/opticharger
Pat Thoyts304457f2010-07-11 02:42:36 -040039QUIET=-q
Steve Kondikae76c842010-06-28 11:47:26 -040040DELETE_BINS="applypatch applypatch_static check_prereq recovery updater"
Chris Cosby972e0032010-07-16 11:13:35 -040041
Chris Cosby972e0032010-07-16 11:13:35 -040042REPACK=$OUT/repack.d
Chris Cosby972e0032010-07-16 11:13:35 -040043printf "Sanitizing environment..."
44rm -rf $REPACK
45mkdir -p $REPACK
46echo
Steve Kondikae76c842010-06-28 11:47:26 -040047
Steve Kondikae76c842010-06-28 11:47:26 -040048
49# Unpack the otapackage and opticharge all apks
Chris Cosby972e0032010-07-16 11:13:35 -040050mkdir $REPACK/ota
51(
52cd $REPACK/ota
53printf "Unpacking $OTAPACKAGE..."
Pat Thoyts304457f2010-07-11 02:42:36 -040054unzip $QUIET $OTAPACKAGE
Chris Cosby972e0032010-07-16 11:13:35 -040055echo
56cd $REPACK/ota/system/framework
Steve Kondikae76c842010-06-28 11:47:26 -040057$OPTICHARGER framework-res.apk
Chris Cosby972e0032010-07-16 11:13:35 -040058cd $REPACK/ota/system/app
Takuo Kitame9db76662010-10-29 09:55:59 +090059find ./ -name \*.apk | $XARGS $OPTICHARGER
Chris Cosby972e0032010-07-16 11:13:35 -040060)
Steve Kondikae76c842010-06-28 11:47:26 -040061
Steve Kondikae76c842010-06-28 11:47:26 -040062# Fix build.prop
Takuo Kitame9db76662010-10-29 09:55:59 +090063$SED -i \
Chris Cosby972e0032010-07-16 11:13:35 -040064 -e '/ro\.kernel\.android\.checkjni/d' \
65 -e '/ro\.build\.type/s/eng/user/' \
Chris Cosby2d0feb52010-07-16 16:28:46 -040066 $REPACK/ota/system/build.prop
Chris Cosby972e0032010-07-16 11:13:35 -040067
Steve Kondikae76c842010-06-28 11:47:26 -040068
69# Delete unnecessary binaries
Chris Cosby2d0feb52010-07-16 16:28:46 -040070( cd $REPACK/ota/system/bin; echo $DELETE_BINS | xargs rm -f; )
Steve Kondikae76c842010-06-28 11:47:26 -040071
Steve Kondikae76c842010-06-28 11:47:26 -040072# No need for recovery
Chris Cosby972e0032010-07-16 11:13:35 -040073rm -rf $REPACK/ota/recovery
Steve Kondikae76c842010-06-28 11:47:26 -040074
Chris Cosby972e0032010-07-16 11:13:35 -040075# Strip modules
Pat Thoyts8ed18b52011-08-03 16:14:31 +010076[ -d $REPACK/ota/system/lib/modules ] && \
77 find $REPACK/ota/system/lib/modules -name "*.ko" -print0 | xargs -0 arm-eabi-strip --strip-unneeded
Chris Cosby972e0032010-07-16 11:13:35 -040078
79# Determine what to name the new signed package
Warren Togami2128e2f2012-05-06 19:49:33 -100080MODVERSION=`sed -n -e'/ro\.cm\.version/s/^.*=//p' $REPACK/ota/system/build.prop`
81OUTFILE=$OUT/cm-$MODVERSION.zip
82echo MODVERSION: $MODVERSION
Steve Kondikae76c842010-06-28 11:47:26 -040083
Steve Kondikae76c842010-06-28 11:47:26 -040084# Pack it up and sign
Chris Cosby972e0032010-07-16 11:13:35 -040085printf "Zipping package..."
86( cd $REPACK/ota; zip $QUIET -r $REPACK/update.zip . )
87echo
88printf "Signing package..."
Steve Kondikae76c842010-06-28 11:47:26 -040089SECURITYDIR=$ANDROID_BUILD_TOP/build/target/product/security
Pavel Valenta1af866c2012-04-18 01:06:51 +080090java -Xmx1024m \
Chris Cosby972e0032010-07-16 11:13:35 -040091 -jar $ANDROID_BUILD_TOP/out/host/$OUT_TARGET_HOST/framework/signapk.jar \
92 -w $SECURITYDIR/testkey.x509.pem $SECURITYDIR/testkey.pk8 \
93 $REPACK/update.zip $OUTFILE
94echo
95printf "Cleaning up..."
96rm -rf $REPACK
97echo
Steve Kondikae76c842010-06-28 11:47:26 -040098
Chris Cosby2d0feb52010-07-16 16:28:46 -040099# Create a md5 checksum image of the repacked package
Chris Cosby972e0032010-07-16 11:13:35 -0400100(
101img=`basename $OUTFILE`
102cd `dirname $OUTFILE`
103$MD5 $img >$img.md5sum
104echo
105echo "Package complete: $OUTFILE"
106cat $img.md5sum
107echo
108)
Steve Kondikae76c842010-06-28 11:47:26 -0400109
Chris Cosby972e0032010-07-16 11:13:35 -0400110exit 0