#!/bin/bash # # $Id: rvi,v 1.2 2002/08/13 04:40:42 kevino Exp $ # # Copyright 2002 Kevin O'Donnell # # 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 declare -i RECURSE=0 find_sym_source() { RECURSE=$RECURSE+1 echo starting with $FILE DIRNAME=`dirname $FILE` BASENAME=`basename $FILE` cd $DIRNAME if [ -h $BASENAME ]; then echo $BASENAME is a sym if [ $RECURSE == 10 ]; then echo 10 deep exit fi FILE=`ls -lF $BASENAME | awk ' BEGIN { FS = " " } { print $11 } '` echo now using $FILE find_sym_source; fi } # set an editor if there isn't one already if [ -n "$EDITOR" ]; then EDITOR=`which vi` fi # find ci CI=`which ci` if [ ! -n "$CI" ]; then echo "ERROR: could not find 'ci'; check $PATH" exit 1 fi # fine rcs RCS=`which rcs` if [ ! -n "$RCS" ]; then echo "ERROR: could not find 'rcs'; check $PATH" exit 1 fi # remember the current directory PWD=`pwd` # set FILE to the file we want to edit FILE=$1 # follow symlinks if necessary find_sym_source; # check the RCS directory if [ ! -e RCS ]; then # nothing by the name of RCS exists mkdir RCS if [ $? -ne 0 ]; then echo "ERROR: failed to make RCS directory" exit 1 fi chmod g+w RCS if [ $? -ne 0 ]; then echo "ERROR: failed to make RCS directory group writable" fi else # something by the name of RCS exists if [ ! -d RCS ]; then # RCS is not a directory echo "ERROR: $DIRNAME/RCS exists but is not a directory" exit 1 else # good, it is a directory if [ ! -w RCS ]; then # it's not writable chmod u+w RCS if [ $? -ne 0 ]; then echo "ERROR: failed to make RCS directory user writable" exit 1 fi chmod g+w RCS if [ $? -ne 0 ]; then echo "ERROR: failed to make RCS directory group writable" exit 1 fi fi if [ ! -x RCS ]; then # it's not executable chmod u+x RCS if [ $? -ne 0 ]; then echo "ERROR: failed to make RCS directory user executable" exit 1 fi chmod g+x RCS if [ $? -ne 0 ]; then echo "ERROR: failed to make RCS directory group executable" exit 1 fi fi fi fi # check RCS status of file if [ ! -e $BASENAME ]; then # editing a new file, create an empty version touch $BASENAME # since the basename doesn't exist, remove any entries in the RCS tree if [ -e "RCS/$BASENAME,v" ]; then DATE=`date "+%Y-%m-%d-%H-%M-%S"` mv "RCS/$BASENAME,v" "RCS/$BASENAME-$DATE,v" fi fi if [ ! -e "RCS/$BASENAME,v" ]; then # no RCS log exists, to initial checkint echo "" echo "Entering $BASENAME into RCS repository" echo "" echo "" | ci -u $BASENAME rcs -U $BASENAME chmod u+w $BASENAME chmod g+w $BASENAME fi # edit the file $EDITOR $BASENAME # check in any changes ci -u $BASENAME chmod u+w $BASENAME chmod g+w $BASENAME # finished, return to old directory cd $PWD