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