blob: 250a248dcc1bde349cf0c6517d3184505961920d [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
Jorge Ruesga547bd462012-08-12 20:42:54 +020056
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
60mkdir -p $REPACK/parallel
61cd $REPACK/parallel
62cp $REPACK/ota/system/framework/framework-res.apk .
63cp $REPACK/ota/system/app/*.apk .
64
65# Do optimization in parallel
Takuo Kitame9db76662010-10-29 09:55:59 +090066find ./ -name \*.apk | $XARGS $OPTICHARGER
Jorge Ruesga547bd462012-08-12 20:42:54 +020067
68# Move optimized apks to repack directory
69mv -f $REPACK/parallel/framework-res.apk $REPACK/ota/system/framework/framework-res.apk
70mv -f $REPACK/parallel/*.apk $REPACK/ota/system/app/
71
72# Return to directory
73cd $REPACK/ota
74rm -rf $REPACK/parallel
Chris Cosby972e0032010-07-16 11:13:35 -040075)
Steve Kondikae76c842010-06-28 11:47:26 -040076
Steve Kondikae76c842010-06-28 11:47:26 -040077# Fix build.prop
Takuo Kitame9db76662010-10-29 09:55:59 +090078$SED -i \
Chris Cosby972e0032010-07-16 11:13:35 -040079 -e '/ro\.kernel\.android\.checkjni/d' \
80 -e '/ro\.build\.type/s/eng/user/' \
Chris Cosby2d0feb52010-07-16 16:28:46 -040081 $REPACK/ota/system/build.prop
Chris Cosby972e0032010-07-16 11:13:35 -040082
Steve Kondikae76c842010-06-28 11:47:26 -040083
84# Delete unnecessary binaries
Chris Cosby2d0feb52010-07-16 16:28:46 -040085( cd $REPACK/ota/system/bin; echo $DELETE_BINS | xargs rm -f; )
Steve Kondikae76c842010-06-28 11:47:26 -040086
Steve Kondikae76c842010-06-28 11:47:26 -040087# No need for recovery
Chris Cosby972e0032010-07-16 11:13:35 -040088rm -rf $REPACK/ota/recovery
Steve Kondikae76c842010-06-28 11:47:26 -040089
Chris Cosby972e0032010-07-16 11:13:35 -040090# Strip modules
Pat Thoyts8ed18b52011-08-03 16:14:31 +010091[ -d $REPACK/ota/system/lib/modules ] && \
92 find $REPACK/ota/system/lib/modules -name "*.ko" -print0 | xargs -0 arm-eabi-strip --strip-unneeded
Chris Cosby972e0032010-07-16 11:13:35 -040093
94# Determine what to name the new signed package
Warren Togami2128e2f2012-05-06 19:49:33 -100095MODVERSION=`sed -n -e'/ro\.cm\.version/s/^.*=//p' $REPACK/ota/system/build.prop`
96OUTFILE=$OUT/cm-$MODVERSION.zip
97echo MODVERSION: $MODVERSION
Steve Kondikae76c842010-06-28 11:47:26 -040098
Steve Kondikae76c842010-06-28 11:47:26 -040099# Pack it up and sign
Chris Cosby972e0032010-07-16 11:13:35 -0400100printf "Zipping package..."
101( cd $REPACK/ota; zip $QUIET -r $REPACK/update.zip . )
102echo
103printf "Signing package..."
Steve Kondikae76c842010-06-28 11:47:26 -0400104SECURITYDIR=$ANDROID_BUILD_TOP/build/target/product/security
Pavel Valenta1af866c2012-04-18 01:06:51 +0800105java -Xmx1024m \
Chirayu Desaic10f6d52012-08-11 16:34:32 +0530106 -jar $OUT/../../../host/$OUT_TARGET_HOST/framework/signapk.jar \
Chris Cosby972e0032010-07-16 11:13:35 -0400107 -w $SECURITYDIR/testkey.x509.pem $SECURITYDIR/testkey.pk8 \
108 $REPACK/update.zip $OUTFILE
109echo
110printf "Cleaning up..."
111rm -rf $REPACK
112echo
Steve Kondikae76c842010-06-28 11:47:26 -0400113
Chris Cosby2d0feb52010-07-16 16:28:46 -0400114# Create a md5 checksum image of the repacked package
Chris Cosby972e0032010-07-16 11:13:35 -0400115(
116img=`basename $OUTFILE`
117cd `dirname $OUTFILE`
118$MD5 $img >$img.md5sum
119echo
120echo "Package complete: $OUTFILE"
121cat $img.md5sum
122echo
123)
Steve Kondikae76c842010-06-28 11:47:26 -0400124
Chris Cosby972e0032010-07-16 11:13:35 -0400125exit 0