Updated copyright year in --version output and improved the 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 be a
5 # copy of the /home/ftp/pub/rsync dir on samba.org.  When the script is done,
6 # the git repository in the current directory will be updated, and the local
7 # ~/samba-rsync-ftp dir will be ready to be rsynced to samba.org.
8
9 use Cwd;
10 use Date::Format;
11
12 my $dest = $ENV{HOME} . '/samba-rsync-ftp';
13
14 my $now = time;
15 my $cl_today = time2str('* %a %b %d %Y', $now);
16 my $year = time2str('%Y', $now);
17 my $ztoday = time2str('%d %b %Y', $now);
18 (my $today = $ztoday) =~ s/^0//;
19
20 my $curdir = Cwd::cwd;
21
22 my @extra_files;
23 open(IN, '<', 'Makefile.in') or die "Couldn't open Makefile.in: $!\n";
24 while (<IN>) {
25     if (s/^GENFILES=//) {
26         while (s/\\$//) {
27             $_ .= <IN>;
28         }
29         @extra_files = split(' ', $_);
30         last;
31     }
32 }
33 close IN;
34
35 my $break = <<EOT;
36 ==========================================================================
37 EOT
38
39 print $break, <<EOT, $break, "\n";
40 == This will release a new version of rsync onto an unsuspecting world. ==
41 EOT
42
43 die "$dest does not exist\n" unless -d $dest;
44 die "There is no .git dir in the current directory.\n" unless -d '.git';
45 die "'a' must not exist in the current directory.\n" if -e 'a';
46 die "'b' must not exist in the current directory.\n" if -e 'b';
47
48 open(IN, '-|', 'git status') or die $!;
49 my $status = join('', <IN>);
50 close IN;
51 die "The checkout is not clean:\n", $status unless $status =~ /\nnothing to commit \(working directory clean\)/;
52 die "The checkout is not on the master branch.\n" unless $status =~ /^# On branch master\n/;
53
54 my $confversion;
55 open(IN, '<', 'configure.in') or die $!;
56 while (<IN>) {
57     if (/^RSYNC_VERSION=(.*)/) {
58         $confversion = $1;
59         last;
60     }
61 }
62 close IN;
63 die "Unable to find RSYNC_VERSION in configure.in\n" unless defined $confversion;
64
65 open(IN, '<', 'OLDNEWS') or die $!;
66 $_ = <IN>;
67 close IN;
68 my($lastversion) = /(\d+\.\d+\.\d+)/;
69
70 my $version = $confversion;
71 $version =~ s/dev/pre1/ || $version =~ s/pre(\d+)/ 'pre' . ($1 + 1) /e;
72
73 print "Please enter the version number of this release: [$version] ";
74 chomp($_ = <STDIN>);
75 if ($_ eq '.') {
76     $version =~ s/pre\d+//;
77 } elsif ($_ ne '') {
78     $version = $_;
79 }
80
81 if ($version =~ s/[-.]*pre[-.]*/pre/ && $confversion !~ /dev$/) {
82     $lastversion = $confversion;
83 }
84
85 print "Enter the previous version to produce a patch against: [$lastversion] ";
86 chomp($_ = <STDIN>);
87 $lastversion = $_ if $_ ne '';
88 $lastversion =~ s/[-.]*pre[-.]*/pre/;
89
90 my $release = 1;
91 print "Please enter the RPM release number of this release: [$release] ";
92 chomp($_ = <STDIN>);
93 $release = $_ if $_ ne '';
94
95 my $diffdir;
96 my $skipping;
97 if ($lastversion =~ /pre/) {
98     if ($version !~ /pre/) {
99         die "You should not diff a release version against a pre-release version.\n";
100     }
101     $diffdir = "$dest/old-previews";
102     $skipping = ' ** SKIPPING **';
103 } elsif ($version =~ /pre/) {
104     $diffdir = $dest;
105     $skipping = ' ** SKIPPING **';
106 } else {
107     $diffdir = "$dest/old-versions";
108     $skipping = '';
109 }
110
111 print "\n", $break, <<EOT;
112 \$version is "$version"
113 \$lastversion is "$lastversion"
114 \$dest is "$dest"
115 \$curdir is "$curdir"
116 \$diffdir is "$diffdir"
117 \$release is "$release"
118
119 About to:
120     - make sure that SUBPROTOCOL_VERSION is 0$skipping
121     - tweak the version in configure.in and the spec files
122     - tweak NEWS and OLDNEWS to update the release date$skipping
123     - tweak the date in the *.yo files and generate the man pages
124     - generate configure.sh, config.h.in, and proto.h
125     - page through the differences
126
127 EOT
128 print "<Press Enter to continue> ";
129 $_ = <STDIN>;
130
131 my @tweak_files = ( glob('packaging/*.spec'), glob('packaging/*/*.spec'),
132                     glob('*.yo'), qw( configure.in options.c ) );
133
134 if ($version !~ /pre/) {
135     push(@tweak_files, qw( rsync.h NEWS OLDNEWS ));
136 }
137 foreach my $fn (@tweak_files) {
138     open(IN, '<', $fn) or die $!;
139     undef $/; $_ = <IN>; $/ = "\n";
140     close IN;
141     if ($fn =~ /configure/) {
142         s/^RSYNC_VERSION=.*/RSYNC_VERSION=$version/m;
143     } elsif ($fn =~ /\.spec/) {
144         s/^(Version:) .*/$1 $version/m;
145         s/^(Release:) .*/$1 $release/m;
146         s/^(Released) .*/$1 $version./m;
147         s/^\* \w\w\w \w\w\w \d\d \d\d\d\d (.*)/$cl_today $1/m;
148     } elsif ($fn =~ /\.yo/) {
149         s/^(manpage\([^)]+\)\(\d+\)\()[^)]+(\).*)/$1$today$2/m;
150         s/^(This man ?page is current for version) \S+ (of rsync)/$1 $version $2/m;
151     } elsif ($fn eq 'NEWS') {
152         s/^(NEWS for rsync \Q$version\E) \(UNRELEASED\)\s*\n/$1 ($today)\n/mi
153             or die "Couldn't update NEWS file with release date!\n";
154     } elsif ($fn eq 'rsync.h') {
155         s/(#define\s+SUBPROTOCOL_VERSION)\s+\d+/$1 0/;
156     } elsif ($fn eq 'OLDNEWS') {
157         s/^\t\S\S\s\S\S\S\s\d\d\d\d(\t\Q$version\E)/\t$ztoday$1/m
158             or die "Couldn't update OLDNEWS file with release date!\n";
159     } elsif ($fn eq 'options.c') {
160         s/(rprintf\(f, "Copyright \(C\) 1996-)\d+/$1$year/;
161         s/(Copyright \(C\) 2002-)\d+( Wayne Davison)/$1$year$2/;
162     } else {
163         die "Unrecognized file in \@tweak_files: $fn\n";
164     }
165     open(OUT, '>', $fn) or die $!;
166     print OUT $_;
167     close OUT;
168 }
169
170 print $break;
171 system "git diff --color | less -p '^diff .*'";
172
173 my $srctar_name = "rsync-$version.tar.gz";
174 my $pattar_name = "rsync-patches-$version.tar.gz";
175 my $diff_name = "rsync-$lastversion-$version.diffs.gz";
176 my $srctar_file = "$dest/$srctar_name";
177 my $pattar_file = "$dest/$pattar_name";
178 my $diff_file = "$dest/$diff_name";
179 my $lasttar_file = "$dest/rsync-$lastversion.tar.gz";
180
181 print $break, <<EOT;
182
183 About to:
184     - commit all changes
185     - tag this release as v$version
186     - move the old tar/diff files into the appropriate old-* dirs
187     - hard-link the moved tar/diff files on samba.org
188     - create release tar, "$srctar_name"
189     - create patches tar, "$pattar_name"
190     - create release diffs, "$diff_name"
191     - update patch branches and generate patch/* files
192     - update README, *NEWS, TODO, and ChangeLog
193     - update rsync*.html man pages
194     - gpg-sign the release files
195
196 EOT
197 print "<Press Enter to continue> ";
198 $_ = <STDIN>;
199
200 system "git commit -a -m 'Preparing for release of $version'" and exit 1;
201 print "\nSign the tag:";
202 system "git tag -s -m 'Version $version.' v$version" and exit 1;
203
204 # Extract some files from the old tar before we do the shuffle.
205 @_ = @extra_files;
206 map { s#^#rsync-$lastversion/# } @_;
207 system "tar xzf $lasttar_file @_";
208 rename("rsync-$lastversion", 'a');
209
210 # When creating a pre-release after a normal release, there's nothing to move.
211 if ($diffdir ne $dest) {
212     chdir($dest) or die $!;
213
214     print "Shuffling old files ...\n";
215
216     # We need to run this regardless of $lastversion's "pre"ness.
217     my @moved_files;
218     foreach my $fn (glob('rsync*pre*.tar.gz*'), glob('rsync*pre*-NEWS')) {
219         link($fn, "old-previews/$fn") or die $!;
220         push(@moved_files, $fn);
221     }
222
223     if ($version !~ /pre/) {
224         foreach my $fn (glob('rsync*.tar.gz*'), glob('rsync*-NEWS')) {
225             next if $fn =~ /^rsync.*pre/;
226             link($fn, "old-versions/$fn") or die $!;
227             push(@moved_files, $fn);
228         }
229
230         foreach my $fn (glob('rsync*pre*.diffs.gz*')) {
231             unlink($fn);
232         }
233
234         foreach my $fn (glob('rsync*.diffs.gz*')) {
235             link($fn, "old-patches/$fn") or die $!;
236             push(@moved_files, $fn);
237         }
238     }
239
240     # Optimize our future upload (in the absence of --detect-renamed) by
241     # using rsync to hard-link the above files on samba.org.
242     system "rsync -avHOC --include='rsync*.gz*' --include='old-*/' --exclude='*' . samba.org:/home/ftp/pub/rsync";
243     foreach (@moved_files) {
244         unlink($_);
245     }
246
247     chdir($curdir) or die $!;
248 }
249
250 print "Creating $diff_file ...\n";
251 system "./config.status Makefile; make gen; rsync -a @extra_files b/";
252 my $sed_script = 's:^((---|\+\+\+) [ab]/[^\t]+)\t.*:\1:';
253 system "(git diff v$lastversion v$version; diff -upN a b | sed -r '$sed_script') | gzip -9 >$diff_file";
254 system "rm -rf a";
255 rename('b', "rsync-$version");
256
257 print "Creating $srctar_file ...\n";
258 system "git archive --format=tar --prefix=rsync-$version/ v$version | tar xf -";
259 system "support/git-set-file-times --prefix=rsync-$version/";
260 system "fakeroot tar czf $srctar_file rsync-$version; rm -rf rsync-$version";
261
262 mkdir("rsync-$version", 0755);
263 mkdir("rsync-$version/patches", 0755);
264 system "support/patch-update --skip-check --gen=rsync-$version/patches";
265 system "fakeroot tar chzf $pattar_file rsync-$version/patches; rm -rf rsync-$version";
266
267 print "Updating the other files in $dest ...\n";
268 system "rsync -a README NEWS OLDNEWS TODO $dest";
269 unlink("$dest/rsync-$version-NEWS");
270 link("$dest/NEWS", "$dest/rsync-$version-NEWS");
271 system "git log --name-status | gzip -9 >$dest/ChangeLog.gz";
272
273 system "yodl2html -o $dest/rsync.html rsync.yo";
274 system "yodl2html -o $dest/rsyncd.conf.html rsyncd.conf.yo";
275
276 chdir($dest) or die $!;
277 my $cnt = 0;
278 foreach my $fn ($srctar_name, $pattar_name, $diff_name) {
279     print ++$cnt, ". Sign file \"$fn\":";
280     system "gpg -ba $fn";
281 }
282 print $break, <<'EOT';
283
284 Local changes are done.  When you're satisfied, push the git repository
285 and rsync the release files.  Remember to announce the release on *BOTH*
286 rsync-announce@lists.samba.org and rsync@lists.samba.org (and the web)!
287 EOT