#!/usr/bin/env bash
# Only clone the repo if it doesn't already exist in $pwd
if [ ! -d "linux-bananapi" ]; then
    git clone -b bananapi-3.4 https://github.com/LeMaker/linux-bananapi.git
fi

cd linux-bananapi
# Update repo; only really useful if it already exists
git pull
# fetch kernel config
wget http://watchmysys.com/blog/wp-content/uploads/2014/08/linux-bananapi.config -O .config
# make clean just in case this isn't a clean tree
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- clean
# build the kernel and modules
make -j4 ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- uImage modules
# install to ./modules
make ARCH=arm CROSS_COMPILE=arm-linux-gnueabihf- INSTALL_MOD_PATH=output modules_install
# create directory structure
mkdir -p output/boot/
# copy kernel
cp arch/arm/boot/uImage output/boot/
# create archive
tar -C output -cjvf ../linux-bananapi-3.4.90.tar.bz2 boot/ lib/
