#!/bin/sh
#
# Module: vc-clone 
#
# Description:
#   Script that automates the installation and configuration of a vc build
#   according to README in build-iso directory.
#
# Author: Jon Andersson
# Date:   2008
#

if [ ! -n "$1" ]
then
  echo "Usage: $0 <src> Branch [full]"
  echo "<src> is where to pull from (and over what protocol)"
  echo "Branch to use: e.g. islavista|jenner|kenwood| etc."
  echo "Optional parameter <full> to do verification build."
  exit 0
fi

build=" "
master=$1
branch=$2
build=$3

# Possible UPDATE: check what branches are valid before installing

case "$branch" in

  "glendale"|"hollywood"|"islavista"|"jenner"|"kenwood"|"larkspur" )
	echo "===> Branch $branch used."
  ;;

  * )
	echo "===> Branch $branch not recognised."
	exit 1
  ;;
esac

case "$master" in
    "vyatta")
	master="http://git.vyatta.com/build-iso.git"
	;;
    * )
	
        # Test if destination directory already exists. 
	if [ ! -e "$master" ]
	then
	    echo "===> Directory $master does not exist. Please re-specify."
	    exit 1
	fi
	;;
esac

echo "===> git-clone $master <==="
git-clone $master
cd build-iso
echo "===> git branch --track $branch origin/$branch <==="
git branch --track $branch origin/$branch
echo "===> git checkout $branch <==="
git checkout $branch
echo "===> git submodule init <==="
git-submodule init

if [ "$build" ==  "full" ]
then
    echo "===> Verification Build <==="
    echo "===> git submodule update <==="
    git-submodule update

    echo "===> create branch for each submodule <==="
    submodules=$(git-submodule | awk '{print $2}')
    for module in $submodules
    do
	cd $module
	git-checkout --track -b $branch origin/$branch
	cd ../../
    done
fi

echo "===> autoreconf <==="
autoreconf -i

echo "===> configure <==="
./configure --with-target-dist=lenny

exit 0
