From 7d2ce6f78da1a38c2db5c40080864721fd9f6681 Mon Sep 17 00:00:00 2001 From: Greg Kroah-Hartman Date: Wed, 18 Oct 2006 13:51:56 -0700 Subject: [PATCH] add some helper scripts that I have started using to notify people when patches are applied to the queue --- scripts/added-to-stable | 175 ++++++++++++++++++++++++++++++++++++++++ scripts/makemail | 53 ++++++++++++ scripts/smtpsend | 154 +++++++++++++++++++++++++++++++++++ 3 files changed, 382 insertions(+) create mode 100755 scripts/added-to-stable create mode 100755 scripts/makemail create mode 100755 scripts/smtpsend diff --git a/scripts/added-to-stable b/scripts/added-to-stable new file mode 100755 index 00000000000..acbc4f097da --- /dev/null +++ b/scripts/added-to-stable @@ -0,0 +1,175 @@ +#!/bin/bash + +#. patchfns 2>/dev/null || +#. /usr/lib/patch-scripts/patchfns 2>/dev/null || +#. $PATCHSCRIPTS_LIBDIR/patchfns 2>/dev/null || +#{ +# echo "Impossible to find my library 'patchfns'." +# echo "Check your install, or go to the right directory" +# exit 1 +#} + +EMAIL_ADDRESS='' + +STABLE='' + +extract_addr() +{ + read l + read l + read l + read l + a=$(echo "$l" | sed -n -e 's/.*<\(.*@[^>]*\).*/\1/p') + echo $a +} + +if [ x"$SMTP_SERVER" = x ] +then + SMTP_SERVER=localhost:25 +fi + +if [ x"$EMAIL_ADDRESS" = x ] +then + echo "You must set the EMAIL_ADDRESS environment variable to your email address" + exit 1 +fi +FROM=$EMAIL_ADDRESS + +TO="" +CC="" + +author() +{ + first_author="" + TXT=$2 + if [ ! -f $TXT ] + then + echo $TXT is missing + exit 1 + fi + author="" + while read l + do + # skip the Message-ID: line so we don't send email to the wrong place + echo $l + reply=$(echo "$l" | grep -i Message-ID:) + if [ x"$reply" != x ] + then + continue + fi + + # if this is the start of the diff, then it's time to stop looking + diff=$(echo "$l" | grep "^---") + if [ x"$diff" != x ] + then + echo "diffstart!!!!!" + break + fi + + for x in $l + do + a=$(echo "$x" | sed -n -e 's/.*<\(.*@[^>]*\).*/\1/p') + if [ x"$a" != x ] + then + if [ x"$author" == x ] + then + author=$a + first_author=$a + else + author="$author $a" + fi + fi + done + done < $TXT + author=$(echo $author | tr ' ' '\n' | grep -v "$first_author" | + sort | uniq) + author="$first_author $author" + eval $1=$(echo $author | sed -e 's/ /,/g') + if [ x"$3" != x ] + then + eval $3=$first_author + fi +} + + + +reply() +{ + PATCH=$1 +# patch_name=$(stripit $1) +# PATCH=$P/patches/$patch_name.patch +# TXT=$P/txt/$patch_name.txt +# if [ ! -f $TXT ] +# then +# echo $TXT is missing +# exit 1 +# fi + echo "PATCH=$PATCH" + SUBJECT=`grep "Subject:" $PATCH` +# SUBJECT=$(head -n 2 $PATCH | tail -n 1) + MESSAGE_ID=`grep -i "^Message-ID:" $PATCH | cut -f 2 -d ' ' | cut -f 2 -d '<' | cut -f 1 -d '>'` + author AUTHOR $1 FIRST_AUTHOR + echo author said $AUTHOR + echo first_author said $FIRST_AUTHOR + if [ x"$AUTHOR" == "x" ] + then + echo nobody to notify + exit 0 + fi + to="" + for i in $(echo $AUTHOR | sed -e 's/,/ /g') + do + if ! echo "$TO" | grep "$i" + then + to=$to" -to $i" + fi + done + if [ x"$cc" != x ] + then + cc="-cc $cc" + fi + + echo makemail -to $AUTHOR -from=$FROM -subject="patch $PATCH added to gregkh tree" -date="$(date -R)" -reply_to=$MESSAGE_ID + echo smtpsend -server=$SMTP_SERVER $to -from=$FROM + + + ( + echo + echo -n "This is a note to let we have just queued up the " + echo "patch titled" + echo + echo " " $SUBJECT + echo + echo "to the 2.6.18-stable tree. Its filename is" + echo + echo " " $PATCH + echo + echo "A git repo of this tree can be found at " + echo " http://www.kernel.org/git/?p=linux/kernel/git/gregkh/stable-queue.git;a=summary" + echo + echo + cat $PATCH + echo + echo + echo -n "Patches currently in stable-queue which might be from " + echo "$FIRST_AUTHOR are" + echo + grep -lR $FIRST_AUTHOR /home/greg/linux/stable/stable-queue/queue-2.6.18/ 2> /dev/null | + sed -e 's/\/home\/greg\/linux\/stable\/stable-queue\///' + ) | + makemail -to $AUTHOR -from=$FROM -cc=$STABLE\ + -subject="patch $PATCH queued to -stable tree" \ + -date="$(date -R)" \ + -reply_to="$MESSAGE_ID" | \ + # talk to the suse network instead of localhost (due to the way suse.de now handles email...) + # smtpsend -server=$SMTP_SERVER $to -from=$FROM + msmtp $to +} + +for patch_file in $* +do + reply $patch_file + echo "acknowledged $patch_file" + echo "-----------------------------------------------" + echo +done diff --git a/scripts/makemail b/scripts/makemail new file mode 100755 index 00000000000..a64c75676e4 --- /dev/null +++ b/scripts/makemail @@ -0,0 +1,53 @@ +#!/usr/bin/perl -w + +#----------------------------------------------------------------------------- +# All this does is generate RFC 822 headers and then copy standard input +# to standard output. You determine what headers it generates with +# command options. +# +# You can feed the output of this program to 'smtpsend' to send the mail +# message somewhere via SMTP. +#----------------------------------------------------------------------------- + +use strict; + +my $TRUE=1; my $FALSE = 0; + +use Getopt::Long; + + +my %options; + +GetOptions(\%options, + "from=s", + "to=s", + "cc=s", + "subject=s", + "date=s", + "reply_to=s" + ); + +if (defined($options{"subject"})) { + print("Subject: " . $options{"subject"} . "\n"); +} +if (defined($options{"to"})) { + print("To: " . $options{"to"} . "\n"); +} +if (defined($options{"cc"})) { + print("Cc: " . $options{"cc"} . "\n"); +} +if (defined($options{"from"})) { + print("From: " . $options{"from"} . "\n"); +} +if (defined($options{"date"})) { + print("Date: " . $options{"date"} . "\n"); +} +if (defined($options{"reply_to"})) { + print("In-Reply-To: <" . $options{"reply_to"} . ">\n"); +} + +print("\n"); + +while () { + print; +} diff --git a/scripts/smtpsend b/scripts/smtpsend new file mode 100755 index 00000000000..b314b2f547f --- /dev/null +++ b/scripts/smtpsend @@ -0,0 +1,154 @@ +#!/usr/bin/perl +#----------------------------------------------------------------------------- +# This program gives you low level control over an SMTP conversation. +# +# This program delivers a mail message to an SMTP server. Command line +# options tell what server to use and determine the commands this program +# sends to it. The program reads the mail message itself from +# Standard Input. +# +# This program does not generate headers inside the mail message (e.g. +# RFC 822 headers). You can use the program 'makemail' to do that. +# +# This program does not extract any envelope information from the mail +# message or rewrite the message in any way. +#----------------------------------------------------------------------------- + +use strict; +use warnings; + +use Net::SMTP; +use Getopt::Long; +use Sys::Hostname; +use Data::Dumper; + +my $TRUE = 1; +my $FALSE = 0; + + +sub getSender($) { + my ($fromOpt) = @_; + + my $retval; + + if (defined($fromOpt)) { + $retval = $fromOpt; + } else { + my $user = $ENV{"USER"} || $ENV{"LOGNAME"}; + if (!defined("$user")) { + die("You didn't supply a sender address with " . + "--from and I cannot " . + "default one because neither USER nor LOGNAME environment " . + "variables is set."); + } else { + my $hostname = hostname; + if (defined($hostname)) { + $retval = "$user\@$hostname"; + } else { + $retval = $user; + } + } + } + return $retval; +} + + +############################################################################## +# MAINLINE +############################################################################## + +my %options; + +$options{"to"} = []; # Establish as an array reference + +GetOptions(\%options, + "to=s", + "from=s", + "server=s", + "hello=s", + "timeout=i", + "quiet", + "debug" + ); + +if ($options{"debug"}) { + Net::SMTP->debug(1); +} + +if (@{$options{"to"}} == 0) { + die("Must specify the recipient email address with --to"); +} + +my @recipients = @{$options{"to"}}; +#print Data::Dumper->Dump([ \@recipients ], [ "recipients" ]); + +my $sender = getSender($options{"from"}); + +my $server = $options{"server"} || "localhost"; + +my @smtpOptions = (); # initial value +if (defined($options{"hello"})) { + push(@smtpOptions, Hello => $options{"hello"}); +} +if (defined($options{"timeout"})) { + push(@smtpOptions, Timeout => $options{"timeout"}); +} +if ($options{"debug"}) { + push(@smtpOptions, Debug => 1); +} + +my $smtp = Net::SMTP->new($server, @smtpOptions); + +if (!defined($smtp)) { + die("Failed to connect to SMTP server at '$server'"); +} + +if (!$options{"quiet"}) { + print("Server at $server identifies as '" . $smtp->domain . "' " . + "and says:\n"); + print $smtp->banner; + print ("\n"); + print ("Reading mail message from Standard Input...\n"); +} + +my $result = $smtp->mail($sender); +if (!$result) { + warn("Failed sending MAIL command. " . + "Server says '" . $smtp->message . "'"); +} else { + my $rcptError; + foreach my $recipient (@recipients) { + my $result = $smtp->recipient($recipient); + if (!$result) { + warn("Failed sending RCPT command for '$recipient'. " . + "Server says '" . $smtp->message . "'"); + $rcptError = $TRUE; + } + } + if ($rcptError) { + $smtp->quit; + die("send error"); + } else { + my @message = ; + + my $result = $smtp->data(@message); + + if (!$result) { + warn("Server rejected message. " . + "Server says '" . $smtp->message . "'"); + $smtp->quit; + die("rejected"); + } else { + $smtp->quit; + if (!$options{"quiet"}) { + my $recipientDesc; + if (@recipients == 1) { + $recipientDesc = $recipients[0]; + } else { + $recipientDesc = scalar(@recipients) . " recipients"; + } + print("Message sent to $recipientDesc from $sender.\n"); + } + } + } +} -- 2.47.2