Thursday, September 1, 2011

Autobuild script

Put the following script in crontab
crontab -e

*/10 * * * * ~/autobuild

crontab -l

should see the added task


!/bin/bash
#If the startbuild file is changed within 300 seconds, 
#We will start build flashplayer automatically

#The threshold time that file is modified, we will build
TIME=300
FILE="startbuild"
DATE=(`stat -c %y $FILE| cut -d ' ' -f1`)
#DATE=(`stat -c %y $FILE| awk '{printf $1}')

LOG="/tmp/$FILE$DATE.log"
LOCK="/tmp/lockfile"
t1=(`stat -c %Y $FILE`)
t2=(`date +%s`)
gap=$(($t2-$t1))

function buildfp() {
	touch $LOCK
	cd /jian/koobe
	. build/envsetup.sh 
	chooseproduct VTAB1008
	cd $1/flash/code/products/player/android
	make TARGET_ARCH=ARMV7-A MAKECMDGOALS=release DISABLE_UYVY422_BUFFER=1   USE_AAC_SWCODEC=1  >> $LOG
	cp  $1/flash/code/build/android/results/plugin/ARMV7-A/Release/install_flash_player.apk $2
	rm $LOCK
}

#create log file if it doesn't exist
if [ ! -f $LOG ]; then
	touch $LOG
fi

if [ $gap -lt $TIME ]; then
	if [ -f $LOCK ]; then 
		echo "Another autobuild job is running, skip" > $LOG
	else
		echo "File have been modified in $gap seconds, so start building..." >$LOG
		buildfp /jian/FP103 /tmp
		echo "Finish build!!!" >> $LOG;
	fi
else
	echo "File modified $gap seconds ago, do nothing" > $LOG;
fi