#!/bin/sh

if [ ! "$2" = "ci" -a ! "$2" = "add" -a ! "$2" = "remove" -a ! "$2" = "addb" ]
then
  echo invalid cvs command $2
  exit
fi

dir=`dirname $1`
file=`basename $1`

if [ ! -d $dir ] ; then
  echo invalid directory $dir
  exit
fi

cd $dir

if [ -d $file ] ; then
  cvs $2 $file
  exit
fi

if [ ! -f $file ] ; then
  echo file $file does not exist
  exit
fi

if [ "$2" = "addb" ] ; then
  cmd="add"
  opt="-kb"
else  
  cmd=$2
  opt=
fi

if [ "$cmd" = "add" ] ; then
  cvs add $opt $file
  cmd="ci"
fi

if [ "$cmd" = "remove" ] ; then
  sudo rm -f $file
  cvs remove $file
  cmd="ci"
fi

if [ "$3" = "" ] ; then
  cvs $cmd -m "no comments" $file
else
  cvs $cmd -m "$3" $file
fi

cd -

