#!/bin/sh
#	This file is part of the Concurrent Versions System CVS.
#	Written by Dick Grune, Vrije Universiteit, Amsterdam.
#	$Header: LCK,v 3.1 89/09/25 16:32:25 dick Exp $

#
#		L o C K
#	LCK on <repository>   sets a lock in <repository>
#	LCK off <repository>   removes the lock.
#	For maintenance only. NOT to be used by the normal user; CM and UV
#	handle all normal cases.
#
Name=LCK; export Name

# CVSBIN, CVSLIB and RCSBIN directories
CVSBIN=/home/top/dick/cvs
CVSLIB=/home/top/dick/cvs
RCSBIN=${RCSBIN-/usr/local/bin}
export CVSBIN CVSLIB RCSBIN

# avoid spurious identifications
PATH=${CVSPATH-/bin:/usr/bin}; export PATH

# get the request
Request=$1
case "$Request" in
on|off)	# OK
	;;
*)
	echo Call is: $Name \[ on \| off \] repository-name >&2
	exit 1
esac
shift

# is the number of parameters correct?
case $# in
1)	# OK
	;;
*)
	echo Call is: $Name \[ on \| off \] repository-name >&2
	exit 1
	;;
esac

Repository=$1

# check the existence of the repository
. $CVSLIB/NR.aux

LCK=$Repository/\#cvs.lock		# the lock
TFL=$Repository/\#cvs.tfl		# pattern of temporary test files
RFL=$Repository/\#cvs.rfl		# pattern of the read flags
WFL=$Repository/\#cvs.wfl		# the general write flag
LFL=$Repository/\#cvs.lfl		# the general lock flag

case $Request in
on)	# now just lock the repository
	AutoRemove=no			# with AutoRemove off,
	. $CVSLIB/WL.aux		# set write lock
	cp /dev/null $LFL		# and plant the lock flag
	;;

off)	# let's have a look
	if	# there is a lock
		[ -d $LCK ]
	then	# we must first remove the non-lock flags
		rm -f $TFL.* $RFL.* $WFL
		# and then the lock (otherwise somebody can plant a flag
		# just after the rmdir and just before the rm $WFL !
		if	rmdir $LCK
		then	:
		else
			echo $Name: could not remove existing lock \
				in $Repository >&2
			exit 1
		fi
		rm -f $LFL
	else
		echo $Name: there is no lock in $Repository >&2
		exit 1
	fi
	;;
esac

exit 0

