[114] | 1 | #!/bin/sh
|
---|
| 2 | # Allow tracking on your CVS modules without the need of server access
|
---|
| 3 | # put in cron * * * * *
|
---|
| 4 | # Works only properly if your receive one commit a minute.
|
---|
| 5 | # Rick van der Zwet <info@rickvanderzwet.nl>
|
---|
| 6 | # License BSD: http://rickvanderzwet.nl/LICENSE
|
---|
| 7 |
|
---|
[115] | 8 | CVSPROJECT=wk2010
|
---|
| 9 | CVSDIR=/home/rvdzwet/$CVSPROJECT
|
---|
[114] | 10 |
|
---|
[115] | 11 | EMAIL_TO="info@example.org"
|
---|
| 12 | EMAIL_CC="foo@example.org,bar@example.org"
|
---|
| 13 | EMAIL_FROM="noreply@example.org"
|
---|
| 14 |
|
---|
[114] | 15 | # System internal variables
|
---|
| 16 | TMPDIR=`mktemp -d -t $(basename $0 .sh)`
|
---|
| 17 | CVSLOG=$TMPDIR/cvs.log
|
---|
| 18 | CVSLOG_STDERR=$TMPDIR/cvs.log.stderr
|
---|
| 19 | EMAIL_BODY=$TMPDIR/email-body.txt
|
---|
| 20 | EMAIL_FULL=$TMPDIR/email-full.msg
|
---|
| 21 |
|
---|
| 22 | UPDATED=""
|
---|
| 23 | AUTHOR="unknown"
|
---|
| 24 | UPDATED_FILES=""
|
---|
| 25 |
|
---|
| 26 | {
|
---|
| 27 | cd $CVSDIR
|
---|
| 28 |
|
---|
| 29 | # Changes in repository
|
---|
| 30 | touch $CVSLOG_STDERR
|
---|
| 31 | cvs -q up 2>$CVSLOG_STDERR | tee $CVSLOG
|
---|
| 32 | UPDATED_FILES=`awk '/^[U|P]/ {print $2}' $CVSLOG`
|
---|
| 33 | echo ""
|
---|
| 34 |
|
---|
| 35 | # Deleted files
|
---|
| 36 | if [ -s $CVSLOG_STDERR ]; then
|
---|
| 37 | cat $CVSLOG_STDERR
|
---|
| 38 | echo ""
|
---|
| 39 | UPDATED="yes"
|
---|
| 40 | fi
|
---|
| 41 |
|
---|
| 42 | if [ -n "$UPDATED_FILES" ]; then
|
---|
| 43 | # Log message
|
---|
| 44 | UPDATED_FILE=`echo $UPDATED_FILES | awk '{print $1}'`
|
---|
| 45 | cvs log -l -r$REV $UPDATED_FILE | sed -n '/-----/,/========/p'
|
---|
| 46 | echo ""
|
---|
| 47 |
|
---|
| 48 | # Diff of files
|
---|
| 49 | for FILE in $UPDATED_FILES; do
|
---|
| 50 | UPDATED="yes"
|
---|
| 51 | REV=`cvs log -h $FILE | awk '/^head:/ {print $2}'`
|
---|
| 52 | PREV=`echo $REV | awk -F. '{print $1 "." $2 - 1}'`
|
---|
| 53 | cvs diff -N -u -r $PREV -r $REV $FILE
|
---|
| 54 |
|
---|
| 55 | # Should be the same for all files
|
---|
| 56 | AUTHOR=`cvs log -l -r$REV $FILE | awk '/^date:/ {print $6}' | tr -d ';'`
|
---|
| 57 | done
|
---|
| 58 | fi
|
---|
| 59 | } > $EMAIL_BODY
|
---|
| 60 |
|
---|
| 61 |
|
---|
| 62 | # Send email if updated
|
---|
| 63 | if [ -n "$UPDATED" ]; then
|
---|
| 64 | {
|
---|
| 65 | echo "To: $EMAIL_TO"
|
---|
| 66 | if [ -n "$EMAIL_CC" ]; then
|
---|
| 67 | echo "Cc: $EMAIL_CC"
|
---|
| 68 | fi
|
---|
| 69 | echo "From: 'CVS Commit - $AUTHOR' <$EMAIL_FROM>"
|
---|
| 70 | echo "Subject: CVS Update $CVSPROJECT `echo $UPDATED_FILES`"
|
---|
| 71 | if [ -n "$EMAIL_CC" ]; then
|
---|
| 72 | echo "Reply-To: $EMAIL_TO,$EMAIL_CC"
|
---|
| 73 | else
|
---|
| 74 | echo "Reply-To: $EMAIL_TO"
|
---|
| 75 | fi
|
---|
| 76 | echo "X-Mailer: cvsmailer - $CVSPROJECT"
|
---|
| 77 | echo 'X-Version: $Id$'
|
---|
| 78 | echo ""
|
---|
| 79 |
|
---|
| 80 | cat $EMAIL_BODY
|
---|
| 81 | echo ""
|
---|
| 82 | echo "==== ALL DONE generated by `id -un`@`hostname` at `date` ===="
|
---|
| 83 | } > $EMAIL_FULL
|
---|
| 84 | cat $EMAIL_FULL | /usr/sbin/sendmail -t
|
---|
| 85 | fi
|
---|
| 86 |
|
---|
| 87 | rm -R $TMPDIR
|
---|