Add CM tools.

This commit is contained in:
Steve Kondik 2010-06-28 11:47:26 -04:00
parent afd7526805
commit ae76c84593
2 changed files with 224 additions and 0 deletions

119
tools/opticharger Executable file
View File

@ -0,0 +1,119 @@
#!/bin/sh
#
# Super-mega opticharger of doom
# Shrinks apks by running pngcrush on png images
#
# Point APKCERTS at the full path to a generated apkcerts.txt file, such as:
# /home/shade/dev/sources/android-cm-eclair/out/target/product/dream_sapphire/obj/PACKAGING/target_files_intermediates/cyanogen_dream_sapphire-target_files-eng.shade/META/apkcerts.txt
#
# cyanogen - shade@chemlab.org
# ChrisSoyars - me@ctso.me
OUT_TARGET_HOST=$(uname -a | grep Darwin)
if [ -z "$OUT_TARGET_HOST" ]
then
OUT_TARGET_HOST=linux-x86
else
OUT_TARGET_HOST=darwin-x86
fi
set -e
BASE=`pwd`
if [ "$APKCERTS" = "" ];
then
APKCERTS=$OUT/obj/PACKAGING/target_files_intermediates/$TARGET_PRODUCT-target_files-$TARGET_BUILD_VARIANT.$LOGNAME/META/apkcerts.txt
if [ ! -f "$APKCERTS" ];
then
echo "Set APKCERTS to the path to your apkcerts.txt file"
exit 1;
fi
fi
if [ ! -f "$APKCERTS" ];
then
echo "Invalid path to apkcerts.txt, set APKCERTS to the correct path."
fi
if [ "`which pngcrush`" = "" ];
then
echo "Please install pngcrush"
exit 1;
fi
if [ "`which aapt`" = "" ];
then
echo "Please ensure aapt is in your \$PATH"
exit 1;
fi
if [ "`which zipalign`" = "" ];
then
echo "Please ensure zipalign is in your \$PATH"
exit 1;
fi
if [ -e "$1" ];
then
NAME=`basename $1`;
echo "Optimizing $NAME...";
if [ "$2" != "" ];
then
CERT=build/target/product/security/$2.x509.pem
KEY=build/target/product/security/$2.pk8
if [ ! -f "$ANDROID_BUILD_TOP/$CERT" ];
then
echo "$CERT does not exist!";
exit 1;
fi
else
APKINFO=`grep "name=\"$NAME\"" $APKCERTS`;
echo "APKINFO: $APKINFO";
if [ "$APKINFO" = "" ];
then
echo "No apk info for $NAME";
exit 1;
fi
CERT=`echo $APKINFO | awk {'print $2'} | cut -f 2 -d "=" | tr -d "\""`;
KEY=`echo $APKINFO | awk {'print $3'} | cut -f 2 -d "=" | tr -d "\""`;
if [ "$CERT" = "" ];
then
echo "Unable to find certificate for $NAME"
exit 1;
fi
fi
echo "Certificate: $CERT";
rm -rf /tmp/$NAME
mkdir /tmp/$NAME
cd /tmp/$NAME
unzip $BASE/$1
for x in `find . -name "*.png" | grep -v "\.9.png$" | tr "\n" " "`
do
echo "Crushing $x"
pngcrush $x $x.crushed 1>/dev/null
if [ -e "$x.crushed" ];
then
mv $x.crushed $x
fi
done
cp $BASE/$1 $BASE/$1.old
echo "Repacking apk.."
aapt p -0 res/raw -0 res/raw-en -F $NAME .
echo "Resigning with cert: `echo $CERT`"
echo java -jar $ANDROID_BUILD_TOP/out/host/$OUT_TARGET_HOST/framework/signapk.jar $ANDROID_BUILD_TOP/$CERT $ANDROID_BUILD_TOP/$KEY $NAME signed_$NAME
java -jar $ANDROID_BUILD_TOP/out/host/$OUT_TARGET_HOST/framework/signapk.jar $ANDROID_BUILD_TOP/$CERT $ANDROID_BUILD_TOP/$KEY $NAME signed_$NAME
echo "Zipalign.."
zipalign -f 4 signed_$NAME $BASE/$1
ls -l $BASE/$1.old
ls -l $BASE/$1
rm $BASE/$1.old
else
echo "Usage: $0 [apk file]"
fi

105
tools/squisher Executable file
View File

@ -0,0 +1,105 @@
#!/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
OTAPACKAGE=$OUT/$TARGET_PRODUCT-ota-$TARGET_BUILD_VARIANT.$LOGNAME.zip
if [ ! -f "$OTAPACKAGE" ]; then
echo "$OTAPACKAGE doesn't exist!";
exit 1
fi
XBIN=$OUT/system/xbin
OPTICHARGER=$ANDROID_BUILD_TOP/vendor/cyanogen/tools/opticharger
DELETE_BINS="applypatch applypatch_static check_prereq recovery updater"
WORK=/tmp/repack
rm -rf $WORK
mkdir -p $WORK
if [ "$TARGET_PRODUCT" = "cyanogen_dream_sapphire" ]
then
# Create the xbin squashfs
cp -a $XBIN $WORK/xbin/
cd $WORK/xbin
chown -R 1000:1000 *
chmod -R 755 *
rm su
ln -s ../bin/su su
mksquashfs . $WORK/xbin.sqf
fi
# Unpack the otapackage and opticharge all apks
mkdir $WORK/ota
cd $WORK/ota
unzip $OTAPACKAGE
cd system/framework
$OPTICHARGER framework-res.apk
cd ../app
for i in *.apk; do
$OPTICHARGER $i;
done
cd $WORK/ota/system
if [ "$TARGET_PRODUCT" == "cyanogen_dream_sapphire" ]
then
# Relocate su and put xbin.sqf where it belongs
rm -f bin/su
mv xbin/su bin/su
rm -rf xbin/*
mv $WORK/xbin.sqf xbin/
fi
# Fix build.prop
grep -v ro.kernel.android.checkjni build.prop | sed -e "s/^ro\.build\.type=eng$/ro\.build\.type=user/g" > build.prop.new
mv build.prop.new build.prop
# Delete unnecessary binaries
for i in $DELETE_BINS; do
rm -f bin/$i
done
# Find the CM version
MODVERSION=`grep ro.modversion build.prop | sed -e "s/^.*CyanogenMod-//g"`
# No need for recovery
cd $WORK/ota
rm -rf recovery
# Remove xbin stuff and fix up updater-script
if [ "$TARGET_PRODUCT" == "cyanogen_dream_sapphire" ]
then
sed -e "s/system\/xbin\/su/system\/bin\/su/g" META-INF/com/google/android/updater-script | grep -v xbin > updater-script.new
else
cp META-INF/com/google/android/updater-script updater-script.new
fi
echo "ui_print(\"Welcome to CyanogenMod-$MODVERSION!\");" > META-INF/com/google/android/updater-script
cat updater-script.new >> META-INF/com/google/android/updater-script
rm updater-script.new
# Pack it up and sign
zip -r update.zip .
echo "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 update.zip update_signed.zip
mv update_signed.zip $OUT/update-cm-$MODVERSION-signed.zip
$MD5 $OUT/update-cm-$MODVERSION-signed.zip > $OUT/update-cm-$MODVERSION-signed.zip.md5sum
echo "Package complete: $OUT/update-cm-$MODVERSION-signed.zip";
cat $OUT/update-cm-$MODVERSION-signed.zip.md5sum