blob: b208ed254a7153cf06c9ddda9fd40b46e8183f2e [file] [log] [blame]
Chirayu Desai39cb8782012-10-13 16:10:45 +05301#!/bin/bash
Steve Kondikae76c842010-06-28 11:47:26 -04002#
3# Squish a CM otapackage for distribution
4# cyanogen
5#
6
Chirayu Desai39cb8782012-10-13 16:10:45 +05307. $ANDROID_BUILD_TOP/vendor/cm/tools/functions
8
Chris Cosby2d0feb52010-07-16 16:28:46 -04009OUT_TARGET_HOST=`uname -a | grep Darwin`
Steve Kondikae76c842010-06-28 11:47:26 -040010if [ -z "$OUT_TARGET_HOST" ]
11then
12 OUT_TARGET_HOST=linux-x86
13 MD5=md5sum
Takuo Kitame9db76662010-10-29 09:55:59 +090014 XARGS="xargs --max-args=1 --max-procs `grep 'processor' /proc/cpuinfo|wc -l`"
15 SED=sed
Steve Kondikae76c842010-06-28 11:47:26 -040016else
17 OUT_TARGET_HOST=darwin-x86
18 MD5=md5
Takuo Kitame9db76662010-10-29 09:55:59 +090019 XARGS="xargs -n 1 -P `sysctl hw.ncpu | awk '{print $2}'`"
20 SED=gsed
Steve Kondikae76c842010-06-28 11:47:26 -040021fi
22
Chris Cosby972e0032010-07-16 11:13:35 -040023if [ -z "$OUT" -o ! -d "$OUT" ]; then
Chirayu Desai39cb8782012-10-13 16:10:45 +053024 echo -e $CL_RED"ERROR: $0 only works with a full build environment. $OUT should exist."$CL_RST
Chris Cosby972e0032010-07-16 11:13:35 -040025 exit 1
Steve Kondikae76c842010-06-28 11:47:26 -040026fi
27
Chris Cosby972e0032010-07-16 11:13:35 -040028if [ ! -f "$OTAPACKAGE" ]; then
Chirayu Desai39cb8782012-10-13 16:10:45 +053029 echo -e $CL_RED"$OTAPACKAGE doesn't exist!"$CL_RST;
Chris Cosby972e0032010-07-16 11:13:35 -040030 exit 1
31fi
32
Ricardo Cerqueirae1f37382011-11-27 19:56:54 +000033OPTICHARGER=$ANDROID_BUILD_TOP/vendor/cm/tools/opticharger
Pat Thoyts304457f2010-07-11 02:42:36 -040034QUIET=-q
Steve Kondikae76c842010-06-28 11:47:26 -040035DELETE_BINS="applypatch applypatch_static check_prereq recovery updater"
Chris Cosby972e0032010-07-16 11:13:35 -040036
Chris Cosby972e0032010-07-16 11:13:35 -040037REPACK=$OUT/repack.d
Chris Cosby972e0032010-07-16 11:13:35 -040038printf "Sanitizing environment..."
39rm -rf $REPACK
40mkdir -p $REPACK
41echo
Steve Kondikae76c842010-06-28 11:47:26 -040042
Steve Kondikae76c842010-06-28 11:47:26 -040043
44# Unpack the otapackage and opticharge all apks
Chris Cosby972e0032010-07-16 11:13:35 -040045mkdir $REPACK/ota
46(
47cd $REPACK/ota
48printf "Unpacking $OTAPACKAGE..."
Pat Thoyts304457f2010-07-11 02:42:36 -040049unzip $QUIET $OTAPACKAGE
Chris Cosby972e0032010-07-16 11:13:35 -040050echo
Jorge Ruesga547bd462012-08-12 20:42:54 +020051
52# Move all apks to the same directory so xargs can
53# use also with framework-res.apk. This allow process
54# framework-res.apk in parallel with other apks
55mkdir -p $REPACK/parallel
56cd $REPACK/parallel
57cp $REPACK/ota/system/framework/framework-res.apk .
58cp $REPACK/ota/system/app/*.apk .
59
60# Do optimization in parallel
Takuo Kitame9db76662010-10-29 09:55:59 +090061find ./ -name \*.apk | $XARGS $OPTICHARGER
Jorge Ruesga547bd462012-08-12 20:42:54 +020062
63# Move optimized apks to repack directory
64mv -f $REPACK/parallel/framework-res.apk $REPACK/ota/system/framework/framework-res.apk
65mv -f $REPACK/parallel/*.apk $REPACK/ota/system/app/
66
67# Return to directory
68cd $REPACK/ota
69rm -rf $REPACK/parallel
Chris Cosby972e0032010-07-16 11:13:35 -040070)
Steve Kondikae76c842010-06-28 11:47:26 -040071
Steve Kondikae76c842010-06-28 11:47:26 -040072# Fix build.prop
Takuo Kitame9db76662010-10-29 09:55:59 +090073$SED -i \
Chris Cosby972e0032010-07-16 11:13:35 -040074 -e '/ro\.kernel\.android\.checkjni/d' \
75 -e '/ro\.build\.type/s/eng/user/' \
Chris Cosby2d0feb52010-07-16 16:28:46 -040076 $REPACK/ota/system/build.prop
Chris Cosby972e0032010-07-16 11:13:35 -040077
Steve Kondikae76c842010-06-28 11:47:26 -040078
79# Delete unnecessary binaries
Chris Cosby2d0feb52010-07-16 16:28:46 -040080( cd $REPACK/ota/system/bin; echo $DELETE_BINS | xargs rm -f; )
Steve Kondikae76c842010-06-28 11:47:26 -040081
Steve Kondikae76c842010-06-28 11:47:26 -040082# No need for recovery
Chris Cosby972e0032010-07-16 11:13:35 -040083rm -rf $REPACK/ota/recovery
Steve Kondikae76c842010-06-28 11:47:26 -040084
Chris Cosby972e0032010-07-16 11:13:35 -040085# Strip modules
Pat Thoyts8ed18b52011-08-03 16:14:31 +010086[ -d $REPACK/ota/system/lib/modules ] && \
87 find $REPACK/ota/system/lib/modules -name "*.ko" -print0 | xargs -0 arm-eabi-strip --strip-unneeded
Chris Cosby972e0032010-07-16 11:13:35 -040088
89# Determine what to name the new signed package
Warren Togami2128e2f2012-05-06 19:49:33 -100090MODVERSION=`sed -n -e'/ro\.cm\.version/s/^.*=//p' $REPACK/ota/system/build.prop`
91OUTFILE=$OUT/cm-$MODVERSION.zip
Chirayu Desai39cb8782012-10-13 16:10:45 +053092echo -e $CL_CYN"MODVERSION: $MODVERSION"$CL_RST
Steve Kondikae76c842010-06-28 11:47:26 -040093
Steve Kondikae76c842010-06-28 11:47:26 -040094# Pack it up and sign
Chris Cosby972e0032010-07-16 11:13:35 -040095printf "Zipping package..."
96( cd $REPACK/ota; zip $QUIET -r $REPACK/update.zip . )
97echo
98printf "Signing package..."
Steve Kondikae76c842010-06-28 11:47:26 -040099SECURITYDIR=$ANDROID_BUILD_TOP/build/target/product/security
Pavel Valenta1af866c2012-04-18 01:06:51 +0800100java -Xmx1024m \
Chirayu Desaic10f6d52012-08-11 16:34:32 +0530101 -jar $OUT/../../../host/$OUT_TARGET_HOST/framework/signapk.jar \
Chris Cosby972e0032010-07-16 11:13:35 -0400102 -w $SECURITYDIR/testkey.x509.pem $SECURITYDIR/testkey.pk8 \
103 $REPACK/update.zip $OUTFILE
104echo
105printf "Cleaning up..."
106rm -rf $REPACK
107echo
Steve Kondikae76c842010-06-28 11:47:26 -0400108
Chris Cosby2d0feb52010-07-16 16:28:46 -0400109# Create a md5 checksum image of the repacked package
Chris Cosby972e0032010-07-16 11:13:35 -0400110(
111img=`basename $OUTFILE`
112cd `dirname $OUTFILE`
113$MD5 $img >$img.md5sum
114echo
Chirayu Desai39cb8782012-10-13 16:10:45 +0530115echo -e $CL_GRN"Package complete: $OUTFILE"$CL_RST
Chris Cosby972e0032010-07-16 11:13:35 -0400116cat $img.md5sum
117echo
118)
Steve Kondikae76c842010-06-28 11:47:26 -0400119
Chris Cosby972e0032010-07-16 11:13:35 -0400120exit 0