2010-06-28 15:47:26 +00:00
|
|
|
#!/bin/sh
|
|
|
|
#
|
|
|
|
# Squish a CM otapackage for distribution
|
|
|
|
# cyanogen
|
|
|
|
#
|
|
|
|
|
2010-07-16 20:28:46 +00:00
|
|
|
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
|
|
|
|
else
|
|
|
|
OUT_TARGET_HOST=darwin-x86
|
|
|
|
MD5=md5
|
|
|
|
fi
|
|
|
|
|
2010-07-16 15:13:35 +00:00
|
|
|
if [ -z "$OUT" -o ! -d "$OUT" ]; then
|
|
|
|
echo "ERROR: $0 only works with a full build environment. $OUT should exist."
|
|
|
|
exit 1
|
|
|
|
fi
|
|
|
|
|
2010-06-28 15:47:26 +00:00
|
|
|
OTAPACKAGE=$OUT/$TARGET_PRODUCT-ota-$TARGET_BUILD_VARIANT.$LOGNAME.zip
|
|
|
|
if [ ! -f "$OTAPACKAGE" ]; then
|
2010-07-16 15:13:35 +00:00
|
|
|
echo "$OTAPACKAGE doesn't exist!";
|
|
|
|
exit 1
|
2010-06-28 15:47:26 +00:00
|
|
|
fi
|
|
|
|
|
|
|
|
OPTICHARGER=$ANDROID_BUILD_TOP/vendor/cyanogen/tools/opticharger
|
2010-07-11 06:42:36 +00:00
|
|
|
QUIET=-q
|
2010-06-28 15:47:26 +00:00
|
|
|
DELETE_BINS="applypatch applypatch_static check_prereq recovery updater"
|
2010-07-16 15:13:35 +00:00
|
|
|
|
|
|
|
|
|
|
|
# Some products want a squashfs for xbin for space
|
2010-07-24 22:33:52 +00:00
|
|
|
case "$TARGET_PRODUCT" in
|
|
|
|
cyanogen_dream_sapphire) WANT_SQUASHFS=1 ;;
|
|
|
|
*) WANT_SQUASHFS=0 ;;
|
|
|
|
esac
|
2010-07-16 15:13:35 +00:00
|
|
|
|
2010-07-24 22:33:52 +00:00
|
|
|
if [ "$WANT_SQUASHFS" -eq 1 ]; then
|
2010-07-16 15:13:35 +00:00
|
|
|
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
|
2010-07-15 19:44:43 +00:00
|
|
|
fi
|
|
|
|
|
2010-07-16 15:13:35 +00:00
|
|
|
if [ "$fatal" -ne 0 ]; then
|
|
|
|
echo
|
|
|
|
echo " Unoptimized package is still available at"
|
|
|
|
echo " $OTAPACKAGE"
|
|
|
|
exit $fatal
|
|
|
|
fi
|
2010-07-15 19:44:43 +00:00
|
|
|
fi
|
2010-06-28 15:47:26 +00:00
|
|
|
|
2010-07-16 15:13:35 +00:00
|
|
|
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
|
2010-07-16 15:13:35 +00:00
|
|
|
mkdir $REPACK/ota
|
|
|
|
(
|
|
|
|
cd $REPACK/ota
|
|
|
|
printf "Unpacking $OTAPACKAGE..."
|
2010-07-11 06:42:36 +00:00
|
|
|
unzip $QUIET $OTAPACKAGE
|
2010-07-16 15:13:35 +00:00
|
|
|
echo
|
|
|
|
cd $REPACK/ota/system/framework
|
2010-06-28 15:47:26 +00:00
|
|
|
$OPTICHARGER framework-res.apk
|
2010-07-16 15:13:35 +00:00
|
|
|
cd $REPACK/ota/system/app
|
|
|
|
for i in *.apk; do $OPTICHARGER $i; done
|
|
|
|
)
|
2010-06-28 15:47:26 +00:00
|
|
|
|
|
|
|
|
2010-07-24 22:33:52 +00:00
|
|
|
if [ "$WANT_SQUASHFS" -eq 1 ]; then
|
2010-07-16 15:13:35 +00:00
|
|
|
squash_opts="-force-uid 1000 -force-gid 1000 -no-progress -noappend -no-exports -no-recovery"
|
2010-07-16 20:28:46 +00:00
|
|
|
updater=$REPACK/ota/META-INF/com/google/android/updater-script
|
|
|
|
|
|
|
|
# Relocate su
|
|
|
|
cp -a $REPACK/ota/system/xbin $REPACK/_xbin/
|
|
|
|
rm -f $REPACK/_xbin/su $REPACK/ota/system/bin/su
|
|
|
|
mv $REPACK/ota/system/xbin/su $REPACK/ota/system/bin/su
|
|
|
|
chmod -R 555 $REPACK/_xbin/*
|
|
|
|
|
|
|
|
# Create symlinks for su and busybox (since updater-script can't work on the squashfs filesystem).
|
|
|
|
# Forgive me for the regex hell here.
|
|
|
|
ln -s ../bin/su $REPACK/_xbin/su
|
|
|
|
for link in `sed -n -e's/,//g' -e'/symlink(.*busybox/,/xbin.*);/p' $updater | tr '"' '\n' | sed -n -e'\,/system/xbin/,s,/system/xbin/,,p'`
|
|
|
|
do
|
|
|
|
ln -s busybox $REPACK/_xbin/$link
|
|
|
|
done
|
|
|
|
|
|
|
|
# Create the squashfs with new and improved symlinkage!
|
|
|
|
mksquashfs $REPACK/_xbin/* $REPACK/_xbin.sqf $squash_opts
|
|
|
|
rm -rf $REPACK/ota/system/xbin/*
|
|
|
|
mv $REPACK/_xbin.sqf $REPACK/ota/system/xbin/xbin.sqf
|
|
|
|
chmod 444 $REPACK/ota/system/xbin/xbin.sqf
|
2010-07-16 15:13:35 +00:00
|
|
|
|
|
|
|
# Remove xbin stuff and fix up updater-script
|
2010-07-16 20:28:46 +00:00
|
|
|
sed -i -e's,system/xbin/su,system/bin/su,g' -e'/xbin/d' $updater
|
2010-06-28 15:47:26 +00:00
|
|
|
fi
|
|
|
|
|
2010-07-16 15:13:35 +00:00
|
|
|
|
2010-06-28 15:47:26 +00:00
|
|
|
# Fix build.prop
|
2010-07-16 15:13:35 +00:00
|
|
|
sed -i \
|
|
|
|
-e '/ro\.kernel\.android\.checkjni/d' \
|
|
|
|
-e '/ro\.build\.type/s/eng/user/' \
|
2010-07-16 20:28:46 +00:00
|
|
|
$REPACK/ota/system/build.prop
|
2010-07-16 15:13:35 +00:00
|
|
|
|
2010-06-28 15:47:26 +00:00
|
|
|
|
|
|
|
# Delete unnecessary binaries
|
2010-07-16 20:28:46 +00:00
|
|
|
( cd $REPACK/ota/system/bin; echo $DELETE_BINS | xargs rm -f; )
|
2010-06-28 15:47:26 +00:00
|
|
|
|
2010-07-11 08:34:44 +00:00
|
|
|
# Delete leftover wireless driver
|
2010-07-16 20:28:46 +00:00
|
|
|
rm -rf $REPACK/ota/system/lib/modules/*/kernel/drivers/net
|
2010-06-28 15:47:26 +00:00
|
|
|
|
|
|
|
# No need for recovery
|
2010-07-16 15:13:35 +00:00
|
|
|
rm -rf $REPACK/ota/recovery
|
2010-06-28 15:47:26 +00:00
|
|
|
|
2010-07-16 15:13:35 +00:00
|
|
|
# Strip modules
|
2010-07-16 20:28:46 +00:00
|
|
|
find $REPACK/ota/system/lib/modules -name "*.ko" -print0 | xargs -0 arm-eabi-strip --strip-unneeded
|
2010-06-28 15:47:26 +00:00
|
|
|
|
2010-07-16 15:13:35 +00:00
|
|
|
# Determine what to name the new signed package
|
|
|
|
if [ -z "$CYANOGEN_NIGHTLY" ]; then
|
2010-07-16 20:28:46 +00:00
|
|
|
MODVERSION=`sed -n -e'/ro\.modversion/s/^.*CyanogenMod-//p' $REPACK/ota/system/build.prop`
|
2010-07-16 15:13:35 +00:00
|
|
|
: ${MODVERSION:=nightly}
|
|
|
|
OUTFILE=$OUT/update-cm-$MODVERSION-signed.zip
|
2010-07-16 22:03:19 +00:00
|
|
|
else
|
|
|
|
OUTFILE=$OUT/update-squished.zip
|
2010-07-03 06:15:31 +00:00
|
|
|
fi
|
2010-06-28 15:47:26 +00:00
|
|
|
|
2010-07-16 15:13:35 +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
|
2010-08-21 04:30:40 +00:00
|
|
|
java -Xmx512m \
|
2010-07-16 15:13:35 +00:00
|
|
|
-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
|
|
|
|
|
2010-07-16 20:28:46 +00:00
|
|
|
# Create a md5 checksum image of the repacked package
|
2010-07-16 15:13:35 +00:00
|
|
|
(
|
|
|
|
img=`basename $OUTFILE`
|
|
|
|
cd `dirname $OUTFILE`
|
|
|
|
$MD5 $img >$img.md5sum
|
|
|
|
echo
|
|
|
|
echo "Package complete: $OUTFILE"
|
|
|
|
cat $img.md5sum
|
|
|
|
echo
|
|
|
|
)
|
|
|
|
|
|
|
|
exit 0
|