otatools: build-with-colors
- add new file for common functions and stuff
- though it doesn't contain any function now ;)
- red color for errors
- yellow color for "Optimizing: *"
- cyan color for modversion :)
- green color for "package complete"
- and some general cleanup
Change-Id: I83b2e352580e99b1766c5e63821281224cde5c49
diff --git a/tools/functions b/tools/functions
new file mode 100644
index 0000000..30ef005
--- /dev/null
+++ b/tools/functions
@@ -0,0 +1,15 @@
+#!/bin/bash
+# Common functions for CM otatools
+#
+# cdesai
+
+if [ ! "$BUILD_WITH_COLORS" = "0" ];
+then
+CL_RED="\033[31m"
+CL_GRN="\033[32m"
+CL_YLW="\033[33m"
+CL_BLU="\033[34m"
+CL_MAG="\033[35m"
+CL_CYN="\033[36m"
+CL_RST="\033[0m"
+fi
diff --git a/tools/opticharger b/tools/opticharger
index 0473008..652e5c6 100755
--- a/tools/opticharger
+++ b/tools/opticharger
@@ -1,4 +1,4 @@
-#!/bin/sh
+#!/bin/bash
#
# Super-mega opticharger of doom
# Shrinks apks by running pngcrush or optipng or pngout on png images
@@ -15,6 +15,8 @@
BRUTECRUSH="-brute"
TMPDIR=/tmp/opticharge-$$
+. $ANDROID_BUILD_TOP/vendor/cm/tools/functions
+
if [ -z "$BRUTE_PNGCRUSH" ]
then
BRUTECRUSH=""
@@ -31,14 +33,14 @@
APKCERTS=$OUT/obj/PACKAGING/target_files_intermediates/$TARGET_PRODUCT-target_files-$TARGET_BUILD_VARIANT.$USER/META/apkcerts.txt
if [ ! -f "$APKCERTS" ];
then
- echo "Set APKCERTS to the path to your apkcerts.txt file"
+ echo -e $CL_RED"Set APKCERTS to the path to your apkcerts.txt file"$CL_RST
exit 1;
fi
fi
if [ ! -f "$APKCERTS" ];
then
- echo "Invalid path to apkcerts.txt, set APKCERTS to the correct path."
+ echo -e $CL_RED"Invalid path to apkcerts.txt, set APKCERTS to the correct path."$CL_RST
fi
if [ "$(which pngcrush)" != "" ];
@@ -63,26 +65,26 @@
pngout $1
}
else
- echo "Please install pngcrush, optipng, or pngout"
+ echo -e $CL_RED"Please install pngcrush, optipng, or pngout"$CL_RST
exit 1;
fi
if [ "`which aapt`" = "" ];
then
- echo "Please ensure aapt is in your \$PATH"
+ echo -e $CL_RED"Please ensure aapt is in your \$PATH"$CL_RST
exit 1;
fi
if [ "`which zipalign`" = "" ];
then
- echo "Please ensure zipalign is in your \$PATH"
+ echo -e $CL_RED"Please ensure zipalign is in your \$PATH"$CL_RST
exit 1;
fi
if [ -e "$1" ];
then
NAME=`basename $1`;
- echo "Optimizing $NAME...";
+ echo -e $CL_YLW"Optimize:"$CL_RST" $NAME..";
if [ "$2" != "" ];
then
@@ -90,7 +92,7 @@
KEY=build/target/product/security/$2.pk8
if [ ! -f "$ANDROID_BUILD_TOP/$CERT" ];
then
- echo "$CERT does not exist!";
+ echo -e $CL_RED"$CERT does not exist!"$CL_RST;
exit 1;
fi
else
@@ -98,24 +100,24 @@
[ $QUIET ] || echo "APKINFO: $APKINFO";
if [ "$APKINFO" = "" ];
then
- echo "No apk info for $NAME";
+ echo -e $CL_RED"No apk info for $NAME"$CL_RST;
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"
+ echo -e $CL_RED"Unable to find certificate for $NAME"$CL_RST
exit 1;
fi
if [ "$CERT" = "PRESIGNED" ];
then
- echo "$NAME is presigned, skipping"
+ echo -e $CL_YLW"$NAME is presigned, skipping"$CL_RST
exit 1;
fi
fi
- [ $QUIET ] || echo "Certificate: $CERT";
+ [ $QUIET ] || echo -e $CL_YLW"Certificate:"$CL_RST" $CERT";
[ -d $TMPDIR/$NAME ] && rm -rf $TMPDIR/$NAME
mkdir -p $TMPDIR/$NAME
@@ -124,19 +126,19 @@
unzip -q $BASE/$1
for x in `find . -name "*.png" | grep -v "\.9.png$" | tr "\n" " "`
do
- [ $QUIET ] || echo "Crushing $x"
+ [ $QUIET ] || echo -e $CL_YLW"Crushing $x"$CL_RST
optimize_png $x
done
cp $BASE/$1 $BASE/$1.old
- [ $QUIET ] || echo "Repacking apk.."
+ [ $QUIET ] || echo -e $CL_YLW"Repacking apk.."$CL_RST
aapt p -0 .dat -0 .dict -0 .arsc -F $NAME .
- [ $QUIET ] || echo "Resigning with cert: `echo $CERT`"
+ [ $QUIET ] || echo -e $CL_YLW"Resigning with cert: `echo $CERT`"$CL_RST
[ $QUIET ] || echo java -jar $ANDROID_HOST_OUT/framework/signapk.jar $ANDROID_BUILD_TOP/$CERT $ANDROID_BUILD_TOP/$KEY $NAME signed_$NAME
java -jar $ANDROID_HOST_OUT/framework/signapk.jar $ANDROID_BUILD_TOP/$CERT $ANDROID_BUILD_TOP/$KEY $NAME signed_$NAME
- [ $QUIET ] || echo "Zipalign.."
+ [ $QUIET ] || echo -e $CL_YLW"Zipaligning.."$CL_RST
zipalign -f 4 signed_$NAME $BASE/$1
if [ ! $QUIET ]; then
ls -l $BASE/$1.old
diff --git a/tools/squisher b/tools/squisher
index 54498f2..b208ed2 100755
--- a/tools/squisher
+++ b/tools/squisher
@@ -1,9 +1,11 @@
-#!/bin/sh
+#!/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
@@ -19,12 +21,12 @@
fi
if [ -z "$OUT" -o ! -d "$OUT" ]; then
- echo "ERROR: $0 only works with a full build environment. $OUT should exist."
+ 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 "$OTAPACKAGE doesn't exist!";
+ echo -e $CL_RED"$OTAPACKAGE doesn't exist!"$CL_RST;
exit 1
fi
@@ -87,7 +89,7 @@
# 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
+echo -e $CL_CYN"MODVERSION: $MODVERSION"$CL_RST
# Pack it up and sign
printf "Zipping package..."
@@ -110,7 +112,7 @@
cd `dirname $OUTFILE`
$MD5 $img >$img.md5sum
echo
-echo "Package complete: $OUTFILE"
+echo -e $CL_GRN"Package complete: $OUTFILE"$CL_RST
cat $img.md5sum
echo
)