4 # Copyright (C) 1994-2005 The Free Software Foundation, Inc.
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2, or (at your option)
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 ###############################################################################
17 ###############################################################################
18 ###############################################################################
20 # THIS SCRIPT IS PROBABLY BROKEN. REMOVING THE -T SWITCH ON THE #! LINE ABOVE
21 # WOULD FIX IT, BUT THIS IS INSECURE. WE RECOMMEND FIXING THE ERRORS WHICH THE
22 # -T SWITCH WILL CAUSE PERL TO REPORT BEFORE RUNNING THIS SCRIPT FROM A CVS
23 # SERVER TRIGGER. PLEASE SEND PATCHES CONTAINING THE CHANGES YOU FIND
24 # NECESSARY TO RUN THIS SCRIPT WITH THE TAINT-CHECKING ENABLED BACK TO THE
25 # <@PACKAGE_BUGREPORT@> MAILING LIST.
27 # For more on general Perl security and taint-checking, please try running the
28 # `perldoc perlsec' command.
30 ###############################################################################
31 ###############################################################################
32 ###############################################################################
34 # XXX: FIXME: handle multiple '-f logfile' arguments
36 # XXX -- I HATE Perl! This *will* be re-written in shell/awk/sed soon!
39 # Usage: log.pl [-u user] [[-m mailto] ...] [-s] [-V] -f logfile 'dirname file ...'
41 # -u user - $USER passed from loginfo
42 # -m mailto - for each user to receive cvs log reports
43 # (multiple -m's permitted)
44 # -s - to prevent "cvs status -v" messages
45 # -V - without '-s', don't pass '-v' to cvs status
46 # -f logfile - for the logfile to append to (mandatory,
47 # but only one logfile can be specified).
49 # here is what the output looks like:
51 # From: woods@kuma.domain.top
52 # Subject: CVS update: testmodule
54 # Date: Wednesday November 23, 1994 @ 14:15
57 # Update of /local/src-CVS/testmodule
58 # In directory kuma:/home/kuma/woods/work.d/testmodule
69 # (and for each file the "cvs status -v" output is appended unless -s is used)
71 # ==================================================================
72 # File: test3 Status: Up-to-date
74 # Working revision: 1.41 Wed Nov 23 14:15:59 1994
75 # Repository revision: 1.41 /local/src-CVS/cvs/testmodule/test3,v
79 # local-v2 (revision: 1.7)
80 # local-v1 (revision: 1.1.1.2)
81 # CVS-1_4A2 (revision: 1.1.1.2)
82 # local-v0 (revision: 1.2)
83 # CVS-1_4A1 (revision: 1.1.1.1)
89 my $cvsroot = $ENV{'CVSROOT'};
96 my $verbosestatus = 1;
103 # parse command line arguments
106 my $arg = shift @ARGV;
109 $users = "$users " . shift @ARGV;
110 } elsif ($arg eq '-u') {
111 $login = shift @ARGV;
112 } elsif ($arg eq '-f') {
113 ($logfile) && die "Too many '-f' args";
114 $logfile = shift @ARGV;
115 } elsif ($arg eq '-s') {
117 } elsif ($arg eq '-V') {
120 ($donefiles) && die "Too many arguments!\n";
122 @files = split(/ /, $arg);
126 # the first argument is the module location relative to $CVSROOT
128 my $modulepath = shift @files;
130 my $mailcmd = "| Mail -s 'CVS update: $modulepath'";
132 # Initialise some date and time arrays
134 my @mos = ('January','February','March','April','May','June','July',
135 'August','September','October','November','December');
136 my @days = ('Sunday','Monday','Tuesday','Wednesday','Thursday','Friday','Saturday');
138 my ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime;
141 # get a login name for the guy doing the commit....
144 $login = getlogin || (getpwuid($<))[0] || "nobody";
147 # open log file for appending
149 my $logfh = new IO::File ">>" . $logfile
150 or die "Could not open(" . $logfile . "): $!\n";
152 # send mail, if there's anyone to send to!
156 $mailcmd = "$mailcmd $users";
157 $mailfh = new IO::File $mailcmd
158 or die "Could not Exec($mailcmd): $!\n";
161 # print out the log Header
163 $logfh->print ("\n");
164 $logfh->print ("****************************************\n");
165 $logfh->print ("Date:\t$days[$wday] $mos[$mon] $mday, $year @ $hour:" . sprintf("%02d", $min) . "\n");
166 $logfh->print ("Author:\t$login\n\n");
169 $mailfh->print ("\n");
170 $mailfh->print ("Date:\t$days[$wday] $mos[$mon] $mday, $year @ $hour:" . sprintf("%02d", $min) . "\n");
171 $mailfh->print ("Author:\t$login\n\n");
174 # print the stuff from logmsg that comes in on stdin to the logfile
176 my $infh = new IO::File "< -";
177 foreach ($infh->getlines) {
185 $logfh->print ("\n");
187 # after log information, do an 'cvs -Qq status -v' on each file in the arguments.
189 if ($dostatus != 0) {
191 my $file = shift @files;
193 $logfh->print ("[input file was '-']\n");
195 $mailfh->print ("[input file was '-']\n");
199 my $rcsfh = new IO::File;
200 my $pid = $rcsfh->open ("-|");
203 die "fork failed: $!";
207 my @command = ('cvs', '-nQq', 'status');
212 push @command, $file;
214 die "cvs exec failed: $!";
217 while ($line = $rcsfh->getline) {
218 $logfh->print ($line);
220 $mailfh->print ($line);
228 or die "Write to $logfile failed: $!";
233 die "Pipe to $mailcmd failed" if $?;