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