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