#!/bin/bash
#
# @author Leandro Dorileo<ldorileo@gmail.com>

BB_VERSION=1.12.0
BB_TARBALL=bitbake-${BB_VERSION}.tar.gz
WORK_DIR=~/work/oe
BUILD_DIR=$WORK_DIR/build
LOCAL_CONF_DIR=$BUILD_DIR/conf

function basic_setup(){
OE_REPO=https://github.com/openembedded/openembedded.git

echo "creating $LOCAL_CONF_DIR"
mkdir -p $LOCAL_CONF_DIR
if [ ! -f $WORK_DIR/$BB_TARBALL ]; then
	wget http://download.berlios.de/bitbake/${BB_TARBALL} -P$WORK_DIR
else
	echo "bitbake already present... avoiding"
fi

if [ ! -d $WORK_DIR/bitbake ]; then
	echo "extracting bitbake..."
	tar --no-recursion -xf $WORK_DIR/$BB_TARBALL -C $WORK_DIR/
	mv $WORK_DIR/bitbake-${BB_VERSION} $WORK_DIR/bitbake
else
	echo "bitbake already present... avoiding"
fi

if [ ! -d $WORK_DIR/openembedded/.git ]; then
	echo "cloning openembedded"
	git clone $OE_REPO $WORK_DIR/openembedded
else
	echo "oe already present... avoiding"
fi
}

function packages_install(){

if [ -f /etc/apt/sources.list ]; then

if [ `whoami` != "root" ]; then 
	echo "you're not root, we're su'ing you, please enter root password..."
fi

	su - -c 'apt-get install sed wget cvs subversion git-core \
   coreutils unzip texi2html texinfo docbook-utils \
   gawk python-pysqlite2 diffstat help2man make gcc build-essential g++ \
   desktop-file-utils chrpath -y'
else
	echo "you're not running an apt based distributiom, sorry we don't support your distro"
	exit 1
fi

}

packages_install
basic_setup

echo "ok. you're all set... have a good hacking ;)"

