blob: ce94537e855476b5d7ec5740a000a8ec6e868aeb [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
Erez A. Korn8e8a6782012-08-12 08:33:59 +030030elif [ "$TARGET_BUILD_VARIANT" = "user" ]; then
31 OTAPACKAGE=$OUT/$TARGET_PRODUCT-ota-eng.$USER.zip
David Kohen61848e42011-02-06 20:29:33 +020032else
Ladios Jonquil1f765132011-09-25 02:11:08 +080033 OTAPACKAGE=$OUT/$TARGET_PRODUCT-ota-$TARGET_BUILD_VARIANT.$USER.zip
David Kohen61848e42011-02-06 20:29:33 +020034fi
Chris Cosby972e0032010-07-16 11:13:35 -040035if [ ! -f "$OTAPACKAGE" ]; then
36 echo "$OTAPACKAGE doesn't exist!";
37 exit 1
38fi
39
Ricardo Cerqueirae1f37382011-11-27 19:56:54 +000040OPTICHARGER=$ANDROID_BUILD_TOP/vendor/cm/tools/opticharger
Pat Thoyts304457f2010-07-11 02:42:36 -040041QUIET=-q
Steve Kondikae76c842010-06-28 11:47:26 -040042DELETE_BINS="applypatch applypatch_static check_prereq recovery updater"
Chris Cosby972e0032010-07-16 11:13:35 -040043
Chris Cosby972e0032010-07-16 11:13:35 -040044REPACK=$OUT/repack.d
Chris Cosby972e0032010-07-16 11:13:35 -040045printf "Sanitizing environment..."
46rm -rf $REPACK
47mkdir -p $REPACK
48echo
Steve Kondikae76c842010-06-28 11:47:26 -040049
Steve Kondikae76c842010-06-28 11:47:26 -040050
51# Unpack the otapackage and opticharge all apks
Chris Cosby972e0032010-07-16 11:13:35 -040052mkdir $REPACK/ota
53(
54cd $REPACK/ota
55printf "Unpacking $OTAPACKAGE..."
Pat Thoyts304457f2010-07-11 02:42:36 -040056unzip $QUIET $OTAPACKAGE
Chris Cosby972e0032010-07-16 11:13:35 -040057echo
Jorge Ruesga547bd462012-08-12 20:42:54 +020058
59# Move all apks to the same directory so xargs can
60# use also with framework-res.apk. This allow process
61# framework-res.apk in parallel with other apks
62mkdir -p $REPACK/parallel
63cd $REPACK/parallel
64cp $REPACK/ota/system/framework/framework-res.apk .
65cp $REPACK/ota/system/app/*.apk .
66
67# Do optimization in parallel
Takuo Kitame9db76662010-10-29 09:55:59 +090068find ./ -name \*.apk | $XARGS $OPTICHARGER
Jorge Ruesga547bd462012-08-12 20:42:54 +020069
70# Move optimized apks to repack directory
71mv -f $REPACK/parallel/framework-res.apk $REPACK/ota/system/framework/framework-res.apk
72mv -f $REPACK/parallel/*.apk $REPACK/ota/system/app/
73
74# Return to directory
75cd $REPACK/ota
76rm -rf $REPACK/parallel
Chris Cosby972e0032010-07-16 11:13:35 -040077)
Steve Kondikae76c842010-06-28 11:47:26 -040078
Steve Kondikae76c842010-06-28 11:47:26 -040079# Fix build.prop
Takuo Kitame9db76662010-10-29 09:55:59 +090080$SED -i \
Chris Cosby972e0032010-07-16 11:13:35 -040081 -e '/ro\.kernel\.android\.checkjni/d' \
82 -e '/ro\.build\.type/s/eng/user/' \
Chris Cosby2d0feb52010-07-16 16:28:46 -040083 $REPACK/ota/system/build.prop
Chris Cosby972e0032010-07-16 11:13:35 -040084
Steve Kondikae76c842010-06-28 11:47:26 -040085
86# Delete unnecessary binaries
Chris Cosby2d0feb52010-07-16 16:28:46 -040087( cd $REPACK/ota/system/bin; echo $DELETE_BINS | xargs rm -f; )
Steve Kondikae76c842010-06-28 11:47:26 -040088
Steve Kondikae76c842010-06-28 11:47:26 -040089# No need for recovery
Chris Cosby972e0032010-07-16 11:13:35 -040090rm -rf $REPACK/ota/recovery
Steve Kondikae76c842010-06-28 11:47:26 -040091
Chris Cosby972e0032010-07-16 11:13:35 -040092# Strip modules
Pat Thoyts8ed18b52011-08-03 16:14:31 +010093[ -d $REPACK/ota/system/lib/modules ] && \
94 find $REPACK/ota/system/lib/modules -name "*.ko" -print0 | xargs -0 arm-eabi-strip --strip-unneeded
Chris Cosby972e0032010-07-16 11:13:35 -040095
96# Determine what to name the new signed package
Warren Togami2128e2f2012-05-06 19:49:33 -100097MODVERSION=`sed -n -e'/ro\.cm\.version/s/^.*=//p' $REPACK/ota/system/build.prop`
98OUTFILE=$OUT/cm-$MODVERSION.zip
99echo MODVERSION: $MODVERSION
Steve Kondikae76c842010-06-28 11:47:26 -0400100
Steve Kondikae76c842010-06-28 11:47:26 -0400101# Pack it up and sign
Chris Cosby972e0032010-07-16 11:13:35 -0400102printf "Zipping package..."
103( cd $REPACK/ota; zip $QUIET -r $REPACK/update.zip . )
104echo
105printf "Signing package..."
Steve Kondikae76c842010-06-28 11:47:26 -0400106SECURITYDIR=$ANDROID_BUILD_TOP/build/target/product/security
Pavel Valenta1af866c2012-04-18 01:06:51 +0800107java -Xmx1024m \
Chirayu Desaic10f6d52012-08-11 16:34:32 +0530108 -jar $OUT/../../../host/$OUT_TARGET_HOST/framework/signapk.jar \
Chris Cosby972e0032010-07-16 11:13:35 -0400109 -w $SECURITYDIR/testkey.x509.pem $SECURITYDIR/testkey.pk8 \
110 $REPACK/update.zip $OUTFILE
111echo
112printf "Cleaning up..."
113rm -rf $REPACK
114echo
Steve Kondikae76c842010-06-28 11:47:26 -0400115
Chris Cosby2d0feb52010-07-16 16:28:46 -0400116# Create a md5 checksum image of the repacked package
Chris Cosby972e0032010-07-16 11:13:35 -0400117(
118img=`basename $OUTFILE`
119cd `dirname $OUTFILE`
120$MD5 $img >$img.md5sum
121echo
122echo "Package complete: $OUTFILE"
123cat $img.md5sum
124echo
125)
Steve Kondikae76c842010-06-28 11:47:26 -0400126
Chris Cosby972e0032010-07-16 11:13:35 -0400127exit 0