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/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