[Android] Cl3Kener:
Another Example for Fun

Well this thread looked like it needed a comment or at least some positive feedback so here it goes. :)

Thanks so much [MENTION=4238916]ayysir[/MENTION] for making this tutorial!!!! :D I've been using scripts to do lots of things for me for about a year now and it all started when I read this thread. (for some reason the though of bash scripts never really crossed my mind before then)

Here is an example of how creative I've got since the beginning of this. My script now includes some colored logos just for fun as well as final build time, uploading to goo.im, and signing of the final zip. (The logos might not show up right on here but they look great in terminal)

#!/bin/bash
#Cl3Kener's Hammerhead Script

# Colorize and add text parameters (originally grabbed from Ayysir)
red=$(tput setaf 1) # red
grn=$(tput setaf 2) # green
cya=$(tput setaf 6) # cyan
pnk=$(tput bold ; tput setaf 5) # pink
yel=$(tput bold ; tput setaf 3) # yellow
pur=$(tput setaf 5) # purple
txtbld=$(tput bold) # Bold
bldred=${txtbld}$(tput setaf 1) # red
bldgrn=${txtbld}$(tput setaf 2) # green
bldyel=${txtbld}$(tput bold ; tput setaf 3) # yellow
bldblu=${txtbld}$(tput setaf 4) # blue
bldpur=${txtbld}$(tput setaf 5) # purple
bldpnk=${txtbld}$(tput bold ; tput setaf 5) # pink
bldcya=${txtbld}$(tput setaf 6) # cyan
txtrst=$(tput sgr0) # Reset

#Place you defconfig name here:
DEFCONFIG=uber_hammerhead_defconfig

# Change these exports as needed:
export INITRAMFS_DEST=~/android/kernel/usr/initramfs
export PACKAGEDIR=~/android/kernel/OUT
export KERNEL_SOURCE=~/android/kernel
export Meta=~/android/kernel/Cl3Kener/META-INF
export Etc=~/android/kernel/Cl3Kener/etc
export Scripts=~/android/kernel/Cl3Kener/kernel
export Bin=~/android/kernel/Cl3Kener/bin
export Lib=~/android/kernel/Cl3Kener/lib
export GPU=~/android/kernel/Cl3Kener/kcontrol_gpu_msm
export sign=~/android/kernel/Cl3Kener/signapk_files
export ARCH=arm
export CROSS_COMPILE=~/android/kernel/TOOLCHAINS/arm-eabi-4.7/bin/arm-eabi-

# Place your goo.im password here instead of XXXXXX so you don't have to input password (or you can use ssh key if you have one):
export SSHPASS=XXXXXXX

# Start Time
res1=$(date +%s.%N)

# Logo (just for fun)
echo "${bldpur} ${txtrst}"
echo "${bldpur} ________________________________________ ${txtrst}"
echo "${bldpur}| |${txtrst}"
echo "${bldpur}| _| _| _|_|_| _|_|_|_| _|_|_| |${txtrst}"
echo "${bldpur}| _| _| _| _| _| _| _| |${txtrst}"
echo "${bldpur}| _| _| _|_|_| _|_|_| _|_|_| |${txtrst}"
echo "${bldpur}| _| _| _| _| _| _| _| |${txtrst}"
echo "${bldpur}| _| _| _| _| _| _| _| |${txtrst}"
echo "${bldpur}| _|_| _|_|_| _|_|_|_| _| _| |${txtrst}"
echo "${bldpur}|________________________________________|${txtrst}"
echo "${bldpur} ${txtrst}"

echo "${bldcya}Remove Old Package Files ${txtrst}"
rm -rf $PACKAGEDIR/*

echo " "

echo "${bldgrn}Setup Init.d Directory ${txtrst}"
mkdir -p $PACKAGEDIR/system/etc

echo " "

echo "${bldyel}Setup Scripts Directory ${txtrst}"
mkdir -p $PACKAGEDIR/modules

echo " "

echo "${bldblu}Remove old zImage ${txtrst}"
rm $KERNEL_SOURCE/arch/arm/boot/zImage
rm $KERNEL_SOURCE/arch/arm/boot/zImage-dtb

echo " "

echo -e "${bldred}Removing annoying gedit backup files ${txtrst}"
cd ~/android/kernel
find ./ -name '*~' | xargs rm

echo " "

echo "${bldgrn}Clean Environment ${txtrst}"
cd $KERNEL_SOURCE
make $DEFCONFIG
rm $KERNEL_SOURCE/.version
rm $KERNEL_SOURCE/.config.old
rm $KERNEL_SOURCE/.config
make clean

echo " "

echo "${bldpnk}Kernel Menu ${txtrst}"
make menuconfig

echo " "

echo "${bldcya}Compiling.... ${txtrst}"
script -q ~/Compile.log -c "
make -j7"

echo " "

if [ -e $KERNEL_SOURCE/arch/arm/boot/zImage-dtb ]; then

# I used Showp1984 msm_mpdecision hotplug and so I use his KControl Module.
echo "${bldyel}Making GPU Module ${txtrst}"
cd $GPU
make clean
make -j7

echo " "

cd $KERNEL_SOURCE

echo "${bldgrn}Copy Modules to OUT ${txtrst}"
cp -a $(find . -name *.ko -print |grep -v initramfs) $PACKAGEDIR/modules/

echo "${bldblu}Import Scripts ${txtrst}"
cp -R $Scripts $PACKAGEDIR

echo "${bldcya}Copy bin to OUT ${txtrst}"
cp -R $Bin $PACKAGEDIR/system/bin

echo "${bldred}Copy zImage to OUT ${txtrst}"
cp $KERNEL_SOURCE/arch/arm/boot/zImage-dtb $PACKAGEDIR/kernel/zImage

echo "${bldgrn}Import of META-INF ${txtrst}"
cp -R $Meta $PACKAGEDIR

echo "${bldcya}Import Init.d Tweaks ${txtrst}"
cp -R $Etc/init.d $PACKAGEDIR/system/etc

echo "${bldred}Import Dalvik/Bionic Optimized Libs ${txtrst}"
cp -R $Lib $PACKAGEDIR/system

export curdate=`date "+%m-%d-%Y"`
cp ~/Compile.log ~/android/Logs/Completed-Uber-hammerhead-$curdate.log
rm ~/Compile.log

cd $PACKAGEDIR
rm ../UBER-Hammerhead*.zip\
rm -R .fr-7q5stU
zip -r ../UBER-Hammerhead-Nightly.zip .

echo " "

echo "${bldblu}Signing Zip ${txtrst}"
cd $KERNEL_SOURCE
cp $sign/signapk.jar $KERNEL_SOURCE
cp $sign/testkey.pk8 $KERNEL_SOURCE
cp $sign/testkey.x509.pem $KERNEL_SOURCE
java -jar ~/android/kernel/signapk.jar testkey.x509.pem testkey.pk8 UBER-Hammerhead-Nightly.zip UBER-Hammerhead-Linaro-4.8.3-$curdate.zip
rm UBER-Hammerhead-Nightly.zip
rm signapk.jar
rm testkey.pk8
rm testkey.x509.pem

echo "${bldgrn} ${txtrst}"
echo "${bldgrn} ${txtrst}"
echo "${bldgrn} ________________________________________ ${txtrst}"
echo "${bldgrn}| |${txtrst}"
echo "${bldgrn}| _| _| _|_|_| _|_|_|_| _|_|_| |${txtrst}"
echo "${bldgrn}| _| _| _| _| _| _| _| |${txtrst}"
echo "${bldgrn}| _| _| _|_|_| _|_|_| _|_|_| |${txtrst}"
echo "${bldgrn}| _| _| _| _| _| _| _| |${txtrst}"
echo "${bldgrn}| _| _| _| _| _| _| _| |${txtrst}"
echo "${bldgrn}| _|_| _|_|_| _|_|_|_| _| _| |${txtrst}"
echo "${bldgrn}|________________________________________|${txtrst}"
echo "${bldgrn} ${txtrst}"
echo "${bldgrn} ${txtrst}"
echo "${bldgrn}Kernel has completed successfully!!! ${txtrst}"
echo " "
echo " "
echo "${bldgrn}Uploading .... ${txtrst}"

echo " "

sshpass -e scp -P 2222 ~/android/kernel/UBER-Hammerhead-Linaro-4.8.3-$curdate.zip Cl3Kener@upload.goo.im:/home/Cl3Kener/public_html/HAMMERHEAD/KERNELS/UBER/EXP-LINARO/UBER-Hammerhead-Linaro-4.8.3-$curdate.zip

# Show Elapsed Time
res2=$(date +%s.%N)
echo "${bldgrn}Total elapsed time of ALL BUILDS AND UPLOADS: ${txtrst}${grn}$(echo "($res2 - $res1) / 60"|bc ) minutes ($(echo "$res2 - $res1"|bc ) seconds) ${txtrst}"

else

export curdate=`date "+%m-%d-%Y"`
cp ~/Compile.log ~/android/Logs/Failed-Uber-hammerhead-$curdate.log
rm ~/Compile.log
echo "${bldred} ${txtrst}"
echo "${bldred} ${txtrst}"
echo "${bldred} ________________________________________ ${txtrst}"
echo "${bldred}| |${txtrst}"
echo "${bldred}| _| _| _|_|_| _|_|_|_| _|_|_| |${txtrst}"
echo "${bldred}| _| _| _| _| _| _| _| |${txtrst}"
echo "${bldred}| _| _| _|_|_| _|_|_| _|_|_| |${txtrst}"
echo "${bldred}| _| _| _| _| _| _| _| |${txtrst}"
echo "${bldred}| _| _| _| _| _| _| _| |${txtrst}"
echo "${bldred}| _|_| _|_|_| _|_|_|_| _| _| |${txtrst}"
echo "${bldred}|________________________________________|${txtrst}"
echo "${bldred} ${txtrst}"
echo "${bldred} ${txtrst}"
echo "${bldred}KERNEL IMAGE DID NOT BUILD PROPERLY! Check Compile log! ${txtrst}"

echo " "

# Show Elapsed Time
res2=$(date +%s.%N)
echo "${bldred}Total elapsed time of ALL BUILDS AND UPLOADS: ${txtrst}${red}$(echo "($res2 - $res1) / 60"|bc ) minutes ($(echo "$res2 - $res1"|bc ) seconds) ${txtrst}"
fi;

echo " "

read -p "Press ENTER to Exit"

Hope this helps some of you get creative!

If you want to see a finished product so you can figure out how everything came together see here: http://goo.im/devs/Cl3Kener/HAMMERHEAD/KERNELS/UBER

Cheers!

Cl3Kener