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