#!/bin/sh # # $TOOLS/reserve # # reserve - Use RCS to "check out" code from a source dir tree # # Syntax: reserve [-r] [-f] [-s xxx] program_name # Purpose: # 1) Exec an rcs "co" of the desired program # 2) Arg -r will "rcs lock" the code, else, its co'd in read only mode # 3) Arg -f will not prompt for args ("batch" mode) # 4) Arg -s xxx will co only a specific rev, else, latest rev # # Requirements: # 1) The rcs source tree must be compatible with that used by # the tools replace and reserve (Ex: $RCSLIBR/RCS/file,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. # 4) The "mode" script must exist and be found in the PATH. # # Environment Variables: # $RCSLIBR = Dir where we can find "program" dir # # Modified: # 01/25/96 Brian Lomasky - Use RCSLIBR for SrcDir. Add missing exit_proc # to error_proc function. Verify for valid RCSLIBR. # Reformat text descriptions. Allow case-insensitive # Y/N. Added text video attributes. Set required # file permissions. Reformat RCS library tree. # Rename command options. # #-------------------------------------------------------------------------- if [ "$DEBUG" != "" ]; then set -x; fi ErrorProc () #Sub Routine { case $ErrNo in 1) echo "\nUSAGE: reserve [-r] [-f] [-s xxx] program-name" echo " -r will lock (i.e. Reserve) the code so that you can" echo " change it and replace it, otherwise, the file will be" echo " fetched in read-only mode" echo " -f will fetch a copy of the code in read-only mode" echo " -s xxx will fetch only revision xxx, else, latest revision";; 2) echo "\nError - No program specified" echo "\nUSAGE: reserve [-r] [-f] [-s xxx] program-name" echo " -r will lock (i.e. Reserve) the code so that you can" echo " change it and replace it, otherwise, the file will be" echo " fetched in read-only mode" echo " -f will fetch a copy of the code in read-only mode" echo " -s xxx will fetch only revision xxx, else, latest revision";; 3) echo "\nError - There is no RCS library for ${b}$RCSLIBR${n}";; 4) echo "\nError - Can't check out ${b}$Program${n}";; 5) echo "\nError - ${b}$Program${n} can not be found in RCS";; 6) echo "\nError - ${b}$Program${n} already exists in your default" \ "directory" echo " You first first delete or rename the existing file" echo " before you can reserve a new version from RCS";; *) echo "\n\nUnknown error $ErrNo.......";; esac RtrnCode=1 exit_proc } #-------------------------------------------------------------------------- exit_proc () #Sub Routine { exit $RtrnCode } #-------------------------------------------------------------------------- # Main Program Flow b=`tput smso` # Bold video attribute n=`tput rmso` # Normal video attribute echo "\nRESERVE is used to Fetch or Reserve a program from an existing RCS" \ "library\n" ErrNo=0 Lock="" RtrnCode=0 if [ "$RCSLIBR" = "" ] then echo "\nError - You must first indicate the RCS library to be accessed." echo "" 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 containing the RCS library.)\n" echo " Example: L=SOURCE\n" echo " . lib" exit 1 fi Program="" RcsRev="" CoJustLastestRev="" # if [ $# = 0 ]; then ErrNo=1 # No parameters supplied ErrorProc fi #-------------------------------------------------------------------------- # process command line arguments while [ "$1" != "" ]; do if [ "$1" = "-r" ]; then Lock="-l" # RCS lock the code elif [ "$1" = "-f" ]; then Fetch=1 # Fetch a copy of the code elif [ "$1" = "-s" ]; then RcsRev=$2 # RCS revision level specified shift else Program=$1 # must be program name fi shift done if [ "$Program" = "" ]; then ErrNo=2 # No program specified ErrorProc fi if [ ! -d $RCSLIBR/RCS ]; then ErrNo=3 # No such dir ErrorProc fi if [ ! -r $RCSLIBR/RCS/$Program,v ]; then ErrNo=5 # Not under RCS ctrl ErrorProc fi if [ -r $Program ]; then ErrNo=6 # File already exists ErrorProc fi # Calculate current file permissions for Program stored in RCS PROG=$RCSLIBR/RCS/$Program,v . mode if [ "$Lock" = "" -a "$Fetch" = "" ]; then # Determine if a "lock" should be placed on the code YN="" while [ "$YN" != "Y" -a "$YN" != "N" ]; do echo "\nDo you want to ${b}lock${n} (i.e. Reserve) this" \ "program so that you can ${b}edit${n} it and" echo " then later replace it back into the RCS library" \ " (Default of n)? \c" read YN if [ "$YN" = "" ] then YN="N" else YN=`echo $YN | tr '[a-z]' '[A-Z]'` fi done if [ "$YN" = "Y" ]; then Lock="-l" else echo "\nThis code will ${b}NOT${n} be locked against" \ "simultaneous changes..." fi fi #-------------------------------------------------------------------------- #If desired RCS rev not provided, retrieve latest RCS rev of any code if [ "$RcsRev" = "" ]; then CoJustLastestRev="1" RcsRev=`rlog $RCSLIBR/RCS/$Program,v | grep head: | \ awk '{print $2}' | sort -n -r | head -1` else # this is how RCS works, if desired rev not found...prior rev is CO'd if [ "$Lock" = "" ]; then echo "\nAll code <= RCS rev $RcsRev will be fetched..." else echo "\nAll code <= RCS rev $RcsRev will be reserved..." fi fi #-------------------------------------------------------------------------- # check out each file matching the RCS rev level we want for file in `ls $RCSLIBR/RCS/$Program,v`; do if [ "$CoJustLastestRev" = "1" ]; then CkVer=`rlog $file | grep head: | awk '{print $2}'` if [ "$CkVer" = "$RcsRev" ] then co -q $Lock $file if [ $? -ne 0 ]; then ErrNo=4 ErrorProc fi chmod $mode $Program chmod $mode $file fi else co -r$RcsRev $Lock $file #User spec'd rev, CO code <= rev if [ $? -ne 0 ]; then ErrNo=4 ErrorProc fi chmod $mode $Program chmod $mode $file fi echo "\n${b}${Program}${n} has been created in your default" \ "directory..." done exit_proc