release-rsync 13 KB

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