view cds-mv @ 43:7fc785a79615

renamed penis to churn
author Josef "Jeff" Sipek <jsipek@cs.sunysb.edu>
date Sat, 05 May 2007 15:53:53 -0400
parents 46317d48ef24
children
line wrap: on
line source

#!/bin/bash

PROG=`basename $0`

#########################################
## Takes two arguments, the source and ##
## destination,and effects the move in ##
## a safe, version tracked way         ##
#########################################

function do_move
{
	SRC="$1"
	DEST="$2"
	RETVAL=0

	#Perform the move in a fail-safe way

	#Copy first (well -- really link, and track)
	ln "$SRC" "$DEST" >& /dev/null || return $?

	cvs add "$DEST"  >& /dev/null
	RETVAL=$?
	if [ $RETVAL != 0 ]; then
		#cleanup old file
		rm "$DEST" >& /dev/null
		printf "Unable to add $DEST to CVS\n" >&2
		return $RETVAL
	fi

	#Clean up old, and track removal
	rm -f "$SRC" >& /dev/null
	RETVAL=$?
	if [ $RETVAL != 0 ]; then
		rm "$DEST" >& /dev/null
		cvs rm "$DEST" >& /dev/null
		printf "Unable to add $DEST to CVS\n" >&2
		return $RETVAL
	fi

	cvs rm "$SRC" >& /dev/null
	RETVAL=$?
	if [ $RETVAL != 0 ]; then
		ln "$DEST" "$SRC" >& /dev/null
		rm "$DEST" >& /dev/null
		cvs rm "$DEST" >& /dev/null
		printf "Unable to add $DEST to CVS\n" >&2
		return $RETVAL
	fi

	return 0
}


if [ $# -eq 2 ]; then
	do_move "$1" "$2"
	exit $?
elif [ $# -gt 2 ]; then

	#Handle the "generic" case, where the last entry will be a directory
	ARGCNT=0
	declare -a ARGVEC
	for ARG in "$@"; do
		ARGVEC[ $ARGCNT ]= "$ARG"
		ARGCNT=$(( $ARGCNT+1 ))
	done
	DEST="$ARGVEC[ $ARGCNT ]"
	ARGCNT=$(( $ARGCNT-1 ))

	if [ ! -d "$DEST" ]; then
		printf "$PROG: $DEST is not a directory.\n"
	fi

	i=0
	while [ i < $ARGCNT ]; do
		SRC="$ARGVEC[ $i ]"
		do_move "$SRC" "$DEST"
		i= $(( $i + 1 ))
	done
	exit 0
else
	printf "$PROG: Please use good arguments.\n"
fi