#!/bin/bash

# This script updates a directory of checked-out CVS modules, and runs 'cvs log' on each, to generate */cvs.log logs,
# for parsing by a JIRA instance.
# While updating, a lock file, 'cvslog.write.lock', is created in each subdirectory, in case JIRA decides to update at
# the same moment.  See http://www.atlassian.com/software/jira/docs/latest/cvs_integration.html for more info.

REPO_DIR=/opt/tomcat-jira/jira/repos
LOCKNAME=cvslog.write.lock

cd $REPO_DIR
repos=`
for f in *; do
	if [ -d "$f" ]; then
		echo $f
	fi
done
`
echo "Parsing repos $repos"

for repo in $repos; do
	cd $repo
	if [ ! -e "$LOCKNAME" ]; then
		/usr/bin/cvs -z9 -q update -dP &&
		echo "`date`: Generating $PWD/cvs.log" &&
		touch $LOCKNAME
		/usr/bin/cvs -q -z8 log > cvs.log
		rm $LOCKNAME
	else
		echo "CVS for $repo locked: `ls -la $LOCKNAME`"
	fi
	cd ..
done

# vim:set tw=120:
