replicant-vendor_replicant/tools/squisher
2010-07-16 16:38:37 -04:00

159 lines
3.6 KiB
Bash
Executable File

#!/bin/sh
#
# Squish a CM otapackage for distribution
# cyanogen
#
OUT_TARGET_HOST=$(uname -a | grep Darwin)
if [ -z "$OUT_TARGET_HOST" ]
then
OUT_TARGET_HOST=linux-x86
MD5=md5sum
else
OUT_TARGET_HOST=darwin-x86
MD5=md5
fi
if [ -z "$OUT" -o ! -d "$OUT" ]; then
echo "ERROR: $0 only works with a full build environment. $OUT should exist."
exit 1
fi
OTAPACKAGE=$OUT/$TARGET_PRODUCT-ota-$TARGET_BUILD_VARIANT.$LOGNAME.zip
if [ ! -f "$OTAPACKAGE" ]; then
echo "$OTAPACKAGE doesn't exist!";
exit 1
fi
OPTICHARGER=$ANDROID_BUILD_TOP/vendor/cyanogen/tools/opticharger
QUIET=-q
DELETE_BINS="applypatch applypatch_static check_prereq recovery updater"
# Some products want a squashfs for xbin for space
case "$TARGET_PRODUCT" in
cyanogen_dream_sapphire) WANT_SQUASHFS=1 ;;
*) WANT_SQUASHFS=0 ;;
esac
if [ "$WANT_SQUASHFS" -eq 1 ]; then
fatal=0
MKSQUASHFS_VER_REQ=4
if type mksquashfs >/dev/null 2>&1; then
if mksquashfs -version | grep -q "version $MKSQUASHFS_VER_REQ"; then :; else
echo
echo "ERROR: mksquashfs must be at least version $MKSQUASHFS_VER_REQ for this build."
fatal=1
fi
else
echo
echo "ERROR: $TARGET_PRODUCT requires mksquashfs."
fatal=1
fi
if [ "$fatal" -ne 0 ]; then
echo
echo " Unoptimized package is still available at"
echo " $OTAPACKAGE"
exit $fatal
fi
fi
REPACK=$OUT/repack.d
SYSTEM=$REPACK/ota/system
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
cd $REPACK/ota/system/framework
$OPTICHARGER framework-res.apk
cd $REPACK/ota/system/app
for i in *.apk; do $OPTICHARGER $i; done
)
if [ "$WANT_SQUASHFS" -eq 1 ]; then
squash_opts="-force-uid 1000 -force-gid 1000 -no-progress -noappend -no-exports -no-recovery"
# Create the xbin squashfs
cp -a $SYSTEM/xbin $REPACK/xbin/
rm -f $REPACK/xbin/su
chmod -R 555 $REPACK/xbin/*
ln -s ../bin/su $REPACK/xbin/su
# Relocate su and put xbin.sqf where it belongs
rm -f $SYSTEM/bin/su
mv $SYSTEM/xbin/su $SYSTEM/bin/su
rm -rf $SYSTEM/xbin/*
mksquashfs $REPACK/xbin/* $SYSTEM/xbin/xbin.sqf $squash_opts
chmod 444 $SYSTEM/xbin/xbin.sqf
# Remove xbin stuff and fix up updater-script
sed -i -e's,system/xbin/su,system/bin/su,g' -e'/xbin/d' $REPACK/ota/META-INF/com/google/android/updater-script
fi
# Fix build.prop
sed -i \
-e '/ro\.kernel\.android\.checkjni/d' \
-e '/ro\.build\.type/s/eng/user/' \
$SYSTEM/build.prop
# Delete unnecessary binaries
( cd $SYSTEM/bin; echo $DELETE_BINS | xargs rm -f; )
# Delete leftover wireless driver
rm -rf $SYSTEM/lib/modules/*/kernel/drivers/net
# No need for recovery
rm -rf $REPACK/ota/recovery
# Strip modules
find $SYSTEM/lib/modules -name "*.ko" -print0 | xargs -0 arm-eabi-strip --strip-unneeded
# Determine what to name the new signed package
if [ -z "$CYANOGEN_NIGHTLY" ]; then
OUTFILE=$OUT/update-squished.zip
else
MODVERSION=`sed -n -e'/ro\.modversion/s/^.*CyanogenMod-//p' $SYSTEM/build.prop`
: ${MODVERSION:=nightly}
OUTFILE=$OUT/update-cm-$MODVERSION-signed.zip
fi
# 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 -Xmx2048m \
-jar $ANDROID_BUILD_TOP/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
(
img=`basename $OUTFILE`
cd `dirname $OUTFILE`
$MD5 $img >$img.md5sum
echo
echo "Package complete: $OUTFILE"
cat $img.md5sum
echo
)
exit 0