#!/bin/sh
to=`eval echo \\\${$#}`

movefile () {
  mv $1 $2 && \
  (cd `dirname $1` && cvs remove `basename $1`) && \
  (cd `dirname $2` && cvs add `basename $2`) && \
  cvs commit -m "Rename $1 to $2" $1 $2 || \
  echo "moving $1 to $2 failed" >&2
}

if [ -d $to ]; then
  if [ $# -lt 2 ]; then
    echo too few arguments >&2
    exit 1
  fi

  cnt=1
  while [ $cnt -lt $# ]; do
    file=`eval echo \\\${$cnt}`
    cnt=`expr $cnt + 1`
    if [ -d $file ]; then
      echo moving directories not supported yet, skipping >&2
    else
      movefile $file $to/`basename $file`
    fi
  done
elif [ $# -gt 2 ]; then
  echo too many arguments >&2
  exit 1
else
  movefile $1 $to
fi
exit 0
