info-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

cvsp.sh – a wrapper script working on top of CVS


From: Bhavaniprasad Polimetla
Subject: cvsp.sh – a wrapper script working on top of CVS
Date: Thu, 12 Jul 2001 13:53:11 +0530

                        cvsp.sh – a wrapper script working on top of CVS



Sub: Provide authorization to users for check in into cvs repository.

Problem: CVS will provide multiple checkouts. There is no command to
take get latest version from the repository without
doing checkout. Now the user want to lock the particular file or
directory until he finish his work. This functionality achieved by
cvsp.sh script. Is wrapper script for cvs. Internally it will call cvs.

Script Name: cvsp.sh

Pass the parameters as you are passing to cvs.

Lock command:
If you want others to prevent from check in, lock the file or directory.

$cvsp.sh lock absolute path  (or)
$cvsp.sh lock $CVSROOT/path from root level

Once one user locked the file, others can’t check in the file, until he
unlock the file.

Unlock command:
$cvsp.sh unlock absolute path  (or)
$cvsp.sh unlock $CVSROOT/path from root level

Commit command:
To commit or checkin the file—
$cvsp.sh commit filename
$cvsp.sh ci filename

It will ask the comments. Don’t enter the comments along with cvsp.sh
file.

Add command:
If you added the file, then the file automatically locked.
We need to unlock it later.


Status command:
$cvsp.sh status
it will show all locked files/directories status.

Note: Please change the hard coded paths in the script, according to
your requirements.
Note: We can remove .sh also. we can use as $cvsp.

If you want to modify the script, please do the needful and let me now.

For any other clarifications please contact the author.
Bhavani Prasad Polimetla

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

#############################################################
# $Source: /CVSROOT/cvsp.sh $
#
# $RCSfile: cvsp.sh $
#
# $Author: Bhavani Prasad $
#
# $Date: 2001/05/29 $
#
# $Revision: 1.0 $
#############################################################
#!/bin/ksh

function cvsp_exit
{

status=`rm -f $temp_file`
exit
}

#############################################################

lock_file="/home/bhavani/cvsroot/CVSROOT/lock_file.log"
temp_file="/home/bhavani/cvsroot/CVSROOT/temp.log"

if [ ! -f $lock_file ]
then
 `touch $lock_file`
 `chmod 666 $lock_file`
fi

if [ ! -f $temp_file ]
then
 `touch $temp_file`
 `chmod 666 $temp_file`
fi


#echo "parameters passed: $*"

#####----#####----#####----#####----#####----#####----#####
#If user passed no parameters
if [ $# -lt 1 ]
then
        echo "Instead of using cvs use cvsp and pass the parameters as
you are passing to cvs"
        `cvs`
        cvsp_exit
fi

#############################################################
#lock option

#check for command and total parameters
if [ $1 == "lock" ]
then

 #check for number of parameters
 if [ $# != 2 ]
 then
 echo "Syntax: cvsp.sh lock file name/directory name"
 cvsp_exit
 fi

 #check that the given file/directory existed.
 if [ ! -f $2 ]
 then
  if [ ! -d $2 ]
  then
  echo "The given file/directory not existed, pass valid directory or
file name"
  cvsp_exit
  fi
 fi

 #check that left content not locked
 `echo $2 > $temp_file`
 for file in `cat $lock_file | cut -d" " -f2`
 do
  status=`grep -c $file $temp_file`
  value="1"
  if [ $status -ge $value ]
  then

   param2="grep -e$file$ $lock_file"
   param3="grep -e$file$ $lock_file"
   username_from_file=`$param2 | head -1 |cut -d" " -f1`
   file_name=`$param3 | head -1 |cut -d" " -f2`
   echo "($username_from_file) already locked ($file_name)
file/directory."
   cvsp_exit
  fi

 done


 #check that right content not locked
 param2="grep -c -e $2 $lock_file"
 #echo "param is: $param2"
 status=`$param2`
 #echo "return by grep is:$status"
 if [ $status == 0 ]
 then
  #echo "lock, file name: $lock_file"
  user=`id | cut -d"(" -f2 | cut -d")" -f1`
  echo "$user $2" >> $lock_file
  echo "file was locked"
 else
  param2="grep -e$2 $lock_file"
  param3="grep -e$2 $lock_file"
  username_from_file=`$param2 | head -1 |cut -d" " -f1`
  file_name=`$param3 | head -1 |cut -d" " -f2`
  echo "($username_from_file) already locked ($file_name)
file/directory."

 fi

 cvsp_exit
fi

#############################################################
#unlock option

#check for command and total parameters
if [ $1 == "unlock" ]
then

 #check for number of parameters
 if [ $# != 2 ]
 then
 echo "Syntax: cvsp.sh unlock file name/directory name"
 cvsp_exit
 fi

 #check that the given file/directory existed.
 if [ ! -f $2 ]
 then
  if [ ! -d $2 ]
  then
  echo "The given file/directory not existed, pass valid directory or
file name"
  cvsp_exit
  fi
 fi

 #check that the given file existed in lock_file.log
 param2="grep -c -e $2$ $lock_file"
 #echo "param is: $param2"
 status=`$param2`
 #echo "return by grep is:$status"
 if [ $status == 0 ]
 then
  echo "file was not locked"
 else
  #check that the user have the rights to unlock that file
  param2="grep -e$2$ $lock_file"
  username_from_file=`$param2 | head -1 |cut -d" " -f1`
  file_name=`$param2 | head -1 |cut -d" " -f2`
  #echo "username=$username_from_file"
  present_user=`id | cut -d"(" -f2 | cut -d")" -f1`
  if [[ $present_user == $username_from_file || $present_user == "root"
]]
  then
   #unlock the file
   param2="-e$2 -v $lock_file"
   status=`grep $param2 > $temp_file`
   status=`mv $temp_file $lock_file`
   echo "file was unlocked"
  else
   #echo "File was locked by $username"
   #echo "Ask the $username_from_file to unlock or ask supervisor"
   echo "($username_from_file) already locked ($file_name)
file/directory."
  fi


 fi

 cvsp_exit
fi

#############################################################
#checkin/commit option

if [[ $1 == "commit" || $1 == "ci" ]]
then
 #check for number of parameters
 if [ $# != 2 ]
 then
 echo "Syntax: cvsp.sh commit file name/directory name"
 cvsp_exit
 fi


 #check that the given file existed in lock_file.log
 param2="grep -c -e $2 $lock_file"
 #echo "param is: $param2"
 status=`$param2`
 #echo "return by grep is:$status"
 if [ $status == 0 ]
 then
  echo "file was not locked"
 else
  #check that the user have the rights to commit that file
  param2="grep -e$2 $lock_file"
  username_from_file=`$param2 | head -1 |cut -d" " -f1`
  file_name=`$param2 | head -1 |cut -d" " -f2`
  #echo "username=$username_from_file"
  present_user=`id | cut -d"(" -f2 | cut -d")" -f1`
  if [[ $present_user == $username_from_file || $present_user == "root"
]]
  then
   echo "Please enter the coments"
   coments=""
   read coments
   status=`cvs commit -m "$coments" $2`
   echo "$status"
   echo "unlock this file, so that others can use this file"
  else
   #echo "File was locked by $username"
   #echo "Ask the $username_from_file to unlock or ask supervisor"
   echo "($username_from_file) already locked ($file_name)
file/directory."
  fi


 fi

 cvsp_exit
fi

#############################################################
#status option
if [ $1 == "status" ]
then
 echo "The following files are locked"
 echo "user name - file name"
 status=`cat $lock_file`
 echo "$status"

cvsp_exit
fi

#############################################################
#add option

#check for command and total parameters
if [ $1 == "add" ]
then

 #check for number of parameters
 if [ $# != 2 ]
 then
 echo "Syntax: cvsp.sh add file name/directory name"
 cvsp_exit
 fi

 #check that the given file/directory existed.
 if [ ! -f $2 ]
 then
  if [ ! -d $2 ]
  then
  echo "The given file/directory not existed, pass valid directory or
file name"
  cvsp_exit
  fi
 fi

 #check that left content not locked
 `echo $2 > $temp_file`
 for file in `cat $lock_file | cut -d" " -f2`
 do
  status=`grep -c $file $temp_file`
  value="1"
  if [ $status -ge $value ]
  then

   param2="grep -e$file$ $lock_file"
   param3="grep -e$file$ $lock_file"
   username_from_file=`$param2 | head -1 |cut -d" " -f1`
   file_name=`$param3 | head -1 |cut -d" " -f2`
   echo "($username_from_file) already locked ($file_name)
file/directory."
   cvsp_exit
  fi

 done


 #check that right content not locked
 param2="grep -c -e $2 $lock_file"
 #echo "param is: $param2"
 status=`$param2`
 #echo "return by grep is:$status"
 if [ $status == 0 ]
 then
  #echo "lock, file name: $lock_file"
  user=`id | cut -d"(" -f2 | cut -d")" -f1`
  echo "$user $2" >> $lock_file
  echo "file was locked"
  status=`cvs $*`
  echo "$status"
 else
  param2="grep -e$2 $lock_file"
  param3="grep -e$2 $lock_file"
  username_from_file=`$param2 | head -1 |cut -d" " -f1`
  file_name=`$param3 | head -1 |cut -d" " -f2`
  echo "($username_from_file) already locked ($file_name)
file/directory."

 fi

 cvsp_exit
fi



#############################################################
#cvs
#echo "$*"

status=`cvs $*`
echo "$status"

cvsp_exit
#########################################################


^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

Thank you,
Bhavani Prasad Polimetla
address@hidden







reply via email to

[Prev in Thread] Current Thread [Next in Thread]