#!/bin/bash

## Create minimal developement environment for NEMO
###################################################

## Optional arguments
## - $1: developer ID
## - $2: 'repo' to replicate the layout of whole repository

dir='NEMO_dev'

if [ "$2" == 'repo' ]; then root='/'; else root='/NEMO'; fi

## Copy of the repository with empty root directories
echo 'Checkout the repository from' $root
svn co --depth empty http://forge.ipsl.jussieu.fr/nemo/svn/$root $dir
echo

## Switch to developer role if ID is provided
if [ -n "$1" ]; then
    echo 'Switch from user to developer role (http:// => svn+ssh://)'
    ssh-copy-id -i ~/.ssh/id_rsa.pub $1@forge.ipsl.jussieu.fr 2> /dev/null
    svn sw --relocate    http://forge.ipsl.jussieu.fr                       \
	              svn+ssh://$1@forge.ipsl.jussieu.fr/ipsl/forge/projets \
	NEMO_dev
    echo
fi

if [ "$2" == 'repo' ]; then
    echo "With 'repo' arg, create a lightweight copy of the repository"
    echo "for the developement of the sources used as 'externals'"

    for item in utils/build/{arch,makenemo,mk} utils/tools       \
		vendors/{AGRIF/dev,AGRIF/release-4.0,FCM,IOIPSL}  ; do
#		vendors/{AGRIF/dev,AGRIF/stable,FCM,IOIPSL}  ; do
	echo '¤' $item
	svn up -q --parents $dir/$item
    done
	
    dir=$dir/'NEMO'
    echo
fi

## Get the 1st level tree under 'branches' and 'releases'
echo "Get empty development folders under '/NEMO/branches':" {UKMO,2018,2019}
svn up -q --set-depth empty --parents $dir/branches/{UKMO,2018,2019}
echo

## Download trunk and last release
echo 'Full download of 2 main branches'
echo "¤ '/NEMO/trunk'"
svn up -q           $dir/trunk

echo "¤ latest in '/NEMO/releases'"
svn up -q --parents $dir/releases/release-4.0

exit 0
