nightly-rsync 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174
  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. It also requires a
  5. # git checkout of rsync (feel free to use your normal rsync build dir as
  6. # long as it doesn't have any uncommitted changes).
  7. #
  8. # If this is run with -ctu, it will make an updated "nightly" tar file in
  9. # the nightly dir. It will also remove any old tar files, regenerate the
  10. # HTML man pages in the nightly dir, and then rsync the changes to the
  11. # samba.org server.
  12. use Getopt::Long;
  13. use Date::Format;
  14. # Where the local copy of /home/ftp/pub/rsync/dev/nightly should be updated.
  15. our $dest = $ENV{HOME} . '/samba-rsync-ftp/dev/nightly';
  16. our $nightly_symlink = "$dest/rsync-HEAD.tar.gz";
  17. our($make_tar, $upload, $help_opt);
  18. &Getopt::Long::Configure('bundling');
  19. &usage if !&GetOptions(
  20. 'make-tar|t' => \$make_tar,
  21. 'upload|u' => \$upload,
  22. 'help|h' => \$help_opt,
  23. ) || $help_opt;
  24. our $name = time2str('rsync-HEAD-%Y%m%d-%H%M%Z', time, 'GMT');
  25. our $ztoday = time2str('%d %b %Y', time);
  26. our $today = $ztoday;
  27. our $gen_target = $upload ? 'gensend' : 'gen';
  28. die "$dest does not exist\n" unless -d $dest;
  29. die "There is no .git dir in the current directory.\n" unless -d '.git';
  30. die "There is no rsync checkout in the current directory.\n" unless -f 'rsyncd.conf.yo';
  31. if ($make_tar) {
  32. open(IN, '-|', 'git status') or die $!;
  33. my $status = join('', <IN>);
  34. close IN;
  35. die "The checkout is not clean:\n", $status unless $status =~ /\nnothing to commit \(working directory clean\)/;
  36. die "The checkout is not on the master branch.\n" unless $status =~ /^# On branch master\n/;
  37. system "make $gen_target" and die "make $gen_target failed!\n";
  38. my @extra_files;
  39. open(IN, '<', 'Makefile.in') or die "Couldn't open Makefile.in: $!\n";
  40. while (<IN>) {
  41. if (s/^GENFILES=//) {
  42. while (s/\\$//) {
  43. $_ .= <IN>;
  44. }
  45. @extra_files = split(' ', $_);
  46. last;
  47. }
  48. }
  49. close IN;
  50. my $confversion;
  51. open(IN, '<', 'configure.ac') or die "Unable to open configure.ac: $!\n";
  52. while (<IN>) {
  53. if (/^RSYNC_VERSION=(.*)/) {
  54. $confversion = $1;
  55. last;
  56. }
  57. }
  58. close IN;
  59. die "Unable to find RSYNC_VERSION in configure.ac\n" unless defined $confversion;
  60. open(IN, '<', 'OLDNEWS') or die "Unable to open OLDNEWS: $!\n";
  61. $_ = <IN>;
  62. my($lastversion) = /(\d+\.\d+\.\d+)/;
  63. my $last_protocol_version;
  64. while (<IN>) {
  65. 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+)$/) {
  66. $last_protocol_version = $pver if $ver eq $lastversion;
  67. }
  68. }
  69. close IN;
  70. die "Unable to determine protocol_version for $lastversion.\n" unless defined $last_protocol_version;
  71. my($protocol_version,$subprotocol_version);
  72. open(IN, '<', 'rsync.h') or die "Unable to open rsync.h: $!\n";
  73. while (<IN>) {
  74. if (/^#define\s+PROTOCOL_VERSION\s+(\d+)/) {
  75. $protocol_version = $1;
  76. } elsif (/^#define\s+SUBPROTOCOL_VERSION\s+(\d+)/) {
  77. $subprotocol_version = $1;
  78. }
  79. }
  80. close IN;
  81. die "Unable to determine the current PROTOCOL_VERSION.\n" unless defined $protocol_version;
  82. die "Unable to determine the current SUBPROTOCOL_VERSION.\n" unless defined $subprotocol_version;
  83. if ($confversion =~ /dev|pre/) {
  84. if ($last_protocol_version ne $protocol_version) {
  85. if ($subprotocol_version == 0) {
  86. die "SUBPROTOCOL_VERSION must not be 0 for a non-final release with a changed PROTOCOL_VERSION.\n";
  87. }
  88. } else {
  89. if ($subprotocol_version != 0) {
  90. die "SUBPROTOCOL_VERSION must be 0 when the PROTOCOL_VERSION hasn't changed from the last release.\n";
  91. }
  92. }
  93. } else {
  94. if ($subprotocol_version != 0) {
  95. die "SUBPROTOCOL_VERSION must be 0 for a final release.\n";
  96. }
  97. }
  98. print "Creating $name.tar.gz\n";
  99. system "rsync -a @extra_files $name/";
  100. system "git archive --format=tar --prefix=$name/ HEAD | tar xf -";
  101. system "support/git-set-file-times --prefix=$name/";
  102. system "fakeroot tar czf $dest/$name.tar.gz $name; rm -rf $name";
  103. unlink($nightly_symlink);
  104. symlink("$name.tar.gz", $nightly_symlink);
  105. }
  106. foreach my $fn (qw( rsync.yo rsyncd.conf.yo )) {
  107. my $yo_tmp = "$dest/$fn";
  108. (my $html_fn = "$dest/$fn") =~ s/\.yo/.html/;
  109. open(IN, '<', $fn) or die $!;
  110. undef $/; $_ = <IN>; $/ = "\n";
  111. close IN;
  112. s/^(manpage\([^)]+\)\(\d+\)\()[^)]+(\).*)/$1$today$2/m;
  113. #s/^(This man ?page is current for version) \S+ (of rsync)/$1 $version $2/m;
  114. open(OUT, '>', $yo_tmp) or die $!;
  115. print OUT $_;
  116. close OUT;
  117. system 'yodl2html', '-o', $html_fn, $yo_tmp;
  118. unlink($yo_tmp);
  119. }
  120. chdir($dest) or die $!;
  121. my $cnt = 0;
  122. open(PIPE, '-|', 'ls -1t rsync-HEAD-*') or die $!;
  123. while (<PIPE>) {
  124. chomp;
  125. next if $cnt++ < 10;
  126. unlink($_);
  127. }
  128. close PIPE;
  129. system 'ls -ltr';
  130. if ($upload) {
  131. my $opt = '';
  132. if (defined $ENV{RSYNC_PARTIAL_DIR}) {
  133. $opt = " -f 'R $ENV{RSYNC_PARTIAL_DIR}'";
  134. }
  135. system "rsync$opt -aviHP --delete-after . samba.org:/home/ftp/pub/rsync/dev/nightly";
  136. }
  137. exit;
  138. sub usage
  139. {
  140. die <<EOT;
  141. Usage: nightly-rsync [OPTIONS]
  142. -t, --make-tar create a new tar file in $dest
  143. -u, --upload upload the revised nightly dir to samba.org
  144. -h, --help display this help
  145. EOT
  146. }