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