#!/bin/ksh

# Please update your path variable with whatever you want to have to get to all
# the tools you need for this script
PATH=/bin:/usr/bin

# This variable contains the list of branches to lock - update this list as per
# your requirement
locked_branches="branch1 branch2"

# This variable contains the email-ids of people to bug if the checkin fails
# You would probably want to list the ids of the Release Engineers and the CVS admins
people_to_bug="admin1@domain.com admin2@domain.com"

ErrorExit () {
        Branch=$1
        echo " "
        echo "! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !WARNING ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! "
        echo "! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !COMMIT FAILED ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! "
		echo " "
        echo "${Branch} is closed for commits"
		echo "Please contact $people_to_bug"
		echo " "
        echo "! ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! !COMMIT FAILED ! ! ! ! ! ! ! ! ! ! ! ! ! ! ! "
		echo " "
        exit 1
}

# This for is probably unnecessary since this script would get two argument - full path to the
# directory where you are doing the checkin and the file you are checking in
for file in $@
do
		# This makes $1 point to the file I am checking in
        shift

		# Grab the last field - that contains the branch name
        Branch=`grep "^/$1/" CVS/Entries | awk -F/ '{print $NF}' | cut -c2-`

		if [[ ${Branch} != "" ]]
		then
			for locked_branch in $locked_branches
			do
				test ${Branch} != $locked_branch || ErrorExit ${Branch}
			done
		fi
        exit 0
done
