s i s t e m a o p e r a c i o n a l m a g n u x l i n u x | ~/ · documentação · suporte · sobre |
Next
Previous
Contents
24. sunlockNOTE : Korn shell /bin/ksh is got by installing pdksh*.rpm from Linux contrib cdrom Save this file as text file and chmod a+rx on it.
#!/bin/ksh # CVS program sunlock # Program to unlock the file to release the lock done by sedit # Every filename is composed of 3 parts - Home directory, sub-directory # and the filename. The full-path is $HOME/$subdir/$fname # And in CVS the same directory structure is maintained (by # variable $subdir) therefore in cvs we will have $CVSROOT/$subdir/$fname # In this program these 4 variables $HOME, $CVSROOT, $subdir and $fname # play an important role. For example, sample values can be like # HOME=/home/aldev, subdir=myproject/src CVSROOT=/home/cvsroot # and fname=foo.cpp # Caution: Put double-quotes to protect the variables having # spaces, like "$HOME/$subdir" if subdir is 'some foo.cpp' cmdname=`basename $0` Usage() { print "\nUsage: $cmdname [-r revision_number] <filename>" print " The options -r is optional " print "For example - " print " $cmdname -r 1.1 foo.cpp" print " $cmdname foo.cpp " print " " } # Command getopt will not supported in next major release. # Use getopts instead. while getopts r: ii do case $ii in r) FLAG1=$ii; OARG1="$OPTARG";; ?) Usage; exit 2;; esac done shift ` expr $OPTIND - 1 ` if [ $# -lt 1 ]; then Usage exit fi homedir=` echo $HOME | cut -f1 -d' ' ` if [ "$homedir" = "" ]; then print "\nError: \$HOME is not set!!\n" exit fi cur_dir=`pwd` #echo $cur_dir len=${#homedir} len=$(($len + 2)) #echo $len subdir=` echo $cur_dir | cut -b $len-2000 ` #echo "subdir is : " $subdir tmpaa=`dirname $1` if [ "$tmpaa" = "." ]; then fname=$1 if [ "$subdir" = "" ]; then subdir=$tmpaa fi else fname=`basename $1` if [ "$subdir" = "" ]; then subdir=$tmpaa else subdir="$subdir/$tmpaa" fi fi #echo "subdir is : " $subdir #echo "fname is : " $fname cvs_root=` echo $CVSROOT | cut -f1 -d' ' ` if [ "$cvs_root" = "" ]; then print "\nError: \$CVSROOT is not set!!\n" exit fi if [ ! -e "$CVSROOT/$subdir/$fname,v" ]; then print "\nError: File $fname does not exist in CVS repository!!\n" exit fi # CVS directory in your local directory is required for all commands.. if [ ! -d "$homedir/$subdir/CVS" ]; then tmpaa=` (cd "$CVSROOT/$subdir"; find * -prune -type f -print | head -1 ) ` tmpbb=`basename $tmpaa | cut -d',' -f1 ` if [ "$tmpaa" = "" -o ! -f "$CVSROOT/$subdir/$tmpbb,v" ]; then print "\nThe directory $homedir/$subdir/CVS does not exist" print "You must do a sget on `basename $subdir` directory. Give -" print " cd $homedir/`dirname $subdir` " print " sget `basename $subdir` " exit else # Now try to create CVS in local dir by sget ( cd "$homedir" if [ "$subdir" = "." ]; then # don't use dot, will mess up cvs cvs -r checkout -A $tmpbb else cvs -r checkout -A "$subdir/$tmpbb" fi ) fi fi # Get the tip revision number of the file.... # Use tmpfile as the arg cannot be set inside the sub-shell tmpfile=$homedir/sunlock-lock.tmp \rm -f $tmpfile 2>/dev/null if [ "$FLAG1" = "" ]; then # Operate inside sub-shell - from root directory ( cd $homedir if [ "$subdir" = "." ]; then # don't use dot, will mess up cvs cvs log $fname | head -6 | grep head: | awk '{print $2}' > $tmpfile else cvs log "$subdir/$fname" | head -6 | grep head: | awk '{print $2}' > $tmpfile fi ) OARG1=`cat $tmpfile` \rm -f $tmpfile 2>/dev/null fi lockfile="$CVSROOT/$subdir/Locks/$fname-$OARG1" #echo lockfile is : $lockfile if [ ! -e $lockfile ]; then print "\nFile $fname revision $OARG1 is NOT locked by anyone" print " " exit fi ans="" while : do print "\n\n***************************************************" print "WARNING: $cmdname will release lock and enable other" print " developers to edit the file. It is advisable" print " to save your changes with scommit command" print "***************************************************" print -n "\nAre you sure you want to unlock the file <y/n>? [n]: " read ans if [ "$ans" = "" -o "$ans" = " " -o "$ans" = "n" -o "$ans" = "N" ]; then print "\nAborting $cmdname ...." exit fi if [ "$ans" = "y" -o "$ans" = "Y" ]; then print "\n\n\n\n\n " print "CAUTION: You may lose all the changes made to file!!" print -n "Are you sure? Do you really want to unlock the file <y/n>? [n]: " read ans if [ "$ans" = "y" -o "$ans" = "Y" ]; then break elif [ "$ans" = "" -o "$ans" = " " -o "$ans" = "n" -o "$ans" = "N" ]; then exit else print "\n\nWrong entry. Try again..." sleep 1 fi else print "\n\nWrong entry. Try again..." sleep 1 fi done if [ -e $lockfile ]; then \rm -f $lockfile print "\nDone $cmdname" else print "\nFile $fname is NOT locked by anyone" print " " fi Next Previous Contents |