| 1 | #!/usr/bin/perl -w |
| 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 | my($cur_branch) = $status =~ /^# On branch (.+)\n/; |
| 68 | if ($cur_branch ne $master_branch) { |
| 69 | print "The checkout is not on the $master_branch branch.\n"; |
| 70 | exit 1 if $master_branch ne 'master'; |
| 71 | print "Do you want to release branch $cur_branch? [n] "; |
| 72 | $_ = <STDIN>; |
| 73 | exit 1 unless /^y/i; |
| 74 | $master_branch = $cur_branch; |
| 75 | } |
| 76 | |
| 77 | my $confversion; |
| 78 | open(IN, '<', 'configure.in') or die $!; |
| 79 | while (<IN>) { |
| 80 | if (/^RSYNC_VERSION=(.*)/) { |
| 81 | $confversion = $1; |
| 82 | last; |
| 83 | } |
| 84 | } |
| 85 | close IN; |
| 86 | die "Unable to find RSYNC_VERSION in configure.in\n" unless defined $confversion; |
| 87 | |
| 88 | open(IN, '<', 'OLDNEWS') or die $!; |
| 89 | $_ = <IN>; |
| 90 | my($lastversion) = /(\d+\.\d+\.\d+)/; |
| 91 | my($last_protocol_version, %pdate); |
| 92 | while (<IN>) { |
| 93 | 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+)$/) { |
| 94 | $pdate{$ver} = $pdate if defined $pdate; |
| 95 | $last_protocol_version = $pver if $ver eq $lastversion; |
| 96 | } |
| 97 | } |
| 98 | close IN; |
| 99 | die "Unable to determine protocol_version for $lastversion.\n" unless defined $last_protocol_version; |
| 100 | |
| 101 | my $protocol_version; |
| 102 | open(IN, '<', 'rsync.h') or die $!; |
| 103 | while (<IN>) { |
| 104 | if (/^#define\s+PROTOCOL_VERSION\s+(\d+)/) { |
| 105 | $protocol_version = $1; |
| 106 | last; |
| 107 | } |
| 108 | } |
| 109 | close IN; |
| 110 | die "Unable to determine the current PROTOCOL_VERSION.\n" unless defined $protocol_version; |
| 111 | |
| 112 | my $version = $confversion; |
| 113 | $version =~ s/dev/pre1/ || $version =~ s/pre(\d+)/ 'pre' . ($1 + 1) /e; |
| 114 | |
| 115 | print "Please enter the version number of this release: [$version] "; |
| 116 | chomp($_ = <STDIN>); |
| 117 | if ($_ eq '.') { |
| 118 | $version =~ s/pre\d+//; |
| 119 | } elsif ($_ ne '') { |
| 120 | $version = $_; |
| 121 | } |
| 122 | die "Invalid version: `$version'\n" unless $version =~ /^[\d.]+(pre\d+)?$/; |
| 123 | |
| 124 | if (`git tag -l v$version` ne '') { |
| 125 | print "Tag v$version already exists.\n\nDelete tag or quit? [q/del] "; |
| 126 | $_ = <STDIN>; |
| 127 | exit 1 unless /^del/i; |
| 128 | system "git tag -d v$version"; |
| 129 | } |
| 130 | |
| 131 | if ($version =~ s/[-.]*pre[-.]*/pre/ && $confversion !~ /dev$/) { |
| 132 | $lastversion = $confversion; |
| 133 | } |
| 134 | |
| 135 | print "Enter the previous version to produce a patch against: [$lastversion] "; |
| 136 | chomp($_ = <STDIN>); |
| 137 | $lastversion = $_ if $_ ne ''; |
| 138 | $lastversion =~ s/[-.]*pre[-.]*/pre/; |
| 139 | |
| 140 | my $pre = $version =~ /(pre\d+)/ ? $1 : ''; |
| 141 | |
| 142 | my $release = $pre ? '0.1' : '1'; |
| 143 | print "Please enter the RPM release number of this release: [$release] "; |
| 144 | chomp($_ = <STDIN>); |
| 145 | $release = $_ if $_ ne ''; |
| 146 | $release .= ".$pre" if $pre; |
| 147 | |
| 148 | (my $finalversion = $version) =~ s/pre\d+//; |
| 149 | my($proto_changed,$proto_change_date); |
| 150 | if ($protocol_version eq $last_protocol_version) { |
| 151 | $proto_changed = 'unchanged'; |
| 152 | $proto_change_date = "\t\t"; |
| 153 | } else { |
| 154 | $proto_changed = 'changed'; |
| 155 | if (!defined($proto_change_date = $pdate{$finalversion})) { |
| 156 | while (1) { |
| 157 | print "On what date did the protocol change to $protocol_version get checked in? (dd Mmm yyyy) "; |
| 158 | chomp($_ = <STDIN>); |
| 159 | last if /^\d\d \w\w\w \d\d\d\d$/; |
| 160 | } |
| 161 | $proto_change_date = "$_\t"; |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | my($srcdir,$srcdiffdir,$lastsrcdir,$skipping); |
| 166 | if ($lastversion =~ /pre/) { |
| 167 | if (!$pre) { |
| 168 | die "You should not diff a release version against a pre-release version.\n"; |
| 169 | } |
| 170 | $srcdir = $srcdiffdir = $lastsrcdir = 'src-previews'; |
| 171 | $skipping = ' ** SKIPPING **'; |
| 172 | } elsif ($pre) { |
| 173 | $srcdir = $srcdiffdir = 'src-previews'; |
| 174 | $lastsrcdir = 'src'; |
| 175 | $skipping = ' ** SKIPPING **'; |
| 176 | } else { |
| 177 | $srcdir = $lastsrcdir = 'src'; |
| 178 | $srcdiffdir = 'src-diffs'; |
| 179 | $skipping = ''; |
| 180 | } |
| 181 | |
| 182 | print "\n", $break, <<EOT; |
| 183 | \$version is "$version" |
| 184 | \$lastversion is "$lastversion" |
| 185 | \$dest is "$dest" |
| 186 | \$curdir is "$curdir" |
| 187 | \$srcdir is "$srcdir" |
| 188 | \$srcdiffdir is "$srcdiffdir" |
| 189 | \$lastsrcdir is "$lastsrcdir" |
| 190 | \$release is "$release" |
| 191 | |
| 192 | About to: |
| 193 | - tweak SUBPROTOCOL_VERSION in rsync.h, if needed |
| 194 | - tweak the version in configure.in and the spec files |
| 195 | - tweak NEWS and OLDNEWS to ensure header values are correct |
| 196 | - tweak the date in the *.yo files and generate the manpages |
| 197 | - generate configure.sh, config.h.in, and proto.h |
| 198 | - page through the differences |
| 199 | |
| 200 | EOT |
| 201 | print "<Press Enter to continue> "; |
| 202 | $_ = <STDIN>; |
| 203 | |
| 204 | my %specvars = ( 'Version:' => $finalversion, 'Release:' => $release, |
| 205 | '%define fullversion' => "\%{version}$pre", 'Released' => "$version.", |
| 206 | '%define srcdir' => $srcdir ); |
| 207 | my @tweak_files = ( glob('packaging/*.spec'), glob('packaging/*/*.spec'), glob('*.yo'), |
| 208 | qw( configure.in rsync.h NEWS OLDNEWS options.c ) ); |
| 209 | |
| 210 | foreach my $fn (@tweak_files) { |
| 211 | open(IN, '<', $fn) or die $!; |
| 212 | undef $/; $_ = <IN>; $/ = "\n"; |
| 213 | close IN; |
| 214 | if ($fn =~ /configure/) { |
| 215 | s/^RSYNC_VERSION=.*/RSYNC_VERSION=$version/m |
| 216 | or die "Unable to update RSYNC_VERSION in $fn\n"; |
| 217 | } elsif ($fn =~ /\.spec/) { |
| 218 | while (my($str, $val) = each %specvars) { |
| 219 | s/^\Q$str\E .*/$str $val/m |
| 220 | or die "Unable to update $str in $fn\n"; |
| 221 | } |
| 222 | s/^\* \w\w\w \w\w\w \d\d \d\d\d\d (.*)/$cl_today $1/m |
| 223 | or die "Unable to update ChangeLog header in $fn\n"; |
| 224 | } elsif ($fn =~ /\.yo/) { |
| 225 | s/^(manpage\([^)]+\)\(\d+\)\()[^)]+(\).*)/$1$today$2/m |
| 226 | or die "Unable to update date in manpage() header in $fn\n"; |
| 227 | s/^(This man ?page is current for version) \S+ (of rsync)/$1 $version $2/m |
| 228 | or die "Unable to update current version info in $fn\n"; |
| 229 | } elsif ($fn eq 'rsync.h') { |
| 230 | s{(#define\s+SUBPROTOCOL_VERSION)\s+(\d+)} |
| 231 | { $1 . ' ' . get_subprotocol_version($2) }e |
| 232 | or die "Unable to find SUBPROTOCOL_VERSION define in $fn\n"; |
| 233 | } elsif ($fn eq 'NEWS') { |
| 234 | s{^(NEWS for rsync \Q$finalversion\E )(\(UNRELEASED\))\s*(\nProtocol: )(\d+) (\([^)]+\))\n} |
| 235 | { $1 . ($pre ? $2 : "($today)") . "$3$protocol_version ($proto_changed)\n" }ei |
| 236 | or die "The first 2 lines of $fn are not in the right format. They must be:\n" |
| 237 | . "NEWS for rsync $finalversion (UNRELEASED)\n" |
| 238 | . "Protocol: $protocol_version ($proto_changed)\n"; |
| 239 | } elsif ($fn eq 'OLDNEWS') { |
| 240 | s{^(\t\S\S\s\S\S\S\s\d\d\d\d)(\t\Q$finalversion\E\t).*} |
| 241 | { ($pre ? $1 : "\t$ztoday") . $2 . $proto_change_date . $protocol_version }em |
| 242 | or die "Unable to find \"?? ??? $year\t$finalversion\" line in $fn\n"; |
| 243 | } elsif ($fn eq 'options.c') { |
| 244 | if (s/(Copyright \(C\) 2002-)(\d+)( Wayne Davison)/$1$year$3/ |
| 245 | && $2 ne $year) { |
| 246 | die "Copyright comments need to be updated to $year in all files!\n"; |
| 247 | } |
| 248 | # Adjust the year in the --version output. |
| 249 | s/(rprintf\(f, "Copyright \(C\) 1996-)(\d+)/$1$year/ |
| 250 | or die "Unable to find Copyright string in --version output of $fn\n"; |
| 251 | next if $2 eq $year; |
| 252 | } else { |
| 253 | die "Unrecognized file in \@tweak_files: $fn\n"; |
| 254 | } |
| 255 | open(OUT, '>', $fn) or die $!; |
| 256 | print OUT $_; |
| 257 | close OUT; |
| 258 | } |
| 259 | |
| 260 | print $break; |
| 261 | system "git diff --color | less -p '^diff .*'"; |
| 262 | |
| 263 | my $srctar_name = "rsync-$version.tar.gz"; |
| 264 | my $pattar_name = "rsync-patches-$version.tar.gz"; |
| 265 | my $diff_name = "rsync-$lastversion-$version.diffs.gz"; |
| 266 | my $srctar_file = "$dest/$srcdir/$srctar_name"; |
| 267 | my $pattar_file = "$dest/$srcdir/$pattar_name"; |
| 268 | my $diff_file = "$dest/$srcdiffdir/$diff_name"; |
| 269 | my $news_file = "$dest/$srcdir/rsync-$version-NEWS"; |
| 270 | my $lasttar_file = "$dest/$lastsrcdir/rsync-$lastversion.tar.gz"; |
| 271 | |
| 272 | print $break, <<EOT; |
| 273 | |
| 274 | About to: |
| 275 | - commit all version changes |
| 276 | - merge the $master_branch branch into the patch/* branches |
| 277 | - update the files in the "patches" dir and OPTIONALLY |
| 278 | (if you type 'y') to launch a shell for each patch |
| 279 | |
| 280 | EOT |
| 281 | print "<Press Enter OR 'y' to continue> "; |
| 282 | my $ans = <STDIN>; |
| 283 | |
| 284 | system "git commit -a -m 'Preparing for release of $version'" and exit 1; |
| 285 | |
| 286 | print "Updating files in \"patches\" dir ...\n"; |
| 287 | system "packaging/patch-update --branch=$master_branch"; |
| 288 | |
| 289 | if ($ans =~ /^y/i) { |
| 290 | print "\nVisiting all \"patch/*\" branches ...\n"; |
| 291 | system "packaging/patch-update --branch=$master_branch --shell"; |
| 292 | } |
| 293 | |
| 294 | print $break, <<EOT; |
| 295 | |
| 296 | About to: |
| 297 | - create signed tag for this release: v$version |
| 298 | - create release diffs, "$diff_name" |
| 299 | - create release tar, "$srctar_name" |
| 300 | - generate rsync-$version/patches/* files |
| 301 | - create patches tar, "$pattar_name" |
| 302 | - update top-level README, *NEWS, TODO, and ChangeLog |
| 303 | - update top-level rsync*.html manpages |
| 304 | - gpg-sign the release files |
| 305 | - update hard-linked top-level release files$skipping |
| 306 | |
| 307 | EOT |
| 308 | print "<Press Enter to continue> "; |
| 309 | $_ = <STDIN>; |
| 310 | |
| 311 | my $passphrase; |
| 312 | while (1) { |
| 313 | ReadMode('noecho'); |
| 314 | print "\nEnter your GPG pass-phrase: "; |
| 315 | chomp($passphrase = <STDIN>); |
| 316 | ReadMode(0); |
| 317 | print "\n"; |
| 318 | |
| 319 | # Briefly create a temp file with the passphrase for git's tagging use. |
| 320 | my $oldmask = umask 077; |
| 321 | unlink($passfile); |
| 322 | open(OUT, '>', $passfile) or die $!; |
| 323 | print OUT $passphrase, "\n"; |
| 324 | close OUT; |
| 325 | umask $oldmask; |
| 326 | $ENV{'GPG_PASSFILE'} = $passfile; |
| 327 | |
| 328 | # We want to use our passphrase-providing "gpg" script, so modify the PATH. |
| 329 | $ENV{PATH} = "packaging/bin:$path"; |
| 330 | $_ = `git tag -s -m 'Version $version.' v$version 2>&1`; |
| 331 | $ENV{PATH} = $path; |
| 332 | unlink($passfile); |
| 333 | print $_; |
| 334 | next if /bad passphrase/; |
| 335 | last unless /failed/; |
| 336 | exit 1; |
| 337 | } |
| 338 | |
| 339 | # Extract the generated files from the old tar. |
| 340 | @_ = @extra_files; |
| 341 | map { s#^#rsync-$lastversion/# } @_; |
| 342 | system "tar xzf $lasttar_file @_"; |
| 343 | rename("rsync-$lastversion", 'a'); |
| 344 | |
| 345 | print "Creating $diff_file ...\n"; |
| 346 | system "./config.status Makefile; make gen; rsync -a @extra_files b/"; |
| 347 | my $sed_script = 's:^((---|\+\+\+) [ab]/[^\t]+)\t.*:\1:'; |
| 348 | system "(git diff v$lastversion v$version; diff -upN a b | sed -r '$sed_script') | gzip -9 >$diff_file"; |
| 349 | system "rm -rf a"; |
| 350 | rename('b', "rsync-$version"); |
| 351 | |
| 352 | print "Creating $srctar_file ...\n"; |
| 353 | system "git archive --format=tar --prefix=rsync-$version/ v$version | tar xf -"; |
| 354 | system "support/git-set-file-times --prefix=rsync-$version/"; |
| 355 | system "fakeroot tar czf $srctar_file rsync-$version; rm -rf rsync-$version"; |
| 356 | |
| 357 | print "Updating files in \"rsync-$version/patches\" dir ...\n"; |
| 358 | mkdir("rsync-$version", 0755); |
| 359 | mkdir("rsync-$version/patches", 0755); |
| 360 | system "packaging/patch-update --skip-check --branch=$master_branch --gen=rsync-$version/patches"; |
| 361 | |
| 362 | print "Creating $pattar_file ...\n"; |
| 363 | system "fakeroot tar chzf $pattar_file rsync-$version/patches; rm -rf rsync-$version"; |
| 364 | |
| 365 | print "Updating the other files in $dest ...\n"; |
| 366 | system "rsync -a README NEWS OLDNEWS TODO $dest"; |
| 367 | unlink($news_file); |
| 368 | link("$dest/NEWS", $news_file); |
| 369 | system "git log --name-status | gzip -9 >$dest/ChangeLog.gz"; |
| 370 | |
| 371 | system "yodl2html -o $dest/rsync.html rsync.yo"; |
| 372 | system "yodl2html -o $dest/rsyncd.conf.html rsyncd.conf.yo"; |
| 373 | |
| 374 | foreach my $fn ($srctar_file, $pattar_file, $diff_file) { |
| 375 | unlink("$fn.asc"); |
| 376 | open(GPG, '|-', "gpg --batch --passphrase-fd=0 -ba $fn") or die $!; |
| 377 | print GPG $passphrase, "\n"; |
| 378 | close GPG; |
| 379 | } |
| 380 | |
| 381 | if (!$pre) { |
| 382 | system "rm $dest/rsync-*.gz $dest/rsync-*.asc $dest/rsync-*-NEWS $dest/src-previews/rsync-*diffs.gz*"; |
| 383 | |
| 384 | foreach my $fn ($srctar_file, "$srctar_file.asc", |
| 385 | $pattar_file, "$pattar_file.asc", |
| 386 | $diff_file, "$diff_file.asc", $news_file) { |
| 387 | (my $top_fn = $fn) =~ s#/src(-\w+)?/#/#; |
| 388 | link($fn, $top_fn); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | print $break, <<'EOT'; |
| 393 | |
| 394 | Local changes are done. When you're satisfied, push the git repository |
| 395 | and rsync the release files. Remember to announce the release on *BOTH* |
| 396 | rsync-announce@lists.samba.org and rsync@lists.samba.org (and the web)! |
| 397 | EOT |
| 398 | |
| 399 | exit; |
| 400 | |
| 401 | sub get_subprotocol_version |
| 402 | { |
| 403 | my($subver) = @_; |
| 404 | if ($pre && $proto_changed eq 'changed') { |
| 405 | return $subver == 0 ? 1 : $subver; |
| 406 | } |
| 407 | 0; |
| 408 | } |
| 409 | |
| 410 | sub usage |
| 411 | { |
| 412 | die <<EOT; |
| 413 | Usage: release-rsync [OPTIONS] |
| 414 | |
| 415 | -b, --branch=BRANCH The branch to release (default: master) |
| 416 | -h, --help Display this help message |
| 417 | EOT |
| 418 | } |