2 # This script expects the directory ~/samba-rsync-ftp to exist and to be a
3 # copy of the /home/ftp/pub/rsync dir on samba.org. When the script is done,
4 # the git repository in the current directory will be updated, and the local
5 # ~/samba-rsync-ftp dir will be ready to be rsynced to samba.org.
14 my $dest = $ENV{HOME} . '/samba-rsync-ftp';
15 my $passfile = $ENV{HOME} . '/.rsyncpass';
16 my $path = $ENV{PATH};
17 my $make_gen_cmd = 'make -f prepare-source.mak conf && ./config.status && make gen';
19 &Getopt::Long::Configure('bundling');
20 &usage if !&GetOptions(
21 'branch|b=s' => \( my $master_branch = 'master' ),
22 'help|h' => \( my $help_opt ),
27 my $cl_today = time2str('* %a %b %d %Y', $now);
28 my $year = time2str('%Y', $now);
29 my $ztoday = time2str('%d %b %Y', $now);
30 (my $today = $ztoday) =~ s/^0//;
32 my $curdir = Cwd::cwd;
39 open(IN, '<', 'Makefile.in') or die "Couldn't open Makefile.in: $!\n";
45 @extra_files = split(' ', $_);
52 ==========================================================================
55 print $break, <<EOT, $break, "\n";
56 == This will release a new version of rsync onto an unsuspecting world. ==
59 die "$dest does not exist\n" unless -d $dest;
60 die "There is no .git dir in the current directory.\n" unless -d '.git';
61 die "'a' must not exist in the current directory.\n" if -e 'a';
62 die "'b' must not exist in the current directory.\n" if -e 'b';
64 my $status = `git status`;
65 die "The checkout is not clean:\n", $status unless $status =~ /\nnothing to commit \(working directory clean\)/;
66 my($cur_branch) = $status =~ /^# On branch (.+)\n/;
67 if ($cur_branch ne $master_branch) {
68 print "The checkout is not on the $master_branch branch.\n";
69 exit 1 if $master_branch ne 'master';
70 print "Do you want to release branch $cur_branch? [n] ";
73 $master_branch = $cur_branch;
76 if (-d 'patches/.git') {
77 $status = `cd patches && git status`;
78 die "The *patches* checkout is not clean:\n", $status unless $status =~ /\nnothing to commit \(working directory clean\)/;
79 ($cur_branch) = $status =~ /^# On branch (.+)\n/;
80 if ($cur_branch ne $master_branch) {
81 print "The *patches* checkout is on branch $cur_branch, not branch $master_branch.\n";
82 print "Do you want to change it to branch $master_branch? [n] ";
85 system "cd patches && git checkout '$master_branch'";
90 open(IN, '<', 'configure.in') or die $!;
92 if (/^RSYNC_VERSION=(.*)/) {
98 die "Unable to find RSYNC_VERSION in configure.in\n" unless defined $confversion;
100 open(IN, '<', 'OLDNEWS') or die $!;
102 my($lastversion) = /(\d+\.\d+\.\d+)/;
103 my($last_protocol_version, %pdate);
105 if (my($ver,$pdate,$pver) = /^\s+\S\S\s\S\S\S\s\d\d\d\d\s+(\d+\.\d+\.\d+)\s+(\d\d \w\w\w \d\d\d\d\s+)?(\d+)$/) {
106 $pdate{$ver} = $pdate if defined $pdate;
107 $last_protocol_version = $pver if $ver eq $lastversion;
111 die "Unable to determine protocol_version for $lastversion.\n" unless defined $last_protocol_version;
113 my $protocol_version;
114 open(IN, '<', 'rsync.h') or die $!;
116 if (/^#define\s+PROTOCOL_VERSION\s+(\d+)/) {
117 $protocol_version = $1;
122 die "Unable to determine the current PROTOCOL_VERSION.\n" unless defined $protocol_version;
124 my $version = $confversion;
125 $version =~ s/dev/pre1/ || $version =~ s/pre(\d+)/ 'pre' . ($1 + 1) /e;
127 print "Please enter the version number of this release: [$version] ";
130 $version =~ s/pre\d+//;
134 die "Invalid version: `$version'\n" unless $version =~ /^[\d.]+(pre\d+)?$/;
136 if (`git tag -l v$version` ne '') {
137 print "Tag v$version already exists.\n\nDelete tag or quit? [q/del] ";
139 exit 1 unless /^del/i;
140 system "git tag -d v$version";
143 if ($version =~ s/[-.]*pre[-.]*/pre/ && $confversion !~ /dev$/) {
144 $lastversion = $confversion;
147 print "Enter the previous version to produce a patch against: [$lastversion] ";
149 $lastversion = $_ if $_ ne '';
150 $lastversion =~ s/[-.]*pre[-.]*/pre/;
152 my $pre = $version =~ /(pre\d+)/ ? $1 : '';
154 my $release = $pre ? '0.1' : '1';
155 print "Please enter the RPM release number of this release: [$release] ";
157 $release = $_ if $_ ne '';
158 $release .= ".$pre" if $pre;
160 (my $finalversion = $version) =~ s/pre\d+//;
161 my($proto_changed,$proto_change_date);
162 if ($protocol_version eq $last_protocol_version) {
163 $proto_changed = 'unchanged';
164 $proto_change_date = "\t\t";
166 $proto_changed = 'changed';
167 if (!defined($proto_change_date = $pdate{$finalversion})) {
169 print "On what date did the protocol change to $protocol_version get checked in? (dd Mmm yyyy) ";
171 last if /^\d\d \w\w\w \d\d\d\d$/;
173 $proto_change_date = "$_\t";
177 my($srcdir,$srcdiffdir,$lastsrcdir,$skipping);
178 if ($lastversion =~ /pre/) {
180 die "You should not diff a release version against a pre-release version.\n";
182 $srcdir = $srcdiffdir = $lastsrcdir = 'src-previews';
183 $skipping = ' ** SKIPPING **';
185 $srcdir = $srcdiffdir = 'src-previews';
187 $skipping = ' ** SKIPPING **';
189 $srcdir = $lastsrcdir = 'src';
190 $srcdiffdir = 'src-diffs';
194 print "\n", $break, <<EOT;
195 \$version is "$version"
196 \$lastversion is "$lastversion"
198 \$curdir is "$curdir"
199 \$srcdir is "$srcdir"
200 \$srcdiffdir is "$srcdiffdir"
201 \$lastsrcdir is "$lastsrcdir"
202 \$release is "$release"
205 - tweak SUBPROTOCOL_VERSION in rsync.h, if needed
206 - tweak the version in configure.in and the spec files
207 - tweak NEWS and OLDNEWS to ensure header values are correct
208 - tweak the date in the *.yo files and generate the manpages
209 - generate configure.sh, config.h.in, and proto.h
210 - page through the differences
213 print "<Press Enter to continue> ";
216 my %specvars = ( 'Version:' => $finalversion, 'Release:' => $release,
217 '%define fullversion' => "\%{version}$pre", 'Released' => "$version.",
218 '%define srcdir' => $srcdir );
219 my @tweak_files = ( glob('packaging/*.spec'), glob('packaging/*/*.spec'), glob('*.yo'),
220 qw( configure.in rsync.h NEWS OLDNEWS options.c ) );
222 foreach my $fn (@tweak_files) {
223 open(IN, '<', $fn) or die $!;
224 undef $/; $_ = <IN>; $/ = "\n";
226 if ($fn =~ /configure/) {
227 s/^RSYNC_VERSION=.*/RSYNC_VERSION=$version/m
228 or die "Unable to update RSYNC_VERSION in $fn\n";
229 } elsif ($fn =~ /\.spec/) {
230 while (my($str, $val) = each %specvars) {
231 s/^\Q$str\E .*/$str $val/m
232 or die "Unable to update $str in $fn\n";
234 s/^\* \w\w\w \w\w\w \d\d \d\d\d\d (.*)/$cl_today $1/m
235 or die "Unable to update ChangeLog header in $fn\n";
236 } elsif ($fn =~ /\.yo/) {
237 s/^(manpage\([^)]+\)\(\d+\)\()[^)]+(\).*)/$1$today$2/m
238 or die "Unable to update date in manpage() header in $fn\n";
239 s/^(This man ?page is current for version) \S+ (of rsync)/$1 $version $2/m
240 or die "Unable to update current version info in $fn\n";
241 } elsif ($fn eq 'rsync.h') {
242 s{(#define\s+SUBPROTOCOL_VERSION)\s+(\d+)}
243 { $1 . ' ' . get_subprotocol_version($2) }e
244 or die "Unable to find SUBPROTOCOL_VERSION define in $fn\n";
245 } elsif ($fn eq 'NEWS') {
246 s{^(NEWS for rsync \Q$finalversion\E )(\(UNRELEASED\))\s*(\nProtocol: )(\d+) (\([^)]+\))\n}
247 { $1 . ($pre ? $2 : "($today)") . "$3$protocol_version ($proto_changed)\n" }ei
248 or die "The first 2 lines of $fn are not in the right format. They must be:\n"
249 . "NEWS for rsync $finalversion (UNRELEASED)\n"
250 . "Protocol: $protocol_version ($proto_changed)\n";
251 } elsif ($fn eq 'OLDNEWS') {
252 s{^(\t\S\S\s\S\S\S\s\d\d\d\d)(\t\Q$finalversion\E\t).*}
253 { ($pre ? $1 : "\t$ztoday") . $2 . $proto_change_date . $protocol_version }em
254 or die "Unable to find \"?? ??? $year\t$finalversion\" line in $fn\n";
255 } elsif ($fn eq 'options.c') {
256 if (s/(Copyright \(C\) 2002-)(\d+)( Wayne Davison)/$1$year$3/
258 die "Copyright comments need to be updated to $year in all files!\n";
260 # Adjust the year in the --version output.
261 s/(rprintf\(f, "Copyright \(C\) 1996-)(\d+)/$1$year/
262 or die "Unable to find Copyright string in --version output of $fn\n";
265 die "Unrecognized file in \@tweak_files: $fn\n";
267 open(OUT, '>', $fn) or die $!;
273 system "git diff --color | less -p '^diff .*'";
275 my $srctar_name = "rsync-$version.tar.gz";
276 my $pattar_name = "rsync-patches-$version.tar.gz";
277 my $diff_name = "rsync-$lastversion-$version.diffs.gz";
278 my $srctar_file = "$dest/$srcdir/$srctar_name";
279 my $pattar_file = "$dest/$srcdir/$pattar_name";
280 my $diff_file = "$dest/$srcdiffdir/$diff_name";
281 my $news_file = "$dest/$srcdir/rsync-$version-NEWS";
282 my $lasttar_file = "$dest/$lastsrcdir/rsync-$lastversion.tar.gz";
287 - commit all version changes
288 - merge the $master_branch branch into the patch/* branches
289 - update the files in the "patches" dir and OPTIONALLY
290 (if you type 'y') to launch a shell for each patch
293 print "<Press Enter OR 'y' to continue> ";
296 system "git commit -a -m 'Preparing for release of $version'" and exit 1;
298 print "Updating files in \"patches\" dir ...\n";
299 system "packaging/patch-update --branch=$master_branch";
302 print "\nVisiting all \"patch/*\" branches ...\n";
303 system "packaging/patch-update --branch=$master_branch --shell";
306 if (-d 'patches/.git') {
307 system "cd patches && git commit -a -m 'The patches for $version.'" and exit 1;
313 - create signed tag for this release: v$version
314 - create release diffs, "$diff_name"
315 - create release tar, "$srctar_name"
316 - generate rsync-$version/patches/* files
317 - create patches tar, "$pattar_name"
318 - update top-level README, *NEWS, TODO, and ChangeLog
319 - update top-level rsync*.html manpages
320 - gpg-sign the release files
321 - update hard-linked top-level release files$skipping
324 print "<Press Enter to continue> ";
327 # We want to use our passphrase-providing "gpg" script, so modify the PATH.
328 $ENV{PATH} = "$curdir/packaging/bin:$path";
333 print "\nEnter your GPG pass-phrase: ";
334 chomp($passphrase = <STDIN>);
338 # Briefly create a temp file with the passphrase for git's tagging use.
339 my $oldmask = umask 077;
341 open(OUT, '>', $passfile) or die $!;
342 print OUT $passphrase, "\n";
345 $ENV{'GPG_PASSFILE'} = $passfile;
347 $_ = `git tag -s -m 'Version $version.' v$version 2>&1`;
349 next if /bad passphrase/;
352 if (-d 'patches/.git') {
353 $_ = `cd patches && git tag -s -m 'Version $version.' v$version 2>&1`;
355 exit 1 if /bad passphrase|failed/;
364 # Extract the generated files from the old tar.
366 map { s#^#rsync-$lastversion/# } @_;
367 system "tar xzf $lasttar_file @_";
368 rename("rsync-$lastversion", 'a');
370 print "Creating $diff_file ...\n";
371 system "$make_gen_cmd && rsync -a @extra_files b/" and exit 1;
372 my $sed_script = 's:^((---|\+\+\+) [ab]/[^\t]+)\t.*:\1:';
373 system "(git diff v$lastversion v$version; diff -upN a b | sed -r '$sed_script') | gzip -9 >$diff_file";
375 rename('b', "rsync-$version");
377 print "Creating $srctar_file ...\n";
378 system "git archive --format=tar --prefix=rsync-$version/ v$version | tar xf -";
379 system "support/git-set-file-times --prefix=rsync-$version/";
380 system "fakeroot tar czf $srctar_file rsync-$version; rm -rf rsync-$version";
382 print "Updating files in \"rsync-$version/patches\" dir ...\n";
383 mkdir("rsync-$version", 0755);
384 mkdir("rsync-$version/patches", 0755);
385 system "packaging/patch-update --skip-check --branch=$master_branch --gen=rsync-$version/patches";
387 print "Creating $pattar_file ...\n";
388 system "fakeroot tar chzf $pattar_file rsync-$version/patches; rm -rf rsync-$version";
390 print "Updating the other files in $dest ...\n";
391 system "rsync -a README NEWS OLDNEWS TODO $dest";
393 link("$dest/NEWS", $news_file);
394 system "git log --name-status | gzip -9 >$dest/ChangeLog.gz";
396 system "yodl2html -o $dest/rsync.html rsync.yo";
397 system "yodl2html -o $dest/rsyncd.conf.html rsyncd.conf.yo";
399 foreach my $fn ($srctar_file, $pattar_file, $diff_file) {
401 open(GPG, '|-', "gpg --batch --passphrase-fd=0 -ba $fn") or die $!;
402 print GPG $passphrase, "\n";
407 system "rm $dest/rsync-*.gz $dest/rsync-*.asc $dest/rsync-*-NEWS $dest/src-previews/rsync-*diffs.gz*";
409 foreach my $fn ($srctar_file, "$srctar_file.asc",
410 $pattar_file, "$pattar_file.asc",
411 $diff_file, "$diff_file.asc", $news_file) {
412 (my $top_fn = $fn) =~ s#/src(-\w+)?/#/#;
417 print $break, <<'EOT';
419 Local changes are done. When you're satisfied, push the git repository
420 and rsync the release files. Remember to announce the release on *BOTH*
421 rsync-announce@lists.samba.org and rsync@lists.samba.org (and the web)!
426 sub get_subprotocol_version
429 if ($pre && $proto_changed eq 'changed') {
430 return $subver == 0 ? 1 : $subver;
438 Usage: release-rsync [OPTIONS]
440 -b, --branch=BRANCH The branch to release (default: master)
441 -h, --help Display this help message