Fixed a bug where the NEWS file got an extra newline inserted when
[rsync/rsync.git] / packaging / release-rsync
CommitLineData
6d12a859
WD
1#!/usr/bin/perl
2use strict;
3
4# This script expects the directory ~/samba-rsync-ftp to exist and to
5# be a copy of the /home/ftp/pub/rsync dir on samba.org. If it is run
6# in test mode, it instead expects a dir named ~/tmp/samba-rsync-ftp
7# (e.g. copy ~/samba-rsync-ftp into ~/tmp and you can do a trial-run of
8# a release without affecting the files in the ~/samba-rsync-ftp dir).
9#
10# Run this as "release-rsync live" to affect ~/samba-rsync-ftp instead
11# of ~/tmp/samba-rsync-ftp.
12
13use Date::Format;
14
15my $dest = $ENV{HOME} . '/samba-rsync-ftp';
16my $releasedir = $ENV{HOME} . '/release';
17my $cvsroot = $ENV{CVSROOT} = 'samba.org:/data/cvs';
18
19my $ztoday = time2str('%d %b %Y', time);
20my $today = $ztoday;
21$today =~ s/^0//;
22
5fa38cd6
WD
23my $break = <<EOT;
24==========================================================================
6d12a859
WD
25EOT
26my $note = <<EOT;
5fa38cd6 27== Note: type "-a u,n" if you want to auto-accept the U,N suggestions. ==
6d12a859
WD
28EOT
29
30my $live = shift;
4d8639eb 31my $skipping = '';
6d12a859 32
5fa38cd6 33print $break;
6d12a859 34if ($live) {
5fa38cd6
WD
35 print <<EOT;
36== This will release a new version of rsync onto an unsuspecting world. ==
37EOT
6d12a859 38} else {
5fa38cd6
WD
39 print <<EOT;
40== **** TESTMODE **** (Add "live" arg to avoid this.) ==
41EOT
6d12a859 42 $dest =~ s#([^/]+$)#tmp/$1#;
4d8639eb 43 $skipping = ' ** SKIPPING **';
6d12a859
WD
44}
45die "$dest does not exist\n" unless -d $dest;
46
5fa38cd6 47print $break, "\nChecking out the latest rsync into $releasedir ...\n";
519c8de1
WD
48
49mkdir($releasedir, 0755) or die $! unless -d $releasedir;
50chdir($releasedir) or die $!;
51
5fa38cd6
WD
52system 'rm -rf rsync';
53
54my(%dirs, @files);
55open(CVS, '-|', 'cvs checkout -P rsync') or die $!;
56while (<CVS>) {
57 print $_;
58 next if /\.(cvs)?ignore$/;
59 if (m#^[UP] rsync/(.*)#) {
60 my $fn = $1;
61 my($dir) = $fn =~ m#^(.+)/#;
62 push(@files, $dir) if defined($dir) && !$dirs{$1}++;
63 push(@files, $fn);
64 }
65}
519c8de1
WD
66
67chdir('rsync') or die $!;
68
69my($version, $lastversion);
70open(IN, 'configure.in') or die $!;
71while (<IN>) {
72 if (/^RSYNC_VERSION=(.*)/) {
73 $version = $lastversion = $1;
74 last;
75 }
76}
77close IN;
78
79$lastversion =~ s/(\d+)cvs$/ $1 - 1 /e;
80$version =~ s/cvs/pre1/ || $version =~ s/pre(\d+)/ 'pre' . ($1 + 1) /e;
81
5fa38cd6 82print $break, "\nPlease enter the version number of this release: [$version] ";
519c8de1
WD
83chomp($_ = <STDIN>);
84if ($_ eq '.') {
85 $version =~ s/pre\d+//;
86} elsif ($_ ne '') {
87 $version = $_;
88}
6d12a859
WD
89$version =~ s/[-.]*pre[-.]*/pre/;
90
519c8de1
WD
91$lastversion =~ s/(\d+)pre\d+$/ $1 - 1 /e unless $version =~ /pre/;
92
6d12a859
WD
93my $cvstag = "release-$version";
94$cvstag =~ s/[.]/-/g;
95$cvstag =~ s/pre/-pre/;
96
519c8de1
WD
97print "Enter the previous version to produce a patch against: [$lastversion] ";
98chomp($_ = <STDIN>);
99$lastversion = $_ if $_ ne '';
6d12a859
WD
100$lastversion =~ s/[-.]*pre[-.]*/pre/;
101
519c8de1
WD
102my $release = 1;
103print "Please enter the RPM release number of this release: [$release] ";
104chomp($_ = <STDIN>);
105$release = $_ if $_ ne '';
6d12a859
WD
106
107my $diffdir;
5fa38cd6 108my $skipping2;
6d12a859
WD
109if ($lastversion =~ /pre/) {
110 if ($version !~ /pre/) {
111 die "You should not diff a release version against a pre-release version.\n";
112 }
113 $diffdir = "$dest/old-previews";
5fa38cd6 114 $skipping2 = ' ** SKIPPING **';
6d12a859
WD
115} elsif ($version =~ /pre/) {
116 $diffdir = $dest;
5fa38cd6 117 $skipping2 = ' ** SKIPPING **';
6d12a859
WD
118} else {
119 $diffdir = "$dest/old-versions";
5fa38cd6 120 $skipping2 = '';
6d12a859
WD
121}
122
5fa38cd6 123print "\n", $break, <<EOT;
6d12a859
WD
124\$version is "$version"
125\$lastversion is "$lastversion"
126\$cvstag is "$cvstag"
127\$dest is "$dest"
128\$releasedir is "$releasedir"
129\$diffdir is "$diffdir"
130\$release is "$release"
131
132About to:
5fa38cd6 133 - make sure that configure, config.h.in, and proto.h are updated
6d12a859 134 - tweak the version in configure.in, configure, and the spec files
5fa38cd6 135 - tweak NEWS and OLDNEWS to update the release date$skipping2
6d12a859
WD
136 - tweak the date in the *.yo files and re-generate the man pages
137 - make sure that the patches dir has been updated
138 - page through the "cvs diff" output
139
140EOT
141print "<Press Enter to continue> ";
142$_ = <STDIN>;
c2b2bd6a 143my $f_opt = /f/ ? ' -f' : '';
6d12a859 144
5fa38cd6 145print $break;
6d12a859
WD
146system "./prepare-source && touch proto.h";
147
148my @tweak_files = ( glob('packaging/*.spec'), glob('packaging/*/*.spec'),
149 glob('*.yo'), qw( configure.in configure ) );
150if ($version !~ /pre/) {
151 push(@tweak_files, qw( NEWS OLDNEWS ));
152}
153foreach my $fn (@tweak_files) {
154 open(IN, '<', $fn) or die $!;
155 undef $/; $_ = <IN>; $/ = "\n";
156 close IN;
157 if ($fn =~ /configure/) {
158 s/^RSYNC_VERSION.*/RSYNC_VERSION=$version/m;
159 } elsif ($fn =~ /\.spec/) {
160 s/^(Version:) .*/$1 $version/m;
161 s/^(Release:) .*/$1 $release/m;
162 } elsif ($fn =~ /\.yo/) {
163 s/^(manpage\([^)]+\)\(\d+\)\()[^)]+(\).*)/$1$today$2/m;
164 s/^(This man ?page is current for version) \S+ (of rsync)/$1 $version $2/m;
165 } else {
1b1628b9 166 s/^(NEWS for rsync \Q$version\E) \(UNRELEASED\)\s*\n/$1 ($today)\n/m;
6d12a859
WD
167 s/^\t\S\S\s\S\S\S\s\d\d\d\d(\t\Q$version\E)/\t$ztoday$1/m;
168 }
169 open(OUT, '>', $fn) or die $!;
170 print OUT $_;
171 close OUT;
172}
173
174system "yodl2man -o rsync.1 rsync.yo";
175system "yodl2man -o rsyncd.conf.5 rsyncd.conf.yo";
176#system "perl -pi -e \"s/\\\\\\'/\\\\&'/g\" rsync.1 rsyncd.conf.5";
177
178mkdir('patches/tmp') or die $!;
179system "rsync -a --exclude=patches/ --exclude-from=.cvsignore . patches/tmp/cvsdir/";
180
5fa38cd6 181print "\n", $break, $note, $break;
c2b2bd6a 182system "patches/verify-patches -n -an$f_opt";
6d12a859 183
5fa38cd6 184print $break;
6d12a859
WD
185system "cvs -q diff | egrep -v '^(===============|RCS file: |retrieving revision |Index: )' | less -p '^diff .*'";
186
5fa38cd6 187print $break, <<EOT;
6d12a859
WD
188
189About to:
4d8639eb
WD
190 - "cvs commit" all changes$skipping
191 - "cvs tag" this release as $cvstag$skipping
5fa38cd6 192 - change the diffs in the patches dir to include generated files
6d12a859
WD
193
194EOT
5fa38cd6
WD
195print "<Press Enter to continue> ";
196$_ = <STDIN>;
6d12a859 197
5fa38cd6 198if ($live) {
6d12a859
WD
199 system "cvs commit -m 'Preparing for release of $version'";
200 system "cvs tag -F $cvstag .";
6d12a859
WD
201}
202
5fa38cd6
WD
203if (!/skip/i) {
204 print "\n", $break, $note, $break;
205 system "patches/verify-patches -pun -an";
206}
207
208my $tar_file = "$dest/rsync-$version.tar.gz";
209my $diff_file = "$dest/rsync-$lastversion-$version.diffs.gz";
210
211print $break, <<EOT;
6d12a859
WD
212
213About to do the following in the samba-rsync-ftp dir:
4d8639eb 214 - move the old tar/diff files into the appropriate old-* dirs
d775372a 215 - hard-link moved tar/diff files to old files on samba.org$skipping
5fa38cd6
WD
216 - create release tar, "$tar_file"
217 - create release diffs, "$diff_file"
6d12a859
WD
218 - update README, *NEWS, TODO, and cvs.log
219 - update rsync*.html man pages
220
221EOT
222print "<Press Enter to continue> ";
223$_ = <STDIN>;
224
6d12a859
WD
225chdir($releasedir) or die $!;
226
5fa38cd6
WD
227print $break;
228system "rm -rf rsync-$version";
229rename('rsync', "rsync-$version") or die $!;
6d12a859
WD
230
231# When creating a pre-release after a normal release, there's nothing to move.
232if ($diffdir ne $dest) {
233 chdir($dest) or die $!;
234
5fa38cd6
WD
235 print "Shuffling old files ...\n";
236
519c8de1
WD
237 # We need to run this regardless of $lastversion's "pre"ness.
238 my @moved_files;
6d12a859 239 foreach my $fn (glob('rsync*pre*.tar.gz*'), glob('rsync*pre*-NEWS')) {
c2b2bd6a
WD
240 my $new_fn = "old-previews/$fn";
241 rename($fn, $new_fn) or die $!;
242 push(@moved_files, $new_fn);
6d12a859 243 }
6d12a859
WD
244
245 if ($version !~ /pre/) {
246 foreach my $fn (glob('rsync*.tar.gz*'), glob('rsync*-NEWS')) {
4d8639eb 247 next if $fn =~ /^rsync.*pre/;
c2b2bd6a
WD
248 my $new_fn = "old-versions/$fn";
249 rename($fn, $new_fn) or die $!;
250 push(@moved_files, $new_fn);
6d12a859
WD
251 }
252
253 foreach my $fn (glob('rsync*.diffs.gz*')) {
4d8639eb 254 next if $fn =~ /^rsync.*pre/;
c2b2bd6a
WD
255 my $new_fn = "old-patches/$fn";
256 rename($fn, $new_fn) or die $!;
257 push(@moved_files, $new_fn);
6d12a859
WD
258 }
259 }
260
519c8de1 261 # Optimize our future upload (in the absence of --detect-renamed) by
1b1628b9 262 # copying the above moved files on the remote server.
519c8de1 263 if ($live) {
c2b2bd6a
WD
264 my $remote_cmd = '';
265 foreach (@moved_files) {
266 my($path, $fn) = m#(.*)/([^/]+)$#;
1b1628b9 267 $remote_cmd .= "cp -p /home/ftp/pub/rsync/{$fn,$path};";
c2b2bd6a
WD
268 }
269 system "ssh samba.org '$remote_cmd'";
519c8de1 270 }
c2b2bd6a 271 foreach (glob("rsync*pre*.diffs.gz*")) {
519c8de1
WD
272 unlink($_);
273 }
274
6d12a859
WD
275 chdir($releasedir) or die $!;
276}
6d12a859 277
5fa38cd6
WD
278print "Creating $tar_file ...\n";
279system "fakeroot tar czf $tar_file rsync-$version";
651dc65e 280open(TAR, '|-', "fakeroot tar --files-from=- --no-recursion --mode=g+w -czf $tar_file rsync-$version") or die $!;
5fa38cd6
WD
281foreach (@files) {
282 print TAR "rsync-$version/$_\n";
283}
284close TAR;
285
286print "Creating $diff_file ...\n";
287system "rm -rf rsync-$version rsync-$lastversion";
288system "tar xzf $tar_file; tar xzf $diffdir/rsync-$lastversion.tar.gz";
6d12a859
WD
289## TWEAK THE VERSIONS AS DESIRED HERE ##
290#mkdir("rsync-$lastversion/support", 0755) or die $!;
291#rename("rsync-$lastversion/rsyncstats", "rsync-$lastversion/support/rsyncstats");
5fa38cd6 292unlink("rsync-$lastversion/.ignore");
6d12a859 293## END ##
5fa38cd6 294system "diff -urN --exclude=patches rsync-$lastversion rsync-$version| gzip -9 >$diff_file";
6d12a859 295
5fa38cd6
WD
296print "Updating the other files in $dest ...\n";
297system "rsync -a rsync-$version/{README,NEWS,OLDNEWS,TODO} $dest";
6d12a859
WD
298unlink("$dest/rsync-$version-NEWS");
299link("$dest/NEWS", "$dest/rsync-$version-NEWS");
300system "rsync -a $cvsroot/CVSROOT/rsync.updates $dest/cvs.log";
301
5fa38cd6
WD
302system "yodl2html -o $dest/rsync.html rsync-$version/rsync.yo";
303system "yodl2html -o $dest/rsyncd.conf.html rsync-$version/rsyncd.conf.yo";
6d12a859 304
5fa38cd6 305system "rm -rf rsync-*";
6d12a859
WD
306
307if ($live) {
308 chdir($dest) or die $!;
309 system "gpg -ba rsync-$version.tar.gz";
310 system "gpg -ba rsync-$lastversion-$version.diffs.gz";
311}
312
5fa38cd6 313print $break, <<EOT;
6d12a859
WD
314
315All done. Remember to announce the release on *BOTH*
316rsync-announce\@lists.samba.org and rsync\@lists.samba.org!
317EOT