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