More batch-mode fixes to handle redos properly (and without hanging).
[rsync/rsync.git] / packaging / release-rsync
CommitLineData
4f282b0b 1#!/usr/bin/perl -w
6d12a859
WD
2use strict;
3
805d8ac4
WD
4# This script expects the directory ~/samba-rsync-ftp to exist and to be a
5# copy of the /home/ftp/pub/rsync dir on samba.org. When the script is done,
6# the git repository in the current directory will be updated, and the local
7# ~/samba-rsync-ftp dir will be ready to be rsynced to samba.org.
6d12a859 8
805d8ac4 9use Cwd;
56fc9f70 10use Getopt::Long;
798a9e4e 11use Term::ReadKey;
6d12a859
WD
12use Date::Format;
13
14my $dest = $ENV{HOME} . '/samba-rsync-ftp';
798a9e4e
WD
15my $passfile = $ENV{HOME} . '/.rsyncpass';
16my $path = $ENV{PATH};
6d12a859 17
56fc9f70
WD
18&Getopt::Long::Configure('bundling');
19&usage if !&GetOptions(
20 'branch|b=s' => \( my $master_branch = 'master' ),
21 'help|h' => \( my $help_opt ),
22);
23&usage if $help_opt;
24
fede3785
WD
25my $now = time;
26my $cl_today = time2str('* %a %b %d %Y', $now);
27my $year = time2str('%Y', $now);
28my $ztoday = time2str('%d %b %Y', $now);
90ac152d 29(my $today = $ztoday) =~ s/^0//;
6d12a859 30
805d8ac4
WD
31my $curdir = Cwd::cwd;
32
798a9e4e
WD
33END {
34 unlink($passfile);
35}
36
67b9b26f
WD
37my @extra_files;
38open(IN, '<', 'Makefile.in') or die "Couldn't open Makefile.in: $!\n";
39while (<IN>) {
40 if (s/^GENFILES=//) {
41 while (s/\\$//) {
42 $_ .= <IN>;
43 }
44 @extra_files = split(' ', $_);
45 last;
46 }
47}
805d8ac4
WD
48close IN;
49
5fa38cd6
WD
50my $break = <<EOT;
51==========================================================================
6d12a859 52EOT
6d12a859 53
805d8ac4 54print $break, <<EOT, $break, "\n";
5fa38cd6
WD
55== This will release a new version of rsync onto an unsuspecting world. ==
56EOT
519c8de1 57
805d8ac4
WD
58die "$dest does not exist\n" unless -d $dest;
59die "There is no .git dir in the current directory.\n" unless -d '.git';
60die "'a' must not exist in the current directory.\n" if -e 'a';
61die "'b' must not exist in the current directory.\n" if -e 'b';
519c8de1 62
6a2456c5 63open(IN, '-|', 'git status') or die $!;
805d8ac4
WD
64my $status = join('', <IN>);
65close IN;
66die "The checkout is not clean:\n", $status unless $status =~ /\nnothing to commit \(working directory clean\)/;
4f282b0b
WD
67my($cur_branch) = $status =~ /^# On branch (.+)\n/;
68if ($cur_branch ne $master_branch) {
69 print "The checkout is not on the $master_branch branch.\n";
70 exit 1 if $master_branch ne 'master';
71 print "Do you want to release branch $cur_branch? [n] ";
72 $_ = <STDIN>;
73 exit 1 unless /^y/i;
74 $master_branch = $cur_branch;
75}
519c8de1 76
fede3785 77my $confversion;
578219be 78open(IN, '<', 'configure.in') or die $!;
519c8de1
WD
79while (<IN>) {
80 if (/^RSYNC_VERSION=(.*)/) {
fede3785 81 $confversion = $1;
519c8de1
WD
82 last;
83 }
84}
85close IN;
fede3785 86die "Unable to find RSYNC_VERSION in configure.in\n" unless defined $confversion;
2e4a3d17 87
62ca3826
WD
88open(IN, '<', 'OLDNEWS') or die $!;
89$_ = <IN>;
fede3785 90my($lastversion) = /(\d+\.\d+\.\d+)/;
4f282b0b
WD
91my($last_protocol_version, %pdate);
92while (<IN>) {
93 if (my($ver,$pdate,$pver) = /^\s+\S\S\s\S\S\S\s\d\d\d\d\s+(\d+\.\d+\.\d+)\s+(\d\d \w\w\w \d\d\d\d\s+)?(\d+)$/) {
94 $pdate{$ver} = $pdate if defined $pdate;
95 $last_protocol_version = $pver if $ver eq $lastversion;
96 }
97}
98close IN;
99die "Unable to determine protocol_version for $lastversion.\n" unless defined $last_protocol_version;
100
101my $protocol_version;
102open(IN, '<', 'rsync.h') or die $!;
103while (<IN>) {
104 if (/^#define\s+PROTOCOL_VERSION\s+(\d+)/) {
105 $protocol_version = $1;
106 last;
107 }
108}
109close IN;
110die "Unable to determine the current PROTOCOL_VERSION.\n" unless defined $protocol_version;
62ca3826 111
fede3785 112my $version = $confversion;
805d8ac4 113$version =~ s/dev/pre1/ || $version =~ s/pre(\d+)/ 'pre' . ($1 + 1) /e;
519c8de1 114
805d8ac4 115print "Please enter the version number of this release: [$version] ";
519c8de1
WD
116chomp($_ = <STDIN>);
117if ($_ eq '.') {
118 $version =~ s/pre\d+//;
119} elsif ($_ ne '') {
120 $version = $_;
121}
798a9e4e
WD
122die "Invalid version: `$version'\n" unless $version =~ /^[\d.]+(pre\d+)?$/;
123
124if (`git tag -l v$version` ne '') {
125 print "Tag v$version already exists.\n\nDelete tag or quit? [q/del] ";
126 $_ = <STDIN>;
127 exit 1 unless /^del/i;
128 system "git tag -d v$version";
129}
fede3785
WD
130
131if ($version =~ s/[-.]*pre[-.]*/pre/ && $confversion !~ /dev$/) {
132 $lastversion = $confversion;
133}
6d12a859 134
519c8de1
WD
135print "Enter the previous version to produce a patch against: [$lastversion] ";
136chomp($_ = <STDIN>);
137$lastversion = $_ if $_ ne '';
6d12a859
WD
138$lastversion =~ s/[-.]*pre[-.]*/pre/;
139
99ba99c7
WD
140my $pre = $version =~ /(pre\d+)/ ? $1 : '';
141
142my $release = $pre ? '0.1' : '1';
519c8de1
WD
143print "Please enter the RPM release number of this release: [$release] ";
144chomp($_ = <STDIN>);
145$release = $_ if $_ ne '';
99ba99c7 146$release .= ".$pre" if $pre;
6d12a859 147
4f282b0b
WD
148(my $finalversion = $version) =~ s/pre\d+//;
149my($proto_changed,$proto_change_date);
150if ($protocol_version eq $last_protocol_version) {
151 $proto_changed = 'unchanged';
152 $proto_change_date = "\t\t";
153} else {
154 $proto_changed = 'changed';
155 if (!defined($proto_change_date = $pdate{$finalversion})) {
156 while (1) {
157 print "On what date did the protocol change to $protocol_version get checked in? (dd Mmm yyyy) ";
158 chomp($_ = <STDIN>);
159 last if /^\d\d \w\w\w \d\d\d\d$/;
160 }
161 $proto_change_date = "$_\t";
162 }
163}
164
e63d3a29 165my($srcdir,$srcdiffdir,$lastsrcdir,$skipping);
6d12a859 166if ($lastversion =~ /pre/) {
99ba99c7 167 if (!$pre) {
6d12a859
WD
168 die "You should not diff a release version against a pre-release version.\n";
169 }
e63d3a29 170 $srcdir = $srcdiffdir = $lastsrcdir = 'src-previews';
805d8ac4 171 $skipping = ' ** SKIPPING **';
99ba99c7 172} elsif ($pre) {
e63d3a29
WD
173 $srcdir = $srcdiffdir = 'src-previews';
174 $lastsrcdir = 'src';
805d8ac4 175 $skipping = ' ** SKIPPING **';
6d12a859 176} else {
e63d3a29
WD
177 $srcdir = $lastsrcdir = 'src';
178 $srcdiffdir = 'src-diffs';
805d8ac4 179 $skipping = '';
6d12a859
WD
180}
181
5fa38cd6 182print "\n", $break, <<EOT;
6d12a859
WD
183\$version is "$version"
184\$lastversion is "$lastversion"
6d12a859 185\$dest is "$dest"
805d8ac4 186\$curdir is "$curdir"
e63d3a29
WD
187\$srcdir is "$srcdir"
188\$srcdiffdir is "$srcdiffdir"
189\$lastsrcdir is "$lastsrcdir"
6d12a859
WD
190\$release is "$release"
191
192About to:
4f282b0b 193 - tweak SUBPROTOCOL_VERSION in rsync.h, if needed
805d8ac4 194 - tweak the version in configure.in and the spec files
4f282b0b 195 - tweak NEWS and OLDNEWS to ensure header values are correct
798a9e4e 196 - tweak the date in the *.yo files and generate the manpages
805d8ac4
WD
197 - generate configure.sh, config.h.in, and proto.h
198 - page through the differences
6d12a859
WD
199
200EOT
201print "<Press Enter to continue> ";
202$_ = <STDIN>;
203
99ba99c7 204my %specvars = ( 'Version:' => $finalversion, 'Release:' => $release,
6fd2c27f
WD
205 '%define fullversion' => "\%{version}$pre", 'Released' => "$version.",
206 '%define srcdir' => $srcdir );
800a4485
WD
207my @tweak_files = ( glob('packaging/*.spec'), glob('packaging/*/*.spec'), glob('*.yo'),
208 qw( configure.in rsync.h NEWS OLDNEWS options.c ) );
805d8ac4 209
6d12a859
WD
210foreach my $fn (@tweak_files) {
211 open(IN, '<', $fn) or die $!;
212 undef $/; $_ = <IN>; $/ = "\n";
213 close IN;
214 if ($fn =~ /configure/) {
800a4485
WD
215 s/^RSYNC_VERSION=.*/RSYNC_VERSION=$version/m
216 or die "Unable to update RSYNC_VERSION in $fn\n";
6d12a859 217 } elsif ($fn =~ /\.spec/) {
800a4485
WD
218 while (my($str, $val) = each %specvars) {
219 s/^\Q$str\E .*/$str $val/m
220 or die "Unable to update $str in $fn\n";
221 }
222 s/^\* \w\w\w \w\w\w \d\d \d\d\d\d (.*)/$cl_today $1/m
223 or die "Unable to update ChangeLog header in $fn\n";
6d12a859 224 } elsif ($fn =~ /\.yo/) {
800a4485
WD
225 s/^(manpage\([^)]+\)\(\d+\)\()[^)]+(\).*)/$1$today$2/m
226 or die "Unable to update date in manpage() header in $fn\n";
227 s/^(This man ?page is current for version) \S+ (of rsync)/$1 $version $2/m
228 or die "Unable to update current version info in $fn\n";
2e4a3d17 229 } elsif ($fn eq 'rsync.h') {
4f282b0b
WD
230 s{(#define\s+SUBPROTOCOL_VERSION)\s+(\d+)}
231 { $1 . ' ' . get_subprotocol_version($2) }e
800a4485 232 or die "Unable to find SUBPROTOCOL_VERSION define in $fn\n";
800a4485 233 } elsif ($fn eq 'NEWS') {
4f282b0b
WD
234 s{^(NEWS for rsync \Q$finalversion\E )(\(UNRELEASED\))\s*(\nProtocol: )(\d+) (\([^)]+\))\n}
235 { $1 . ($pre ? $2 : "($today)") . "$3$protocol_version ($proto_changed)\n" }ei
236 or die "The first 2 lines of $fn are not in the right format. They must be:\n"
237 . "NEWS for rsync $finalversion (UNRELEASED)\n"
238 . "Protocol: $protocol_version ($proto_changed)\n";
178a1d20 239 } elsif ($fn eq 'OLDNEWS') {
4f282b0b
WD
240 s{^(\t\S\S\s\S\S\S\s\d\d\d\d)(\t\Q$finalversion\E\t).*}
241 { ($pre ? $1 : "\t$ztoday") . $2 . $proto_change_date . $protocol_version }em
800a4485 242 or die "Unable to find \"?? ??? $year\t$finalversion\" line in $fn\n";
fede3785 243 } elsif ($fn eq 'options.c') {
800a4485
WD
244 if (s/(Copyright \(C\) 2002-)(\d+)( Wayne Davison)/$1$year$3/
245 && $2 ne $year) {
246 die "Copyright comments need to be updated to $year in all files!\n";
247 }
248 # Adjust the year in the --version output.
249 s/(rprintf\(f, "Copyright \(C\) 1996-)(\d+)/$1$year/
250 or die "Unable to find Copyright string in --version output of $fn\n";
251 next if $2 eq $year;
6d12a859 252 } else {
178a1d20 253 die "Unrecognized file in \@tweak_files: $fn\n";
6d12a859
WD
254 }
255 open(OUT, '>', $fn) or die $!;
256 print OUT $_;
257 close OUT;
258}
259
5fa38cd6 260print $break;
6a2456c5 261system "git diff --color | less -p '^diff .*'";
5fa38cd6 262
805d8ac4
WD
263my $srctar_name = "rsync-$version.tar.gz";
264my $pattar_name = "rsync-patches-$version.tar.gz";
e60bba3f 265my $diff_name = "rsync-$lastversion-$version.diffs.gz";
e63d3a29
WD
266my $srctar_file = "$dest/$srcdir/$srctar_name";
267my $pattar_file = "$dest/$srcdir/$pattar_name";
268my $diff_file = "$dest/$srcdiffdir/$diff_name";
269my $news_file = "$dest/$srcdir/rsync-$version-NEWS";
270my $lasttar_file = "$dest/$lastsrcdir/rsync-$lastversion.tar.gz";
5fa38cd6
WD
271
272print $break, <<EOT;
6d12a859 273
805d8ac4 274About to:
798a9e4e 275 - commit all version changes
56fc9f70 276 - merge the $master_branch branch into the patch/* branches
798a9e4e
WD
277 - update the files in the "patches" dir and OPTIONALLY
278 (if you type 'y') to launch a shell for each patch
279
280EOT
281print "<Press Enter OR 'y' to continue> ";
282my $ans = <STDIN>;
283
284system "git commit -a -m 'Preparing for release of $version'" and exit 1;
285
286print "Updating files in \"patches\" dir ...\n";
56fc9f70 287system "packaging/patch-update --branch=$master_branch";
798a9e4e
WD
288
289if ($ans =~ /^y/i) {
290 print "\nVisiting all \"patch/*\" branches ...\n";
56fc9f70 291 system "packaging/patch-update --branch=$master_branch --shell";
798a9e4e
WD
292}
293
294print $break, <<EOT;
295
296About to:
297 - create signed tag for this release: v$version
298 - create release diffs, "$diff_name"
805d8ac4 299 - create release tar, "$srctar_name"
798a9e4e 300 - generate rsync-$version/patches/* files
805d8ac4 301 - create patches tar, "$pattar_name"
798a9e4e
WD
302 - update top-level README, *NEWS, TODO, and ChangeLog
303 - update top-level rsync*.html manpages
805d8ac4 304 - gpg-sign the release files
798a9e4e 305 - update hard-linked top-level release files$skipping
6d12a859
WD
306
307EOT
308print "<Press Enter to continue> ";
309$_ = <STDIN>;
310
798a9e4e
WD
311my $passphrase;
312while (1) {
313 ReadMode('noecho');
314 print "\nEnter your GPG pass-phrase: ";
315 chomp($passphrase = <STDIN>);
316 ReadMode(0);
317 print "\n";
318
319 # Briefly create a temp file with the passphrase for git's tagging use.
320 my $oldmask = umask 077;
321 unlink($passfile);
322 open(OUT, '>', $passfile) or die $!;
323 print OUT $passphrase, "\n";
324 close OUT;
325 umask $oldmask;
326 $ENV{'GPG_PASSFILE'} = $passfile;
327
328 # We want to use our passphrase-providing "gpg" script, so modify the PATH.
329 $ENV{PATH} = "packaging/bin:$path";
330 $_ = `git tag -s -m 'Version $version.' v$version 2>&1`;
331 $ENV{PATH} = $path;
332 unlink($passfile);
333 print $_;
334 next if /bad passphrase/;
335 last unless /failed/;
336 exit 1;
337}
6d12a859 338
e63d3a29 339# Extract the generated files from the old tar.
4bb319c6
WD
340@_ = @extra_files;
341map { s#^#rsync-$lastversion/# } @_;
342system "tar xzf $lasttar_file @_";
343rename("rsync-$lastversion", 'a');
344
5fa38cd6 345print "Creating $diff_file ...\n";
4da9fcd4 346system "./config.status Makefile; make gen; rsync -a @extra_files b/";
ee8a733d 347my $sed_script = 's:^((---|\+\+\+) [ab]/[^\t]+)\t.*:\1:';
62ca3826 348system "(git diff v$lastversion v$version; diff -upN a b | sed -r '$sed_script') | gzip -9 >$diff_file";
9217ce30
WD
349system "rm -rf a";
350rename('b', "rsync-$version");
351
352print "Creating $srctar_file ...\n";
353system "git archive --format=tar --prefix=rsync-$version/ v$version | tar xf -";
354system "support/git-set-file-times --prefix=rsync-$version/";
355system "fakeroot tar czf $srctar_file rsync-$version; rm -rf rsync-$version";
805d8ac4 356
798a9e4e 357print "Updating files in \"rsync-$version/patches\" dir ...\n";
4da9fcd4
WD
358mkdir("rsync-$version", 0755);
359mkdir("rsync-$version/patches", 0755);
56fc9f70 360system "packaging/patch-update --skip-check --branch=$master_branch --gen=rsync-$version/patches";
798a9e4e
WD
361
362print "Creating $pattar_file ...\n";
4da9fcd4 363system "fakeroot tar chzf $pattar_file rsync-$version/patches; rm -rf rsync-$version";
6d12a859 364
5fa38cd6 365print "Updating the other files in $dest ...\n";
805d8ac4 366system "rsync -a README NEWS OLDNEWS TODO $dest";
e63d3a29
WD
367unlink($news_file);
368link("$dest/NEWS", $news_file);
eaa28e65 369system "git log --name-status | gzip -9 >$dest/ChangeLog.gz";
6d12a859 370
805d8ac4
WD
371system "yodl2html -o $dest/rsync.html rsync.yo";
372system "yodl2html -o $dest/rsyncd.conf.html rsyncd.conf.yo";
6d12a859 373
e63d3a29 374foreach my $fn ($srctar_file, $pattar_file, $diff_file) {
798a9e4e
WD
375 unlink("$fn.asc");
376 open(GPG, '|-', "gpg --batch --passphrase-fd=0 -ba $fn") or die $!;
377 print GPG $passphrase, "\n";
378 close GPG;
e0fe5231 379}
e63d3a29 380
99ba99c7 381if (!$pre) {
2551c47e 382 system "rm $dest/rsync-*.gz $dest/rsync-*.asc $dest/rsync-*-NEWS $dest/src-previews/rsync-*diffs.gz*";
e63d3a29
WD
383
384 foreach my $fn ($srctar_file, "$srctar_file.asc",
385 $pattar_file, "$pattar_file.asc",
386 $diff_file, "$diff_file.asc", $news_file) {
387 (my $top_fn = $fn) =~ s#/src(-\w+)?/#/#;
388 link($fn, $top_fn);
389 }
390}
391
e0fe5231 392print $break, <<'EOT';
6d12a859 393
e0fe5231
WD
394Local changes are done. When you're satisfied, push the git repository
395and rsync the release files. Remember to announce the release on *BOTH*
396rsync-announce@lists.samba.org and rsync@lists.samba.org (and the web)!
6d12a859 397EOT
56fc9f70
WD
398
399exit;
400
4f282b0b
WD
401sub get_subprotocol_version
402{
403 my($subver) = @_;
404 if ($pre && $proto_changed eq 'changed') {
405 return $subver == 0 ? 1 : $subver;
406 }
407 0;
408}
409
56fc9f70
WD
410sub usage
411{
412 die <<EOT;
413Usage: release-rsync [OPTIONS]
414
415-b, --branch=BRANCH The branch to release (default: master)
416-h, --help Display this help message
417EOT
418}