#!/bin/sh ######################################################################### # # FILE : cvsupdate # DATE : 10.07.2001 # AUTHOR : Patrick Meier / patrick.meier@profidatagroup.com # DESCRIPTION : update files from the cvs # # Copyrigth (C) 2001 by Patrick Meier, Switzerland # ######################################################################### PN=`basename "$0"` CVS=/usr/local/bin/cvs-1.11.1p1-SUNOS-5.6 CVSBIN="`echo \"$CVS\" | sed 's/.*\/.*\///g'`" CVSPARAMETER="-d -P -C -A" STARTSTRING="==>" export CVS ######################################################################### # getCVSHelp ######################################################################### getCVSHelp() { tag="$1" help="`$CVS $tag --help 2>&1 \ | sed \"s/$tag: invalid option -- -//g\" \ | sed 's/diff: unrecognized option \`--help//g;' \ | sed \"s/Usage:*//g\" \ | sed \"s/$CVSBIN $tag //g\" \ | sed \"s/-d/-dir/g\" \ | sed \"s/\'//g\" \ | sed \"s/(Specify the --help global option for a list of other help options)//g\"`" command="`echo $help | sed \"s/\[files.*/ \[files\.\.\.\]/\"`" description="`echo "$help" | sed \"s/.*\[.*\]//g\"`" echo $command echo "$description" } ######################################################################### # Usage ######################################################################### Usage() { echo "$PN - update files from the cvs" printf "usage: $PN " getCVSHelp update exit 1 } ######################################################################### # ParameterFailed ######################################################################### ParameterFailed() { echo "${STARTSTRING}Parameter faild: $1 ..."; echo "" Usage } ######################################################################### # cutEndSlash ######################################################################### cutEndSlash() { echo $@ | awk ' { text=$0; while( substr( text, length(text),1 ) == "/" ) { text=substr( text, 1, length(text)-1 ); } print text; }' } ######################################################################### # cutEndSlash ######################################################################### getFileName() { echo $@ | awk ' { text=$0; while( substr(text, length( text ),1) == "/" ) { text=substr(text, 1, length(text)-1 ); } for( i=length( text ); i>=1; i-- ) { if( substr( text, i,1) == "/" ) { text=substr( text, i+1, length( text )-i ); break; } } print text; }' } ######################################################################### # complete a given path # tested with: # completePath ../../kkk.c # completePath ../././kkk.c # completePath dsd/dd/dd.c # completePath ../../kkk.c /home/hh/dd/ ######################################################################### completePath() { if [ -z "$2" ] then initPath=`pwd` else initPath=`cutEndSlash $2` fi echo "$initPath $1" | awk ' { mainPath=$1 i=0; backPath=0; num=split( $2, separatedText, "/" ); numMainPath=split( $1, mainPathSeparated, "/" ); fileName="" for( i=1; i <=num; i++ ) { if( separatedText[ i ] == ".." ) backPath++; } for( i=1; i<=numMainPath-backPath; i++ ) { if( length( fileName )==0 ) fileName=mainPathSeparated[ i ]; else fileName=fileName"/"mainPathSeparated[ i ]; } for( i=backPath+1; i<=num; i++ ) { if( separatedText[ i ] != "." ) { if( length( fileName )==0 ) fileName=separatedText[ i ]; else fileName=fileName"/"separatedText[ i ]; } } print "/"fileName }' } ######################################################################### # get all cvs editors ######################################################################### getEditors() { $CVS editors | awk ' { print $2" ("$3" "$4" "$5" "$6" "$7")\t"$1 }' } ######################################################################### # get all cvs editors ######################################################################### getOwnerOfLockedFiles() { fileToEdit="`completePath $1`" cvsLine=`$CVS editors | grep "$1" | awk '{print $2" "$1}'` if [ -z "$cvsLine" ] then return else lockedUser="`echo $cvsLine | awk '{print $1}'`" cvsFileName="`echo $cvsLine | awk '{print $2}'`" cvsFullName=`completePath $cvsFileName` #echo "<$lockedUser> <$cvsFileName> <$cvsFullName>" fi if [ "$fileToEdit" = "$cvsFullName" ] then echo $lockedUser fi } ######################################################################### # get all cvs editors ######################################################################### getLockedFilesByCurrentEditor() { cvsLine=`$CVS editors | grep "$1" | awk '{print $2" "$1}'` if [ -z "$cvsLine" ] then return else lockedUser="`echo $cvsLine | awk '{print $1}'`" cvsFileName="`echo $cvsLine | awk '{print $2}'`" cvsFullName=`completePath $cvsFileName` #echo "<$lockedUser> <$cvsFileName> <$cvsFullName>" fi echo $cvsFullName } ######################################################################### # get all cvs editors ######################################################################### doCVSUpdateFile() { user="`who am i | awk '{print $1}'`" lockedUser="`getOwnerOfLockedFiles $1`" if [ -z "$lockedUser" ] then echo $CVS update $CVSPARAMETER $1 $CVS update $CVSPARAMETER $1 else if [ "$user" = "$lockedUser" ] then echo "${STARTSTRING}You have checked out the file $1! Please check in the file first before you update!" else : # File is locked by $lockedUser fi fi } ######################################################################### # main ######################################################################### while [ $# -gt 0 ] do case "$1" in -h) Usage; exit 1;; -help) Usage; exit 1;; --help) Usage; exit 1;; -k) if [ $# -gt 1 ] ; then CVSPARAMETER="$1 $2 $CVSPARAMETER"; shift; else ParameterFailed $1; fi;; -r) if [ $# -gt 1 ] ; then CVSPARAMETER="$1 $2 $CVSPARAMETER"; shift; else ParameterFailed $1; fi;; -j) if [ $# -gt 1 ] ; then CVSPARAMETER="$1 $2 $CVSPARAMETER"; shift; else ParameterFailed $1; fi;; -I) if [ $# -gt 1 ] ; then CVSPARAMETER="$1 $2 $CVSPARAMETER"; shift; else ParameterFailed $1; fi;; -W) if [ $# -gt 1 ] ; then CVSPARAMETER="$1 $2 $CVSPARAMETER"; shift; else ParameterFailed $1; fi;; -*) CVSPARAMETER="$1 $CVSPARAMETER";; *) break;; esac shift done param="$@" if [ -z "$param" ] then user="`who am i | awk '{print $1}'`" lockedFiles="`getLockedFilesByCurrentEditor $user`" if [ -z "$lockedFiles" ] then $CVS update $CVSPARAMETER $@ else echo "${STARTSTRING}You have checked out some files! Please check in the file first before you update!" fi else for i in $@ do doCVSUpdateFile $i done fi ######################################################################### # EOF #########################################################################