You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

121 lines
2.9 KiB

#!/bin/bash
#
# Squish a CM otapackage for distribution
# cyanogen
#
. $ANDROID_BUILD_TOP/vendor/cm/tools/functions
OUT_TARGET_HOST=`uname -a | grep Darwin`
if [ -z "$OUT_TARGET_HOST" ]
then
OUT_TARGET_HOST=linux-x86
MD5=md5sum
XARGS="xargs --max-args=1 --max-procs `grep 'processor' /proc/cpuinfo|wc -l`"
SED=sed
else
OUT_TARGET_HOST=darwin-x86
MD5=md5
XARGS="xargs -n 1 -P `sysctl hw.ncpu | awk '{print $2}'`"
SED=gsed
fi
if [ -z "$OUT" -o ! -d "$OUT" ]; then
echo -e $CL_RED"ERROR: $0 only works with a full build environment. $OUT should exist."$CL_RST
exit 1
fi
if [ ! -f "$OTAPACKAGE" ]; then
echo -e $CL_RED"$OTAPACKAGE doesn't exist!"$CL_RST;
exit 1
fi
OPTICHARGER=$ANDROID_BUILD_TOP/vendor/cm/tools/opticharger
QUIET=-q
DELETE_BINS="applypatch applypatch_static check_prereq recovery updater"
REPACK=$OUT/repack.d
printf "Sanitizing environment..."
rm -rf $REPACK
mkdir -p $REPACK
echo
# Unpack the otapackage and opticharge all apks
mkdir $REPACK/ota
(
cd $REPACK/ota
printf "Unpacking $OTAPACKAGE..."
unzip $QUIET $OTAPACKAGE
echo
# Move all apks to the same directory so xargs can
# use also with framework-res.apk. This allow process
# framework-res.apk in parallel with other apks
mkdir -p $REPACK/parallel
cd $REPACK/parallel
cp $REPACK/ota/system/framework/framework-res.apk .
cp $REPACK/ota/system/app/*.apk .
# Do optimization in parallel
find ./ -name \*.apk | $XARGS $OPTICHARGER
# Move optimized apks to repack directory
mv -f $REPACK/parallel/framework-res.apk $REPACK/ota/system/framework/framework-res.apk
mv -f $REPACK/parallel/*.apk $REPACK/ota/system/app/
# Return to directory
cd $REPACK/ota
rm -rf $REPACK/parallel
)
# Fix build.prop
$SED -i \
-e '/ro\.kernel\.android\.checkjni/d' \
-e '/ro\.build\.type/s/eng/user/' \
$REPACK/ota/system/build.prop
# Delete unnecessary binaries
( cd $REPACK/ota/system/bin; echo $DELETE_BINS | xargs rm -f; )
# No need for recovery
rm -rf $REPACK/ota/recovery
# Strip modules
[ -d $REPACK/ota/system/lib/modules ] && \
find $REPACK/ota/system/lib/modules -name "*.ko" -print0 | xargs -0 arm-eabi-strip --strip-unneeded
# Determine what to name the new signed package
MODVERSION=`sed -n -e'/ro\.cm\.version/s/^.*=//p' $REPACK/ota/system/build.prop`
OUTFILE=$OUT/cm-$MODVERSION.zip
echo -e $CL_CYN"MODVERSION: $MODVERSION"$CL_RST
# Pack it up and sign
printf "Zipping package..."
( cd $REPACK/ota; zip $QUIET -r $REPACK/update.zip . )
echo
printf "Signing package..."
SECURITYDIR=$ANDROID_BUILD_TOP/build/target/product/security
java -Xmx1024m \
-jar $OUT/../../../host/$OUT_TARGET_HOST/framework/signapk.jar \
-w $SECURITYDIR/testkey.x509.pem $SECURITYDIR/testkey.pk8 \
$REPACK/update.zip $OUTFILE
echo
printf "Cleaning up..."
rm -rf $REPACK
echo
# Create a md5 checksum image of the repacked package
(
img=`basename $OUTFILE`
cd `dirname $OUTFILE`
$MD5 $img >$img.md5sum
echo
echo -e $CL_GRN"Package complete: $OUTFILE"$CL_RST
cat $img.md5sum
echo
)
exit 0