release-rsync 11 KB

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