Created
March 5, 2015 19:54
-
-
Save invisiblek/0d9208eb2f9ea4ad796d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Set some personalized parameters | |
destemail="[email protected]" | |
sourcedir=$HOME/cm | |
tempdir=$sourcedir/tempdir | |
export USE_CCACHE=1 | |
export USE_PREBUILT_CACHE=1 | |
export PREBUILT_CACHE_DIR=/opt/buildcache | |
export CCACHE_DIR=/opt/ccache | |
export OUT_DIR_COMMON_BASE=/opt/out | |
showhelp() { | |
echo "" | |
echo -e `basename $0` "by invisiblek" | |
echo "" | |
echo -e "Usage:\033[0m build.cm.generic <device> <version> [-h] [-u] [-s] [-p] [-c] [-t] [-f]" | |
echo " -h|--help : Show this help message" | |
echo " -s|--sync : Sync source" | |
echo " -p|--pick : Cherry pick (implies -s)" | |
echo " -u|--upload : Upload when finished" | |
echo " -c|--clobber : Clobber the build" | |
echo " -t|--tweet : Tweet when finished" | |
echo " -f|--force : Skip pauses" | |
echo " -a|--addemail <email> : Define additional email address to send notification to" | |
echo "" | |
exit 0; | |
} | |
[ $# -eq 0 ] && showhelp | |
while [ $# -gt 0 ]; do | |
case $1 in | |
-h|--help|help) showhelp;; | |
-s|--sync) sync="true";; | |
-p|--pick) pick="true"; sync="true";; | |
-t|--tweet) tweet="true";; | |
-u|--upload) upload="true";; | |
-f|--force) force="true";; | |
-c|--clobber) clobber="true";; | |
-a|--addemail) shift; addemailaddress="$1"; addemail="true";; | |
10.1|cm-10.1) version=10.1;; | |
10.2|cm-10.2) version=10.2;; | |
11.0|cm-11.0) version=11.0;; | |
12.0|cm-12.0) version=12.0;; | |
*) [ -n "$devicename" ] && showhelp || devicename=$1;; | |
esac | |
shift | |
done | |
sourcedir+="/$version" | |
[ "$version" = "" ] && echo -e '\E[37;41m'"\033[1mPlease specify CM version\033[0m" && exit 1 | |
[ "$upload" != "true" ] && tweet="false" | |
# Let user know what we are going to do | |
echo -e '\E[37;44m'"\033[1mBuilding CM$version for $devicename\033[0m" | |
[ "$clobber" = "true" ] && echo -e '\E[37;44m'"\033[1mWill clobber the build\033[0m" | |
[ "$sync" = "true" ] && echo -e '\E[37;44m'"\033[1mWill repo sync\033[0m" | |
[ "$pick" = "true" ] && echo -e '\E[37;44m'"\033[1mWill pull in repopicks and cherrypicks\033[0m" | |
[ "$upload" = "true" ] && echo -e '\E[37;44m'"\033[1mWill upload when finished\033[0m" | |
[ "$tweet" = "true" ] && echo -e '\E[37;44m'"\033[1mWill tweet when finished\033[0m" | |
[ "$addemail" = "true" ] && destemail+=",$addemailaddress" | |
echo -e '\E[37;44m'"\033[1mWill send an email to $destemail when finished\033[0m" | |
if [ "$force" = "true" ]; then | |
echo -e '\E[37;44m'"\033[1mContinuing build...\033[0m" | |
else | |
read -p "Press [enter] to continue..." | |
echo -e '\E[37;44m'"\033[1mContinuing build...\033[0m" | |
sleep 1 | |
fi | |
# Clean up a bit | |
rm -rf $tempdir | |
mkdir $tempdir | |
# Sync if told to | |
if [ "$sync" = "true" ]; then | |
echo -e '\E[37;44m'"\033[1mSyncing...\033[0m" | |
cd $sourcedir/ | |
source build/envsetup.sh | |
$HOME/.bin/repo sync -d -j16 > /dev/null | |
# Cherry pick if told to | |
if [ "$pick" = "true" ]; then | |
echo -e '\E[37;44m'"\033[1mCleaning Repos...\033[0m" | |
cd $sourcedir/ | |
$HOME/.bin/pick $version | |
# [ -a $HOME/.bin/build.cm.hax ] && echo -e '\E[37;44m'"\033[1mRunning hax...\033[0m" && $HOME/.bin/build.cm.hax $version | |
fi | |
else | |
echo -e '\E[37;44m'"\033[1mSkipping sync...\033[0m" | |
fi | |
cd $sourcedir/ | |
if [ "$clobber" = "true" ]; then | |
echo -e '\E[37;44m'"\033[1mClobbering...\033[0m" | |
make clobber | |
else | |
echo -e '\E[37;44m'"\033[1mDoing a bit of cleanup...\033[0m" | |
rm -f $sourcedir/out/target/product/$devicename/cm-$version-*.zip > /dev/null | |
rm -f $sourcedir/out/target/product/$devicename/cm-$version-*.zip.md5sum > /dev/null | |
rm -f $sourcedir/out/target/product/$devicename/system/build.prop > /dev/null | |
fi | |
# Build! | |
echo -e '\E[37;44m'"\033[1mStarting build...\033[0m" | |
source build/envsetup.sh | |
lunch cm_$devicename-userdebug | |
/usr/bin/time -o $tempdir/seconds -f "%E" bash -c "make -j12 bacon" | |
# Set filename and chmod | |
cd $sourcedir/out/target/product/$devicename/ | |
filename=`ls cm-*.zip` | |
chmod 644 $filename | |
# Clean up some useless shit | |
rm -f $sourcedir/out/target/product/$devicename/cm_*-ota-*.zip | |
rm -f $sourcedir/out/target/product/$devicename/system.img | |
rm -f $sourcedir/out/target/product/$devicename/userdata.img | |
# Copy to daily folder | |
set -e | |
cp $sourcedir/out/target/product/$devicename/$filename $HOME/daily/ | |
set +e | |
# Upload | |
set -e | |
if [ "$upload" = "true" ]; then | |
echo -e '\E[37;44m'"\033[1mRemoving old builds...keep only 10 on server\033[0m" | |
# ssh loudbit.co "cd public_html/roms/cm-${version}/${devicename}/ && (ls -t | head -n 10; ls | sort | uniq -u | sed -e 's,.*,"&",g' | xargs rm -f" | |
echo -e '\E[37;44m'"\033[1mUploading...\033[0m" | |
$HOME/.bin/upload $filename roms/cm-$version/$devicename | |
url=`$HOME/.bin/bitly.py http://download.invisiblek.org/roms/cm-$version/$devicename/$filename` | |
url=`echo $url | sed ':a;N;$!ba;s/\n//g'` | |
# Tweet | |
if [ "$tweet" = "true" ]; then | |
echo -e '\E[37;44m'"\033[1mTweeting...\033[0m" \ | |
$HOME/.bin/tweepy "New unofficial cm$version $devicename is available! Download here: $url" | |
fi | |
else | |
echo -e '\E[37;44m'"\033[1mSkipping upload...\033[0m" | |
fi | |
# Spit out an email | |
elapsed=`cat $tempdir/seconds | sed 's/:\([^:]\+\)$/m\1/;s/:/h/;s/\..\...*//;s/$/s/'` | |
echo -e '\E[37;44m'"\033[1mEmailing $destemail\033[0m" | |
$HOME/.bin/email "[email protected]" "$destemail" "New $devicename CM$version Build" "Download: $url\nBuild Time: $elapsed" "invisiblek.org" "[email protected]" | |
echo -e '\E[37;44m'"\033[1mBuild Time: $elapsed\033[0m" | |
# Cleanup | |
rm -rf $tempdir |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment