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