Commit | Line | Data |
---|---|---|
4f282b0b | 1 | #!/usr/bin/perl -w |
6d12a859 WD |
2 | use 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 | 9 | use Cwd; |
56fc9f70 | 10 | use Getopt::Long; |
798a9e4e | 11 | use Term::ReadKey; |
6d12a859 WD |
12 | use Date::Format; |
13 | ||
14 | my $dest = $ENV{HOME} . '/samba-rsync-ftp'; | |
798a9e4e WD |
15 | my $passfile = $ENV{HOME} . '/.rsyncpass'; |
16 | my $path = $ENV{PATH}; | |
6d12a859 | 17 | |
56fc9f70 WD |
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 | ||
fede3785 WD |
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); | |
90ac152d | 29 | (my $today = $ztoday) =~ s/^0//; |
6d12a859 | 30 | |
805d8ac4 WD |
31 | my $curdir = Cwd::cwd; |
32 | ||
798a9e4e WD |
33 | END { |
34 | unlink($passfile); | |
35 | } | |
36 | ||
67b9b26f WD |
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 | } | |
805d8ac4 WD |
48 | close IN; |
49 | ||
5fa38cd6 WD |
50 | my $break = <<EOT; |
51 | ========================================================================== | |
6d12a859 | 52 | EOT |
6d12a859 | 53 | |
805d8ac4 | 54 | print $break, <<EOT, $break, "\n"; |
5fa38cd6 WD |
55 | == This will release a new version of rsync onto an unsuspecting world. == |
56 | EOT | |
519c8de1 | 57 | |
805d8ac4 WD |
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'; | |
519c8de1 | 62 | |
6a2456c5 | 63 | open(IN, '-|', 'git status') or die $!; |
805d8ac4 WD |
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\)/; | |
4f282b0b WD |
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 | } | |
519c8de1 | 76 | |
fede3785 | 77 | my $confversion; |
578219be | 78 | open(IN, '<', 'configure.in') or die $!; |
519c8de1 WD |
79 | while (<IN>) { |
80 | if (/^RSYNC_VERSION=(.*)/) { | |
fede3785 | 81 | $confversion = $1; |
519c8de1 WD |
82 | last; |
83 | } | |
84 | } | |
85 | close IN; | |
fede3785 | 86 | die "Unable to find RSYNC_VERSION in configure.in\n" unless defined $confversion; |
2e4a3d17 | 87 | |
62ca3826 WD |
88 | open(IN, '<', 'OLDNEWS') or die $!; |
89 | $_ = <IN>; | |
fede3785 | 90 | my($lastversion) = /(\d+\.\d+\.\d+)/; |
4f282b0b WD |
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; | |
62ca3826 | 111 | |
fede3785 | 112 | my $version = $confversion; |
805d8ac4 | 113 | $version =~ s/dev/pre1/ || $version =~ s/pre(\d+)/ 'pre' . ($1 + 1) /e; |
519c8de1 | 114 | |
805d8ac4 | 115 | print "Please enter the version number of this release: [$version] "; |
519c8de1 WD |
116 | chomp($_ = <STDIN>); |
117 | if ($_ eq '.') { | |
118 | $version =~ s/pre\d+//; | |
119 | } elsif ($_ ne '') { | |
120 | $version = $_; | |
121 | } | |
798a9e4e WD |
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 | } | |
fede3785 WD |
130 | |
131 | if ($version =~ s/[-.]*pre[-.]*/pre/ && $confversion !~ /dev$/) { | |
132 | $lastversion = $confversion; | |
133 | } | |
6d12a859 | 134 | |
519c8de1 WD |
135 | print "Enter the previous version to produce a patch against: [$lastversion] "; |
136 | chomp($_ = <STDIN>); | |
137 | $lastversion = $_ if $_ ne ''; | |
6d12a859 WD |
138 | $lastversion =~ s/[-.]*pre[-.]*/pre/; |
139 | ||
99ba99c7 WD |
140 | my $pre = $version =~ /(pre\d+)/ ? $1 : ''; |
141 | ||
142 | my $release = $pre ? '0.1' : '1'; | |
519c8de1 WD |
143 | print "Please enter the RPM release number of this release: [$release] "; |
144 | chomp($_ = <STDIN>); | |
145 | $release = $_ if $_ ne ''; | |
99ba99c7 | 146 | $release .= ".$pre" if $pre; |
6d12a859 | 147 | |
4f282b0b WD |
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 | ||
e63d3a29 | 165 | my($srcdir,$srcdiffdir,$lastsrcdir,$skipping); |
6d12a859 | 166 | if ($lastversion =~ /pre/) { |
99ba99c7 | 167 | if (!$pre) { |
6d12a859 WD |
168 | die "You should not diff a release version against a pre-release version.\n"; |
169 | } | |
e63d3a29 | 170 | $srcdir = $srcdiffdir = $lastsrcdir = 'src-previews'; |
805d8ac4 | 171 | $skipping = ' ** SKIPPING **'; |
99ba99c7 | 172 | } elsif ($pre) { |
e63d3a29 WD |
173 | $srcdir = $srcdiffdir = 'src-previews'; |
174 | $lastsrcdir = 'src'; | |
805d8ac4 | 175 | $skipping = ' ** SKIPPING **'; |
6d12a859 | 176 | } else { |
e63d3a29 WD |
177 | $srcdir = $lastsrcdir = 'src'; |
178 | $srcdiffdir = 'src-diffs'; | |
805d8ac4 | 179 | $skipping = ''; |
6d12a859 WD |
180 | } |
181 | ||
5fa38cd6 | 182 | print "\n", $break, <<EOT; |
6d12a859 WD |
183 | \$version is "$version" |
184 | \$lastversion is "$lastversion" | |
6d12a859 | 185 | \$dest is "$dest" |
805d8ac4 | 186 | \$curdir is "$curdir" |
e63d3a29 WD |
187 | \$srcdir is "$srcdir" |
188 | \$srcdiffdir is "$srcdiffdir" | |
189 | \$lastsrcdir is "$lastsrcdir" | |
6d12a859 WD |
190 | \$release is "$release" |
191 | ||
192 | About to: | |
4f282b0b | 193 | - tweak SUBPROTOCOL_VERSION in rsync.h, if needed |
805d8ac4 | 194 | - tweak the version in configure.in and the spec files |
4f282b0b | 195 | - tweak NEWS and OLDNEWS to ensure header values are correct |
798a9e4e | 196 | - tweak the date in the *.yo files and generate the manpages |
805d8ac4 WD |
197 | - generate configure.sh, config.h.in, and proto.h |
198 | - page through the differences | |
6d12a859 WD |
199 | |
200 | EOT | |
201 | print "<Press Enter to continue> "; | |
202 | $_ = <STDIN>; | |
203 | ||
99ba99c7 | 204 | my %specvars = ( 'Version:' => $finalversion, 'Release:' => $release, |
6fd2c27f WD |
205 | '%define fullversion' => "\%{version}$pre", 'Released' => "$version.", |
206 | '%define srcdir' => $srcdir ); | |
800a4485 WD |
207 | my @tweak_files = ( glob('packaging/*.spec'), glob('packaging/*/*.spec'), glob('*.yo'), |
208 | qw( configure.in rsync.h NEWS OLDNEWS options.c ) ); | |
805d8ac4 | 209 | |
6d12a859 WD |
210 | foreach my $fn (@tweak_files) { |
211 | open(IN, '<', $fn) or die $!; | |
212 | undef $/; $_ = <IN>; $/ = "\n"; | |
213 | close IN; | |
214 | if ($fn =~ /configure/) { | |
800a4485 WD |
215 | s/^RSYNC_VERSION=.*/RSYNC_VERSION=$version/m |
216 | or die "Unable to update RSYNC_VERSION in $fn\n"; | |
6d12a859 | 217 | } elsif ($fn =~ /\.spec/) { |
800a4485 WD |
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"; | |
6d12a859 | 224 | } elsif ($fn =~ /\.yo/) { |
800a4485 WD |
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"; | |
2e4a3d17 | 229 | } elsif ($fn eq 'rsync.h') { |
4f282b0b WD |
230 | s{(#define\s+SUBPROTOCOL_VERSION)\s+(\d+)} |
231 | { $1 . ' ' . get_subprotocol_version($2) }e | |
800a4485 | 232 | or die "Unable to find SUBPROTOCOL_VERSION define in $fn\n"; |
800a4485 | 233 | } elsif ($fn eq 'NEWS') { |
4f282b0b WD |
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"; | |
178a1d20 | 239 | } elsif ($fn eq 'OLDNEWS') { |
4f282b0b WD |
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 | |
800a4485 | 242 | or die "Unable to find \"?? ??? $year\t$finalversion\" line in $fn\n"; |
fede3785 | 243 | } elsif ($fn eq 'options.c') { |
800a4485 WD |
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; | |
6d12a859 | 252 | } else { |
178a1d20 | 253 | die "Unrecognized file in \@tweak_files: $fn\n"; |
6d12a859 WD |
254 | } |
255 | open(OUT, '>', $fn) or die $!; | |
256 | print OUT $_; | |
257 | close OUT; | |
258 | } | |
259 | ||
5fa38cd6 | 260 | print $break; |
6a2456c5 | 261 | system "git diff --color | less -p '^diff .*'"; |
5fa38cd6 | 262 | |
805d8ac4 WD |
263 | my $srctar_name = "rsync-$version.tar.gz"; |
264 | my $pattar_name = "rsync-patches-$version.tar.gz"; | |
e60bba3f | 265 | my $diff_name = "rsync-$lastversion-$version.diffs.gz"; |
e63d3a29 WD |
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"; | |
5fa38cd6 WD |
271 | |
272 | print $break, <<EOT; | |
6d12a859 | 273 | |
805d8ac4 | 274 | About to: |
798a9e4e | 275 | - commit all version changes |
56fc9f70 | 276 | - merge the $master_branch branch into the patch/* branches |
798a9e4e WD |
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"; | |
56fc9f70 | 287 | system "packaging/patch-update --branch=$master_branch"; |
798a9e4e WD |
288 | |
289 | if ($ans =~ /^y/i) { | |
290 | print "\nVisiting all \"patch/*\" branches ...\n"; | |
56fc9f70 | 291 | system "packaging/patch-update --branch=$master_branch --shell"; |
798a9e4e WD |
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" | |
805d8ac4 | 299 | - create release tar, "$srctar_name" |
798a9e4e | 300 | - generate rsync-$version/patches/* files |
805d8ac4 | 301 | - create patches tar, "$pattar_name" |
798a9e4e WD |
302 | - update top-level README, *NEWS, TODO, and ChangeLog |
303 | - update top-level rsync*.html manpages | |
805d8ac4 | 304 | - gpg-sign the release files |
798a9e4e | 305 | - update hard-linked top-level release files$skipping |
6d12a859 WD |
306 | |
307 | EOT | |
308 | print "<Press Enter to continue> "; | |
309 | $_ = <STDIN>; | |
310 | ||
798a9e4e WD |
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 | } | |
6d12a859 | 338 | |
e63d3a29 | 339 | # Extract the generated files from the old tar. |
4bb319c6 WD |
340 | @_ = @extra_files; |
341 | map { s#^#rsync-$lastversion/# } @_; | |
342 | system "tar xzf $lasttar_file @_"; | |
343 | rename("rsync-$lastversion", 'a'); | |
344 | ||
5fa38cd6 | 345 | print "Creating $diff_file ...\n"; |
4da9fcd4 | 346 | system "./config.status Makefile; make gen; rsync -a @extra_files b/"; |
ee8a733d | 347 | my $sed_script = 's:^((---|\+\+\+) [ab]/[^\t]+)\t.*:\1:'; |
62ca3826 | 348 | system "(git diff v$lastversion v$version; diff -upN a b | sed -r '$sed_script') | gzip -9 >$diff_file"; |
9217ce30 WD |
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"; | |
805d8ac4 | 356 | |
798a9e4e | 357 | print "Updating files in \"rsync-$version/patches\" dir ...\n"; |
4da9fcd4 WD |
358 | mkdir("rsync-$version", 0755); |
359 | mkdir("rsync-$version/patches", 0755); | |
56fc9f70 | 360 | system "packaging/patch-update --skip-check --branch=$master_branch --gen=rsync-$version/patches"; |
798a9e4e WD |
361 | |
362 | print "Creating $pattar_file ...\n"; | |
4da9fcd4 | 363 | system "fakeroot tar chzf $pattar_file rsync-$version/patches; rm -rf rsync-$version"; |
6d12a859 | 364 | |
5fa38cd6 | 365 | print "Updating the other files in $dest ...\n"; |
805d8ac4 | 366 | system "rsync -a README NEWS OLDNEWS TODO $dest"; |
e63d3a29 WD |
367 | unlink($news_file); |
368 | link("$dest/NEWS", $news_file); | |
eaa28e65 | 369 | system "git log --name-status | gzip -9 >$dest/ChangeLog.gz"; |
6d12a859 | 370 | |
805d8ac4 WD |
371 | system "yodl2html -o $dest/rsync.html rsync.yo"; |
372 | system "yodl2html -o $dest/rsyncd.conf.html rsyncd.conf.yo"; | |
6d12a859 | 373 | |
e63d3a29 | 374 | foreach my $fn ($srctar_file, $pattar_file, $diff_file) { |
798a9e4e WD |
375 | unlink("$fn.asc"); |
376 | open(GPG, '|-', "gpg --batch --passphrase-fd=0 -ba $fn") or die $!; | |
377 | print GPG $passphrase, "\n"; | |
378 | close GPG; | |
e0fe5231 | 379 | } |
e63d3a29 | 380 | |
99ba99c7 | 381 | if (!$pre) { |
2551c47e | 382 | system "rm $dest/rsync-*.gz $dest/rsync-*.asc $dest/rsync-*-NEWS $dest/src-previews/rsync-*diffs.gz*"; |
e63d3a29 WD |
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 | ||
e0fe5231 | 392 | print $break, <<'EOT'; |
6d12a859 | 393 | |
e0fe5231 WD |
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)! | |
6d12a859 | 397 | EOT |
56fc9f70 WD |
398 | |
399 | exit; | |
400 | ||
4f282b0b WD |
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 | ||
56fc9f70 WD |
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 | } |