#!/bin/bash IMP_PATH=$1 OLD_PATH=`pwd` touch svnimport.log # strip trailing slash if it exists REPO1=`echo $IMP_PATH | sed -n -e 's/\(.*\)\/$/\1/p'` if [ "x$REPO1" = "x" ] ; then REPO1=$IMP_PATH fi # grab repo name from last dir/item in path REPO_NAME=`echo $REPO1 | sed -n -e 's/.*\/\([^/]*\)$/\1/p'` # no echo, svncreate echos status ssh -l root boris "/root/svncreate $REPO_NAME" if [ "$?" -ne "0" ] ; then echo Repository creation failed. exit $? fi echo Creating temporary directory. TEMP_DIR=`mktemp -d` if [ "$?" -ne "0" ] ; then echo failed. exit $? fi echo Creating repository layout. mkdir $TEMP_DIR/trunk if [ "$?" -ne "0" ] ; then echo failed. exit $? fi mkdir $TEMP_DIR/branches if [ "$?" -ne "0" ] ; then echo failed. exit $? fi mkdir $TEMP_DIR/tags if [ "$?" -ne "0" ] ; then echo failed. exit $? fi echo Copying files to temporary repository trunk directory. cp -R $IMP_PATH/* $TEMP_DIR/trunk if [ "$?" -ne "0" ] ; then echo failed. exit $? fi echo Cleaning unneeded files. cd $TEMP_DIR if [ -e "cbuild.c" ] ; then ./cbuild.c clean fi find "$TEMP_DIR" -iname ".svn" | xargs rm -fr if [ -e "Makefile" ] || [ -e "makefile" ] || [ -e "MAKEFILE" ] ; then make clean 2>&1 >/dev/null fi find "$TEMP_DIR" -iname "*~" -o -iname "*.o" -o -iname "*.a" -o -iname "*.so" -o -iregex "core\.\d+" -delete cd $OLD_PATH echo Importing new tree into repository. svn import -m "Initial import" $TEMP_DIR http://svn.tomasu.org/repos/$REPO_NAME > svnimport.log if [ "$?" -ne "0" ] ; then echo failed. exit $? fi echo Removing temporary directory. rm -fr $TEMP_DIR if [ "$?" -ne "0" ] ; then echo failed. exit $? fi echo Backing up original directory. cp -a $IMP_PATH $IMP_PATH.old if [ "$?" -ne "0" ] ; then echo failed. exit $? fi rm -fr $IMP_PATH echo Setting up local svn files. mkdir ${IMP_PATH}.svnco svn co --non-interactive http://svn.tomasu.org/repos/$REPO_NAME/trunk ${IMP_PATH}.svnco >> svnimport.log if [ "$?" -ne "0" ] ; then echo failed. mv $IMP_PATH.old $IMP_PATH rm -fr $IMP_PATH.svnco exit $? fi echo Moving checked out directory to final location. mv ${IMP_PATH}.svnco ${IMP_PATH} if [ "$?" -ne "0" ] ; then echo failed. rm -fr ${IMP_PATH}.svnco rm -fr ${IMP_PATH} mv ${IMP_PATH}.old ${IMP_PATH} exit $? fi rm -fr $IMP_PATH.old