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