replicant-vendor_replicant/tools/squisher

111 lines
2.6 KiB
Plaintext
Raw Normal View History

2010-06-28 15:47:26 +00:00
#!/bin/sh
#
# Squish a CM otapackage for distribution
# cyanogen
#
OUT_TARGET_HOST=`uname -a | grep Darwin`
2010-06-28 15:47:26 +00:00
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
2010-06-28 15:47:26 +00:00
else
OUT_TARGET_HOST=darwin-x86
MD5=md5
XARGS="xargs -n 1 -P `sysctl hw.ncpu | awk '{print $2}'`"
SED=gsed
2010-06-28 15:47:26 +00:00
fi
if [ -z "$OUT" -o ! -d "$OUT" ]; then
echo "ERROR: $0 only works with a full build environment. $OUT should exist."
exit 1
fi
if [ "$TARGET_BUILD_TYPE" = "debug" ]; then
OTAPACKAGE=$OUT/${TARGET_PRODUCT}_debug-ota-$TARGET_BUILD_VARIANT.$USER.zip
elif [ "$TARGET_BUILD_VARIANT" = "userdebug" ]; then
OTAPACKAGE=$OUT/$TARGET_PRODUCT-ota-eng.$USER.zip
else
OTAPACKAGE=$OUT/$TARGET_PRODUCT-ota-$TARGET_BUILD_VARIANT.$USER.zip
fi
2010-06-28 15:47:26 +00:00
if [ ! -f "$OTAPACKAGE" ]; then
echo "$OTAPACKAGE doesn't exist!";
exit 1
2010-06-28 15:47:26 +00:00
fi
OPTICHARGER=$ANDROID_BUILD_TOP/vendor/cm/tools/opticharger
QUIET=-q
2010-06-28 15:47:26 +00:00
DELETE_BINS="applypatch applypatch_static check_prereq recovery updater"
REPACK=$OUT/repack.d
printf "Sanitizing environment..."
rm -rf $REPACK
mkdir -p $REPACK
echo
2010-06-28 15:47:26 +00:00
# Unpack the otapackage and opticharge all apks
mkdir $REPACK/ota
(
cd $REPACK/ota
printf "Unpacking $OTAPACKAGE..."
unzip $QUIET $OTAPACKAGE
echo
cd $REPACK/ota/system/framework
2010-06-28 15:47:26 +00:00
$OPTICHARGER framework-res.apk
cd $REPACK/ota/system/app
find ./ -name \*.apk | $XARGS $OPTICHARGER
)
2010-06-28 15:47:26 +00:00
# Fix build.prop
$SED -i \
-e '/ro\.kernel\.android\.checkjni/d' \
-e '/ro\.build\.type/s/eng/user/' \
$REPACK/ota/system/build.prop
2010-06-28 15:47:26 +00:00
# Delete unnecessary binaries
( cd $REPACK/ota/system/bin; echo $DELETE_BINS | xargs rm -f; )
2010-06-28 15:47:26 +00:00
# No need for recovery
rm -rf $REPACK/ota/recovery
2010-06-28 15:47:26 +00:00
# Strip modules
[ -d $REPACK/ota/system/lib/modules ] && \
find $REPACK/ota/system/lib/modules -name "*.ko" -print0 | xargs -0 arm-eabi-strip --strip-unneeded
2010-06-28 15:47:26 +00:00
# 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 MODVERSION: $MODVERSION
2010-06-28 15:47:26 +00:00
# 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 "Package complete: $OUTFILE"
cat $img.md5sum
echo
)
exit 0