Tweaked rsync.spec to use "rsync" in place of "%{name}" in a few
[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;
798a9e4e 10use Term::ReadKey;
6d12a859
WD
11use Date::Format;
12
13my $dest = $ENV{HOME} . '/samba-rsync-ftp';
798a9e4e
WD
14my $passfile = $ENV{HOME} . '/.rsyncpass';
15my $path = $ENV{PATH};
6d12a859 16
fede3785
WD
17my $now = time;
18my $cl_today = time2str('* %a %b %d %Y', $now);
19my $year = time2str('%Y', $now);
20my $ztoday = time2str('%d %b %Y', $now);
90ac152d 21(my $today = $ztoday) =~ s/^0//;
6d12a859 22
805d8ac4
WD
23my $curdir = Cwd::cwd;
24
798a9e4e
WD
25END {
26 unlink($passfile);
27}
28
67b9b26f
WD
29my @extra_files;
30open(IN, '<', 'Makefile.in') or die "Couldn't open Makefile.in: $!\n";
31while (<IN>) {
32 if (s/^GENFILES=//) {
33 while (s/\\$//) {
34 $_ .= <IN>;
35 }
36 @extra_files = split(' ', $_);
37 last;
38 }
39}
805d8ac4
WD
40close IN;
41
5fa38cd6
WD
42my $break = <<EOT;
43==========================================================================
6d12a859 44EOT
6d12a859 45
805d8ac4 46print $break, <<EOT, $break, "\n";
5fa38cd6
WD
47== This will release a new version of rsync onto an unsuspecting world. ==
48EOT
519c8de1 49
805d8ac4
WD
50die "$dest does not exist\n" unless -d $dest;
51die "There is no .git dir in the current directory.\n" unless -d '.git';
52die "'a' must not exist in the current directory.\n" if -e 'a';
53die "'b' must not exist in the current directory.\n" if -e 'b';
519c8de1 54
6a2456c5 55open(IN, '-|', 'git status') or die $!;
805d8ac4
WD
56my $status = join('', <IN>);
57close IN;
58die "The checkout is not clean:\n", $status unless $status =~ /\nnothing to commit \(working directory clean\)/;
59die "The checkout is not on the master branch.\n" unless $status =~ /^# On branch master\n/;
519c8de1 60
fede3785 61my $confversion;
578219be 62open(IN, '<', 'configure.in') or die $!;
519c8de1
WD
63while (<IN>) {
64 if (/^RSYNC_VERSION=(.*)/) {
fede3785 65 $confversion = $1;
519c8de1
WD
66 last;
67 }
68}
69close IN;
fede3785 70die "Unable to find RSYNC_VERSION in configure.in\n" unless defined $confversion;
2e4a3d17 71
62ca3826
WD
72open(IN, '<', 'OLDNEWS') or die $!;
73$_ = <IN>;
74close IN;
fede3785 75my($lastversion) = /(\d+\.\d+\.\d+)/;
62ca3826 76
fede3785 77my $version = $confversion;
805d8ac4 78$version =~ s/dev/pre1/ || $version =~ s/pre(\d+)/ 'pre' . ($1 + 1) /e;
519c8de1 79
805d8ac4 80print "Please enter the version number of this release: [$version] ";
519c8de1
WD
81chomp($_ = <STDIN>);
82if ($_ eq '.') {
83 $version =~ s/pre\d+//;
84} elsif ($_ ne '') {
85 $version = $_;
86}
798a9e4e
WD
87die "Invalid version: `$version'\n" unless $version =~ /^[\d.]+(pre\d+)?$/;
88
89if (`git tag -l v$version` ne '') {
90 print "Tag v$version already exists.\n\nDelete tag or quit? [q/del] ";
91 $_ = <STDIN>;
92 exit 1 unless /^del/i;
93 system "git tag -d v$version";
94}
fede3785
WD
95
96if ($version =~ s/[-.]*pre[-.]*/pre/ && $confversion !~ /dev$/) {
97 $lastversion = $confversion;
98}
6d12a859 99
519c8de1
WD
100print "Enter the previous version to produce a patch against: [$lastversion] ";
101chomp($_ = <STDIN>);
102$lastversion = $_ if $_ ne '';
6d12a859
WD
103$lastversion =~ s/[-.]*pre[-.]*/pre/;
104
99ba99c7
WD
105my $pre = $version =~ /(pre\d+)/ ? $1 : '';
106
107my $release = $pre ? '0.1' : '1';
519c8de1
WD
108print "Please enter the RPM release number of this release: [$release] ";
109chomp($_ = <STDIN>);
110$release = $_ if $_ ne '';
99ba99c7 111$release .= ".$pre" if $pre;
6d12a859 112
e63d3a29 113my($srcdir,$srcdiffdir,$lastsrcdir,$skipping);
6d12a859 114if ($lastversion =~ /pre/) {
99ba99c7 115 if (!$pre) {
6d12a859
WD
116 die "You should not diff a release version against a pre-release version.\n";
117 }
e63d3a29 118 $srcdir = $srcdiffdir = $lastsrcdir = 'src-previews';
805d8ac4 119 $skipping = ' ** SKIPPING **';
99ba99c7 120} elsif ($pre) {
e63d3a29
WD
121 $srcdir = $srcdiffdir = 'src-previews';
122 $lastsrcdir = 'src';
805d8ac4 123 $skipping = ' ** SKIPPING **';
6d12a859 124} else {
e63d3a29
WD
125 $srcdir = $lastsrcdir = 'src';
126 $srcdiffdir = 'src-diffs';
805d8ac4 127 $skipping = '';
6d12a859
WD
128}
129
5fa38cd6 130print "\n", $break, <<EOT;
6d12a859
WD
131\$version is "$version"
132\$lastversion is "$lastversion"
6d12a859 133\$dest is "$dest"
805d8ac4 134\$curdir is "$curdir"
e63d3a29
WD
135\$srcdir is "$srcdir"
136\$srcdiffdir is "$srcdiffdir"
137\$lastsrcdir is "$lastsrcdir"
6d12a859
WD
138\$release is "$release"
139
140About to:
805d8ac4
WD
141 - make sure that SUBPROTOCOL_VERSION is 0$skipping
142 - tweak the version in configure.in and the spec files
143 - tweak NEWS and OLDNEWS to update the release date$skipping
798a9e4e 144 - tweak the date in the *.yo files and generate the manpages
805d8ac4
WD
145 - generate configure.sh, config.h.in, and proto.h
146 - page through the differences
6d12a859
WD
147
148EOT
149print "<Press Enter to continue> ";
150$_ = <STDIN>;
151
800a4485 152(my $finalversion = $version) =~ s/pre\d+//;
99ba99c7
WD
153my %specvars = ( 'Version:' => $finalversion, 'Release:' => $release,
154 '%define fullversion' => "\%{version}$pre", 'Released' => "$version." );
800a4485
WD
155my @tweak_files = ( glob('packaging/*.spec'), glob('packaging/*/*.spec'), glob('*.yo'),
156 qw( configure.in rsync.h NEWS OLDNEWS options.c ) );
805d8ac4 157
6d12a859
WD
158foreach my $fn (@tweak_files) {
159 open(IN, '<', $fn) or die $!;
160 undef $/; $_ = <IN>; $/ = "\n";
161 close IN;
162 if ($fn =~ /configure/) {
800a4485
WD
163 s/^RSYNC_VERSION=.*/RSYNC_VERSION=$version/m
164 or die "Unable to update RSYNC_VERSION in $fn\n";
6d12a859 165 } elsif ($fn =~ /\.spec/) {
800a4485
WD
166 while (my($str, $val) = each %specvars) {
167 s/^\Q$str\E .*/$str $val/m
168 or die "Unable to update $str in $fn\n";
169 }
170 s/^\* \w\w\w \w\w\w \d\d \d\d\d\d (.*)/$cl_today $1/m
171 or die "Unable to update ChangeLog header in $fn\n";
6d12a859 172 } elsif ($fn =~ /\.yo/) {
800a4485
WD
173 s/^(manpage\([^)]+\)\(\d+\)\()[^)]+(\).*)/$1$today$2/m
174 or die "Unable to update date in manpage() header in $fn\n";
175 s/^(This man ?page is current for version) \S+ (of rsync)/$1 $version $2/m
176 or die "Unable to update current version info in $fn\n";
2e4a3d17 177 } elsif ($fn eq 'rsync.h') {
800a4485
WD
178 s/(#define\s+SUBPROTOCOL_VERSION)\s+\d+/$1 0/
179 or die "Unable to find SUBPROTOCOL_VERSION define in $fn\n";
99ba99c7 180 next if $pre;
800a4485
WD
181 } elsif ($fn eq 'NEWS') {
182 s/^(NEWS for rsync \Q$finalversion\E) \(UNRELEASED\)\s*\n/$1 ($today)\n/mi
183 or die "The first line of $fn is not in the right format. It must be:\n"
184 . "NEWS for rsync $finalversion (UNRELEASED)\n";
99ba99c7 185 next if $pre;
178a1d20 186 } elsif ($fn eq 'OLDNEWS') {
800a4485
WD
187 s/^\t\S\S\s\S\S\S\s\d\d\d\d(\t\Q$finalversion\E)/\t$ztoday$1/m
188 or die "Unable to find \"?? ??? $year\t$finalversion\" line in $fn\n";
99ba99c7 189 next if $pre;
fede3785 190 } elsif ($fn eq 'options.c') {
800a4485
WD
191 if (s/(Copyright \(C\) 2002-)(\d+)( Wayne Davison)/$1$year$3/
192 && $2 ne $year) {
193 die "Copyright comments need to be updated to $year in all files!\n";
194 }
195 # Adjust the year in the --version output.
196 s/(rprintf\(f, "Copyright \(C\) 1996-)(\d+)/$1$year/
197 or die "Unable to find Copyright string in --version output of $fn\n";
198 next if $2 eq $year;
6d12a859 199 } else {
178a1d20 200 die "Unrecognized file in \@tweak_files: $fn\n";
6d12a859
WD
201 }
202 open(OUT, '>', $fn) or die $!;
203 print OUT $_;
204 close OUT;
205}
206
5fa38cd6 207print $break;
6a2456c5 208system "git diff --color | less -p '^diff .*'";
5fa38cd6 209
805d8ac4
WD
210my $srctar_name = "rsync-$version.tar.gz";
211my $pattar_name = "rsync-patches-$version.tar.gz";
e60bba3f 212my $diff_name = "rsync-$lastversion-$version.diffs.gz";
e63d3a29
WD
213my $srctar_file = "$dest/$srcdir/$srctar_name";
214my $pattar_file = "$dest/$srcdir/$pattar_name";
215my $diff_file = "$dest/$srcdiffdir/$diff_name";
216my $news_file = "$dest/$srcdir/rsync-$version-NEWS";
217my $lasttar_file = "$dest/$lastsrcdir/rsync-$lastversion.tar.gz";
5fa38cd6
WD
218
219print $break, <<EOT;
6d12a859 220
805d8ac4 221About to:
798a9e4e
WD
222 - commit all version changes
223 - merge the master branch into the patch/* branches
224 - update the files in the "patches" dir and OPTIONALLY
225 (if you type 'y') to launch a shell for each patch
226
227EOT
228print "<Press Enter OR 'y' to continue> ";
229my $ans = <STDIN>;
230
231system "git commit -a -m 'Preparing for release of $version'" and exit 1;
232
233print "Updating files in \"patches\" dir ...\n";
234system "support/patch-update";
235
236if ($ans =~ /^y/i) {
237 print "\nVisiting all \"patch/*\" branches ...\n";
238 system "support/patch-update --shell";
239}
240
241print $break, <<EOT;
242
243About to:
244 - create signed tag for this release: v$version
245 - create release diffs, "$diff_name"
805d8ac4 246 - create release tar, "$srctar_name"
798a9e4e 247 - generate rsync-$version/patches/* files
805d8ac4 248 - create patches tar, "$pattar_name"
798a9e4e
WD
249 - update top-level README, *NEWS, TODO, and ChangeLog
250 - update top-level rsync*.html manpages
805d8ac4 251 - gpg-sign the release files
798a9e4e 252 - update hard-linked top-level release files$skipping
6d12a859
WD
253
254EOT
255print "<Press Enter to continue> ";
256$_ = <STDIN>;
257
798a9e4e
WD
258my $passphrase;
259while (1) {
260 ReadMode('noecho');
261 print "\nEnter your GPG pass-phrase: ";
262 chomp($passphrase = <STDIN>);
263 ReadMode(0);
264 print "\n";
265
266 # Briefly create a temp file with the passphrase for git's tagging use.
267 my $oldmask = umask 077;
268 unlink($passfile);
269 open(OUT, '>', $passfile) or die $!;
270 print OUT $passphrase, "\n";
271 close OUT;
272 umask $oldmask;
273 $ENV{'GPG_PASSFILE'} = $passfile;
274
275 # We want to use our passphrase-providing "gpg" script, so modify the PATH.
276 $ENV{PATH} = "packaging/bin:$path";
277 $_ = `git tag -s -m 'Version $version.' v$version 2>&1`;
278 $ENV{PATH} = $path;
279 unlink($passfile);
280 print $_;
281 next if /bad passphrase/;
282 last unless /failed/;
283 exit 1;
284}
6d12a859 285
e63d3a29 286# Extract the generated files from the old tar.
4bb319c6
WD
287@_ = @extra_files;
288map { s#^#rsync-$lastversion/# } @_;
289system "tar xzf $lasttar_file @_";
290rename("rsync-$lastversion", 'a');
291
5fa38cd6 292print "Creating $diff_file ...\n";
4da9fcd4 293system "./config.status Makefile; make gen; rsync -a @extra_files b/";
ee8a733d 294my $sed_script = 's:^((---|\+\+\+) [ab]/[^\t]+)\t.*:\1:';
62ca3826 295system "(git diff v$lastversion v$version; diff -upN a b | sed -r '$sed_script') | gzip -9 >$diff_file";
9217ce30
WD
296system "rm -rf a";
297rename('b', "rsync-$version");
298
299print "Creating $srctar_file ...\n";
300system "git archive --format=tar --prefix=rsync-$version/ v$version | tar xf -";
301system "support/git-set-file-times --prefix=rsync-$version/";
302system "fakeroot tar czf $srctar_file rsync-$version; rm -rf rsync-$version";
805d8ac4 303
798a9e4e 304print "Updating files in \"rsync-$version/patches\" dir ...\n";
4da9fcd4
WD
305mkdir("rsync-$version", 0755);
306mkdir("rsync-$version/patches", 0755);
f2b7b64d 307system "support/patch-update --skip-check --gen=rsync-$version/patches";
798a9e4e
WD
308
309print "Creating $pattar_file ...\n";
4da9fcd4 310system "fakeroot tar chzf $pattar_file rsync-$version/patches; rm -rf rsync-$version";
6d12a859 311
5fa38cd6 312print "Updating the other files in $dest ...\n";
805d8ac4 313system "rsync -a README NEWS OLDNEWS TODO $dest";
e63d3a29
WD
314unlink($news_file);
315link("$dest/NEWS", $news_file);
eaa28e65 316system "git log --name-status | gzip -9 >$dest/ChangeLog.gz";
6d12a859 317
805d8ac4
WD
318system "yodl2html -o $dest/rsync.html rsync.yo";
319system "yodl2html -o $dest/rsyncd.conf.html rsyncd.conf.yo";
6d12a859 320
e63d3a29 321foreach my $fn ($srctar_file, $pattar_file, $diff_file) {
798a9e4e
WD
322 unlink("$fn.asc");
323 open(GPG, '|-', "gpg --batch --passphrase-fd=0 -ba $fn") or die $!;
324 print GPG $passphrase, "\n";
325 close GPG;
e0fe5231 326}
e63d3a29 327
99ba99c7 328if (!$pre) {
e63d3a29
WD
329 system "rm $dest/rsync-*{.tar.gz,.asc,-NEWS} $dest/src-preview/rsync-*diffs.gz";
330
331 foreach my $fn ($srctar_file, "$srctar_file.asc",
332 $pattar_file, "$pattar_file.asc",
333 $diff_file, "$diff_file.asc", $news_file) {
334 (my $top_fn = $fn) =~ s#/src(-\w+)?/#/#;
335 link($fn, $top_fn);
336 }
337}
338
e0fe5231 339print $break, <<'EOT';
6d12a859 340
e0fe5231
WD
341Local changes are done. When you're satisfied, push the git repository
342and rsync the release files. Remember to announce the release on *BOTH*
343rsync-announce@lists.samba.org and rsync@lists.samba.org (and the web)!
6d12a859 344EOT