]> git.ipfire.org Git - thirdparty/kernel/stable-queue.git/blob - scripts/mbox2send
6.1-stable patches
[thirdparty/kernel/stable-queue.git] / scripts / mbox2send
1 #!/usr/bin/perl -W
2 #
3 # This takes a mbox of email, created with 'quilt mail --mbox'
4 # and formats it in the proper way to send off a -stable kernel review.
5 #
6 # This means:
7 # - strip off some quilt headers and the threading
8 # - add some text at the top of every message.
9 #
10 # Written in perl because the bash version is broken, it doesn't pass
11 # through the patch correctly :(
12 #
13
14 my $line;
15
16 my $root_version = shift;
17
18 if ($root_version eq "") {
19 print "must provide kernel root version number\n";
20 die;
21 }
22
23 my $full_version = shift;
24 if ($full_version eq "") {
25 print "must provide kernel full version number\n";
26 die;
27 }
28 my $mbox = shift;
29
30 if ($mbox eq "") {
31 print "must provide the name of the mbox file\n";
32 die;
33 }
34
35 my $major_version = substr($root_version, 0, 1);
36
37 my $date=`date -u --iso-8601=minutes --date="2 days"`;
38 chomp($date);
39
40 $mboxnew = "$mbox.new";
41 chomp($mboxnew);
42
43 open MBOX, "$mbox" || die "Failed to open $mbox";
44 open FILE, ">$mboxnew" || die "Failed to create $mboxnew";
45
46 my $header = "true";
47 my $eat = "false";
48 my $tags_written = "false";
49 my $stable_tag_written = "false";
50
51 while ($line = <MBOX>) {
52 $eat = "false";
53
54 if ($header eq "false") {
55 if ($line =~ m/^From /) {
56 # start of a message, this is the header
57 $header = "true";
58 }
59 }
60
61 if ($header eq "true") {
62 if ($stable_tag_written eq "false") {
63 if ($line =~ m/^Subject:/) {
64 # always add a "X-stable: review" tag
65 print FILE "X-stable: review\n";
66 $stable_tag_written = "true";
67 # and a "X-Patchwork-Hint: ignore" tag
68 print FILE "X-Patchwork-Hint: ignore\n"
69 }
70 }
71
72 # if first Subject: line, add our tags
73 if ($tags_written eq "false") {
74 if ($line =~ m/^Subject:/) {
75 # write out our own X-KernelTest tags to make automated tools's lives easier
76 print FILE "X-KernelTest-Patch: http://kernel.org/pub/linux/kernel/v$major_version.x/stable-review/patch-$full_version.gz\n";
77 print FILE "X-KernelTest-Tree: git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable-rc.git\n";
78 print FILE "X-KernelTest-Branch: linux-$root_version.y\n";
79 print FILE "X-KernelTest-Patches: git://git.kernel.org/pub/scm/linux/kernel/git/stable/stable-queue.git\n";
80 print FILE "X-KernelTest-Version: $full_version\n";
81 print FILE "X-KernelTest-Deadline: $date\n";
82
83 $tags_written = "true";
84
85 # hack around the fact that content-type is not in the 000 message
86 # and so the 001 message will not get the X- flags we want to set above
87 $stable_tag_written = "false";
88 }
89 }
90
91 # strip out References line
92 if ($line =~ m/^References:/) {
93 # eat the line
94 $eat = "true";
95 }
96 # strip out the Content-Type line
97 if ($line =~ m/Content-Type:/) {
98 # eat the line
99 $eat = "true";
100
101 # we are now out of the header
102 $header = "false";
103 $stable_tag_written = "false";
104
105 # write out our custom header too
106 print FILE "\n";
107 print FILE "$root_version-stable review patch. If anyone has any objections, please let me know.\n";
108 print FILE "\n";
109 print FILE "------------------\n";
110 }
111 }
112
113 if ($eat eq "false") {
114 print FILE $line;
115 }
116 }
117 close MBOX;
118 close FILE;
119
120 #print "# New mailbox is in $mboxnew\n";
121 #print "# To send the patches out, do:\n";
122 #print "cat $mboxnew | formail -A \"In-Reply-To: <FOO>\" -s msmtp-enqueue.sh\n";
123 #print "# or\n";
124 #print "< $mboxnew formail -ds sh -c 'cat > msg.\$FILENO'\n";