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