#!/bin/sh

SVN_REPOS=/experimental
SVN_CHECKOUT=$HOME/experimental

# ---------------------------------------------------------------------------

CVS_TARBALL=skyeye-cvsroot.tar.gz
CURRENT_DIR=`pwd`

if [ ! -f $CURRENT_DIR/resync-with-skyeye.sh ]; then
  echo "ERROR: Please check working directory, where this script locates."
  exit
fi

if [ ! -f $CVS_TARBALL ]; then
  wget http://download.gro.clinux.org/__tarballs/$CVS_TARBALL
fi

if [ ! -f $CVS_TARBALL ]; then
  echo "ERROR: Cannot fetch skyeye cvs tarball."
  exit
fi

# Decompress the tarball, and rename
tar zxvf $CVS_TARBALL
cd skyeye
# perform the permission changes
find -type d | xargs chmod +w
cd $CURRENT_DIR
chmod +x skyeye
cp -af skyeye/skyeye-v1 .
rm -rf skyeye
mv skyeye-v1 skyeye

# Examine if there is already skyeye in svn repository
cd $SVN_CHECKOUT
svn update skyeye
if [ -d skyeye/.svn ]; then
  svn remove --force skyeye
  svn commit -m "Remove old copy of Skyeye" skyeye
fi

# Convert cvs repository to svn one
cd $CURRENT_DIR
cvs2svn \
	--trunk-only --existing-svnrepos \
	--trunk=skyeye \
	-s $SVN_REPOS skyeye

# Automatically svn checkout
cd $SVN_CHECKOUT
svn update skyeye
