#!/bin/sh # # $TOOLS/replace # # replace - Wrapper script for "ci" # Purpose: # 1) Using "ci", check code into a common source tree from the # current working dir. # 2) The common source tree takes the form $RCSLIBR/RCS/file,v # where "file" is the argument passed on the command line. # 3) The program will also be copied to $RCSLIBR/file. This assumes that # the user running this program is in the rcssys group and that the # $RCSLIBR directory's files have rwx access to the group and that # their group is rcssys. # # Syntax: replace program_name # # Requirements: # 1) The rcs source tree must be compatible with that used by # the tools replace and reserve (Ex: $RCSLIBR/RCS/*,v) # 2) The environment variable RCSLIBR must have been previously defined by # using the "lib" command. # 3) To create or access an RCS library, the user must be in the rcssys # group, and the library's parent directory must have R/W access for # the rcssys group. # # Environment Variable: # $RCSLIBR = Dir where we can find "program" dir # # Modified: # 02/22/96 Brian Lomasky - Skip protection mod if in RCSLIBR dir and not in RCS. # 02/21/96 Brian Lomasky - Force mode of copied file to be 775. Add debug text. # 02/20/96 Brian Lomasky - Force mode of RCS library to be 775 # 02/05/96 Brian Lomasky - Skip softlink if original form already renamed # 01/26/96 Brian Lomasky - Use RCSLIBR for SrcDir. Add missing exit_proc # to error_proc function. Verify for valid RCSLIBR. # Allow case-insensitive Y/N. Reformat text. Remove # bad "SwText=" line. Remove redundant "if" test. # Process only the file specified in the $1 param. # Verify for existing file. Added text video # attributes. Set required file permissions and # group. Change format of RCS library tree. # Also copy file to application directory. Set file # owner. # #-------------------------------------------------------------------------- Prg=replace if [ "$DEBUG" != "" ]; then set -x; fi error_proc() #Sub-routine { case "$ErrNo" in 1) echo "\nError - You must specify the program to be replaced.\n" echo "Usage: $Prg program-name";; 2) echo "\nThe program will ${b}NOT${n} be replaced...";; 3) echo "\nError - Can't find file: ${b}$Program${n}";; 4) echo "\nError - Can't create RCS library in $RCSLIBR\n";; 5) echo "\nError - Can't replace $Program" echo " In order to replace a program that has been under RCS" echo " control, you must have previous reserve'd it with the -l" echo " option, so as to lock the file for future modifications";; *) echo "\n\nUnknown error $ErrNo .......";; esac RtrnCode=1 exit_proc } #-------------------------------------------------------------------------- exit_proc() #Sub-routine { test -h RCS && /bin/rm RCS #If tmp symbolic link exits, delete it /bin/rm -f /tmp/$Prg$$ echo "" exit $RtrnCode } #-------------------------------------------------------------------------- # Main program flow b=`tput smso` # Bold video attribute n=`tput rmso` # Normal video attribute echo "\nREPLACE is used to Create a new or Update an existing RCS library" umask 2 ErrNo=0 RtrnCode=0 if [ "$RCSLIBR" = "" ] then echo "\n\nError - You must first indicate the RCS library" \ "to be accessed.\n" echo " (This is done by typing: ${b}L=SOURCE${n}" echo " ${b}. lib${n}" echo " where \$SOURCE is the complete path to the program" echo " directory which will contain the file.)\n" echo " Example: L=SOURCE\n" echo " . lib" exit 1 fi if [ $# -eq 0 ]; then ErrNo=1 # No parameters supplied error_proc fi Program=$1 if [ ! -r $Program ]; then ErrNo=3 # No such file error_proc fi echo "with the contents of the ${b}${Program}${n} program.\n" echo "The program will also be copied to ${RCSLIBR}\n" # Calculate current file permissions for Program # PROG=$Program # . mode # RcsRev="`date +R%y%m%d`" # enable retrieval by date SwText="-t/tmp/$Prg$$" # if never ci'd before, need desc text echo "$Program" > /tmp/$Prg$$ # #-------------------------------------------------------------------------- if [ ! -d $RCSLIBR/RCS ]; then echo "" echo "The ${b}${RCSLIBR}${n} RCS library doesn't exist" YN="" while [ "$YN" != "Y" -a "$YN" != "N" ]; do echo " Do you ${b}REALLY${n} want to create it ? \c" read YN if [ "$YN" = "" ]; then YN="N" fi YN=`echo $YN | tr '[a-z]' '[A-Z]'` done if [ "$YN" = "N" ]; then ErrNo=2 #Aborting error_proc else mkdir $RCSLIBR/RCS if [ $? -ne 0 ]; then ErrNo=4 error_proc fi chmod 770 $RCSLIBR/RCS chgrp rcssys $RCSLIBR/RCS fi fi ProgExists=0 if [ -f $RCSLIBR/RCS/${Program},v ]; then NewElement=0 else NewElement=1 if [ -r $RCSLIBR/${Program} ]; then echo "\nWarning: A ${b}${Program}${n} already exists in" \ "${b}${RCSLIBR}${n}," echo " but is ${b}NOT${n} in the RCS library" \ "!!\n\007" ProgExists=1 fi fi #-------------------------------------------------------------------------- if [ "$NewElement" -eq 0 ] then echo "\nDescribe the change that you have made to this file:" else echo "\nDescribe why you are inserting this new file into RCS:" fi LogMsg="" while [ "$LogMsg" = "" ]; do read LogMsg done # if [ "$NewElement" -eq 0 ] then echo "\nCopying modified program..." cp $Program $RCSLIBR chmod 775 $RCSLIBR/${Program} chgrp rcssys $RCSLIBR/${Program} echo "Updating program in RCS..." ci -q -f -m"$LogMsg" -N"$RcsRev" $RCSLIBR/RCS/${Program},v if [ $? -ne 0 ] then ErrNo=5 # Unexpected error occurred error_proc fi chmod 775 $RCSLIBR/RCS/${Program},v chgrp rcssys $RCSLIBR/RCS/${Program},v echo "\n${b}${Program}${n} has been copied to $RCSLIBR" echo " and has been replaced in RCS..." else echo "\nNew program ${b}${Program}${n} will be inserted into the" \ "${b}${RCSLIBR}${n} library" echo " with a log message of: ${b}$LogMsg${n}\n" | fold YN="" while [ "$YN" != "Y" -a "$YN" != "N" ]; do echo " Do you want to continue ? \c" read YN YN=`echo $YN | tr '[a-z]' '[A-Z]'` done if [ "$YN" = "N" ]; then ErrNo=2 #Aborting error_proc fi if [ -f $RCSLIBR/${Program} ]; then echo "\nDisplaying info about existing ${Program} program..." ls -l $RCSLIBR/${Program} echo "" fi echo "\nCopying program..." cp $Program $RCSLIBR if [ "$ProgExists" -eq 0 ] then echo "Setting program access..." chmod 775 $RCSLIBR/${Program} echo "Setting program group access..." chgrp rcssys $RCSLIBR/${Program} fi echo "Inserting program into RCS..." ci -q -f $SwText -r1.1 -m"$LogMsg" -N"$RcsRev" $RCSLIBR/RCS/${Program},v if [ $? -ne 0 ]; then ErrNo=5 error_proc fi echo "Setting library access..." chmod 775 $RCSLIBR/RCS/${Program},v echo "Setting library group access..." chgrp rcssys $RCSLIBR/RCS/${Program},v echo "\n${b}${Program}${n} has been copied to $RCSLIBR and stored in" \ "RCS..." fi exit_proc