1 | #! /bin/sh |
---|
2 | |
---|
3 | # /usr/local/bin/cvs-commitinfo.sh et /usr/local/bin/cvs-loginfo.sh |
---|
4 | # Scripts de notification par mail des commits du CVS |
---|
5 | # Version 1.2 |
---|
6 | # Scripts écrits par Boris DorÚs <babal@via.ecp.fr> - 2003 |
---|
7 | # Formation Debian GNU/Linux par Alexis de Lattre |
---|
8 | # http://formation-debian.via.ecp.fr/ |
---|
9 | |
---|
10 | |
---|
11 | # Pour mettre en place la notification par mail : |
---|
12 | # 1) copiez les fichiers cvs-loginfo.sh et cvs-commitinfo.sh dans le répertoire |
---|
13 | # /usr/local/bin/ |
---|
14 | # |
---|
15 | # 2) ajoutez dans le fichier |
---|
16 | # /var/lib/cvs/nom_du_projet/CVSROOT/commitinfo la ligne suivante : |
---|
17 | |
---|
18 | #ALL /usr/local/bin/cvs-commitinfo.sh |
---|
19 | |
---|
20 | # 3) ajoutez dans le fichier |
---|
21 | # /var/lib/cvs/nom_du_projet/CVSROOT/loginfo la ligne suivante : |
---|
22 | |
---|
23 | #ALL /usr/local/bin/cvs-loginfo.sh adresse_de_provenance adresse_destination "Sujet_des_mails" $USER |
---|
24 | |
---|
25 | |
---|
26 | # parameters |
---|
27 | mailfrom="$1"; |
---|
28 | mailto="$2"; |
---|
29 | subject="$3"; |
---|
30 | user="$4"; |
---|
31 | |
---|
32 | # external programs |
---|
33 | AWK=/usr/bin/awk |
---|
34 | CAT=/bin/cat |
---|
35 | CSPLIT=/usr/bin/csplit |
---|
36 | CUT=/usr/bin/cut |
---|
37 | FIND=/usr/bin/find |
---|
38 | GREP=/bin/grep |
---|
39 | MAIL=/usr/bin/mail |
---|
40 | RM=/bin/rm |
---|
41 | WC=/usr/bin/wc |
---|
42 | |
---|
43 | # temporary files |
---|
44 | directories="/tmp/cvslog.$PPID.directories" |
---|
45 | log="/tmp/cvslog.$PPID" |
---|
46 | pattern="/tmp/cvslog.$PPID.$$." |
---|
47 | head="/tmp/cvslog.$PPID.$$.00" |
---|
48 | message="/tmp/cvslog.$PPID.$$.01" |
---|
49 | |
---|
50 | |
---|
51 | # split the loginfo message |
---|
52 | $CSPLIT -qf "$pattern" - "/Log Message:/" |
---|
53 | $GREP -hv '^In directory' "$head" | $GREP -hv '^$' >> "$log" |
---|
54 | echo >> "$log" |
---|
55 | |
---|
56 | # is it the last directory ? |
---|
57 | NB_MAIL=`$GREP '^$' "$log" 2> /dev/null | $WC -l` |
---|
58 | if ( test -f "$directories" ) |
---|
59 | then |
---|
60 | NB_COMMIT=`$CAT "$directories" | $WC -l` |
---|
61 | else |
---|
62 | NB_COMMIT=1 |
---|
63 | fi |
---|
64 | if [[ $NB_MAIL -ge $NB_COMMIT ]] |
---|
65 | then |
---|
66 | # complete and send the mail |
---|
67 | $AWK 'BEGIN { n=0 ; } { if ( $0 ~ "^[ \t\f\n\r\v]*$" ) { n++; } else { for ( i=0; i<n; i++ ) printf "\n"; print $0; n=0; } }' "$message" >> "$log" |
---|
68 | echo -e "\n-- \n$user" >> "$log" |
---|
69 | $CAT "$log" | $MAIL -s "$subject ($user)" -a "From: $mailfrom" "$mailto" |
---|
70 | # clean up |
---|
71 | $RM -f $log |
---|
72 | $RM -f $directories |
---|
73 | fi |
---|
74 | |
---|
75 | # clean up |
---|
76 | $RM -f "$pattern"* |
---|