#!/bin/bash
#
#   FILE: cvs_delete_dir
# AUTHOR: Gratien D'haese <gdha@it3.be>
#   DATE: 30 October 2002
# Copyright (C) 2002 Gratien D'haese
# All rights reserved.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

# Simple script to add/commit a new directory recursively into cvs
# Script assumes CVSROOT is set as an environment variable.
# script take one argument (directory name)

# currently script assumes you are in the CVSROOT directory of your project
# set DEBUG=echo to enable debug mode (echo the line instead of exec)
#DEBUG=echo
DIR=$1

if [ ! -d "$DIR" ]; then
   echo "Directory $DIR not found."
   exit 1
fi

# first we remove all the files recursively under $DIR
$DEBUG cvs remove -f -R $DIR
$DEBUG cvs commit -f -R -m \'remove $DIR\' $DIR

# do a cvs remove of all directories found recursively
i=0
for dirs in `find $DIR -type d | grep -v CVS`
do
    if [ $i -eq 0 ]; then
	# skip top directory (do as last item)
	i=1
    else
	# remove first all subdirectories
	echo Removing $dirs to the CVS tree
	$DEBUG cvs remove $dirs
	$DEBUG cvs commit -m \'remove $DIR\' $dirs
    fi
done
$DEBUG cvs remove $DIR
$DEBUG cvs commit -m \'remove $DIR\' $DIR
echo "$DIR has been removed."
echo "Synchronize CVS tree:"
cvs -q update
