blob: 54498f28ba96a8c05dfbbcf29a81855717596542 [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
Chris Cosby972e0032010-07-16 11:13:35 -040026if [ ! -f "$OTAPACKAGE" ]; then
27 echo "$OTAPACKAGE doesn't exist!";
28 exit 1
29fi
30
Ricardo Cerqueirae1f37382011-11-27 19:56:54 +000031OPTICHARGER=$ANDROID_BUILD_TOP/vendor/cm/tools/opticharger
Pat Thoyts304457f2010-07-11 02:42:36 -040032QUIET=-q
Steve Kondikae76c842010-06-28 11:47:26 -040033DELETE_BINS="applypatch applypatch_static check_prereq recovery updater"
Chris Cosby972e0032010-07-16 11:13:35 -040034
Chris Cosby972e0032010-07-16 11:13:35 -040035REPACK=$OUT/repack.d
Chris Cosby972e0032010-07-16 11:13:35 -040036printf "Sanitizing environment..."
37rm -rf $REPACK
38mkdir -p $REPACK
39echo
Steve Kondikae76c842010-06-28 11:47:26 -040040
Steve Kondikae76c842010-06-28 11:47:26 -040041
42# Unpack the otapackage and opticharge all apks
Chris Cosby972e0032010-07-16 11:13:35 -040043mkdir $REPACK/ota
44(
45cd $REPACK/ota
46printf "Unpacking $OTAPACKAGE..."
Pat Thoyts304457f2010-07-11 02:42:36 -040047unzip $QUIET $OTAPACKAGE
Chris Cosby972e0032010-07-16 11:13:35 -040048echo
Jorge Ruesga547bd462012-08-12 20:42:54 +020049
50# Move all apks to the same directory so xargs can
51# use also with framework-res.apk. This allow process
52# framework-res.apk in parallel with other apks
53mkdir -p $REPACK/parallel
54cd $REPACK/parallel
55cp $REPACK/ota/system/framework/framework-res.apk .
56cp $REPACK/ota/system/app/*.apk .
57
58# Do optimization in parallel
Takuo Kitame9db76662010-10-29 09:55:59 +090059find ./ -name \*.apk | $XARGS $OPTICHARGER
Jorge Ruesga547bd462012-08-12 20:42:54 +020060
61# Move optimized apks to repack directory
62mv -f $REPACK/parallel/framework-res.apk $REPACK/ota/system/framework/framework-res.apk
63mv -f $REPACK/parallel/*.apk $REPACK/ota/system/app/
64
65# Return to directory
66cd $REPACK/ota
67rm -rf $REPACK/parallel
Chris Cosby972e0032010-07-16 11:13:35 -040068)
Steve Kondikae76c842010-06-28 11:47:26 -040069
Steve Kondikae76c842010-06-28 11:47:26 -040070# Fix build.prop
Takuo Kitame9db76662010-10-29 09:55:59 +090071$SED -i \
Chris Cosby972e0032010-07-16 11:13:35 -040072 -e '/ro\.kernel\.android\.checkjni/d' \
73 -e '/ro\.build\.type/s/eng/user/' \
Chris Cosby2d0feb52010-07-16 16:28:46 -040074 $REPACK/ota/system/build.prop
Chris Cosby972e0032010-07-16 11:13:35 -040075
Steve Kondikae76c842010-06-28 11:47:26 -040076
77# Delete unnecessary binaries
Chris Cosby2d0feb52010-07-16 16:28:46 -040078( cd $REPACK/ota/system/bin; echo $DELETE_BINS | xargs rm -f; )
Steve Kondikae76c842010-06-28 11:47:26 -040079
Steve Kondikae76c842010-06-28 11:47:26 -040080# No need for recovery
Chris Cosby972e0032010-07-16 11:13:35 -040081rm -rf $REPACK/ota/recovery
Steve Kondikae76c842010-06-28 11:47:26 -040082
Chris Cosby972e0032010-07-16 11:13:35 -040083# Strip modules
Pat Thoyts8ed18b52011-08-03 16:14:31 +010084[ -d $REPACK/ota/system/lib/modules ] && \
85 find $REPACK/ota/system/lib/modules -name "*.ko" -print0 | xargs -0 arm-eabi-strip --strip-unneeded
Chris Cosby972e0032010-07-16 11:13:35 -040086
87# Determine what to name the new signed package
Warren Togami2128e2f2012-05-06 19:49:33 -100088MODVERSION=`sed -n -e'/ro\.cm\.version/s/^.*=//p' $REPACK/ota/system/build.prop`
89OUTFILE=$OUT/cm-$MODVERSION.zip
90echo MODVERSION: $MODVERSION
Steve Kondikae76c842010-06-28 11:47:26 -040091
Steve Kondikae76c842010-06-28 11:47:26 -040092# Pack it up and sign
Chris Cosby972e0032010-07-16 11:13:35 -040093printf "Zipping package..."
94( cd $REPACK/ota; zip $QUIET -r $REPACK/update.zip . )
95echo
96printf "Signing package..."
Steve Kondikae76c842010-06-28 11:47:26 -040097SECURITYDIR=$ANDROID_BUILD_TOP/build/target/product/security
Pavel Valenta1af866c2012-04-18 01:06:51 +080098java -Xmx1024m \
Chirayu Desaic10f6d52012-08-11 16:34:32 +053099 -jar $OUT/../../../host/$OUT_TARGET_HOST/framework/signapk.jar \
Chris Cosby972e0032010-07-16 11:13:35 -0400100 -w $SECURITYDIR/testkey.x509.pem $SECURITYDIR/testkey.pk8 \
101 $REPACK/update.zip $OUTFILE
102echo
103printf "Cleaning up..."
104rm -rf $REPACK
105echo
Steve Kondikae76c842010-06-28 11:47:26 -0400106
Chris Cosby2d0feb52010-07-16 16:28:46 -0400107# Create a md5 checksum image of the repacked package
Chris Cosby972e0032010-07-16 11:13:35 -0400108(
109img=`basename $OUTFILE`
110cd `dirname $OUTFILE`
111$MD5 $img >$img.md5sum
112echo
113echo "Package complete: $OUTFILE"
114cat $img.md5sum
115echo
116)
Steve Kondikae76c842010-06-28 11:47:26 -0400117
Chris Cosby972e0032010-07-16 11:13:35 -0400118exit 0