Improved check_for_finished_files() to be really, really sure
[rsync/rsync.git] / packaging / nightly-rsync
CommitLineData
920071e2
WD
1#!/usr/bin/perl
2use strict;
3
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. It also requires a
6# pristine CVS checkout of rsync (don't use your normal rsync build dir
7# unless you're 100% sure that there are not unchecked-in changes).
8#
9# If this is run with -ctu, it will make an updated "nightly" tar file in
10# the nightly dir. It will also remove any old tar files, regenerate the
11# HTML man pages in the nightly dir, and then rsync the changes to the
12# samba.org server.
13
14use Getopt::Long;
15use Date::Format;
16
920071e2 17# Where the local copy of /home/ftp/pub/rsync/nightly should be updated.
20c7d7fd
WD
18our $dest = $ENV{HOME} . '/samba-rsync-ftp/nightly';
19our $nightly_symlink = "$dest/rsync-HEAD.tar.gz";
920071e2 20
20c7d7fd 21our($make_tar, $upload, $help_opt);
920071e2
WD
22&Getopt::Long::Configure('bundling');
23&usage if !&GetOptions(
920071e2
WD
24 'make-tar|t' => \$make_tar,
25 'upload|u' => \$upload,
26 'help|h' => \$help_opt,
27) || $help_opt;
28
29our $name = time2str('rsync-HEAD-%Y%m%d-%H%M%Z', time, 'GMT');
30our $ztoday = time2str('%d %b %Y', time);
31our $today = $ztoday;
9217ce30 32our $gen_target = $upload ? 'gensend' : 'gen';
920071e2 33
20c7d7fd
WD
34die "$dest does not exist\n" unless -d $dest;
35die "There is no .git dir in the current directory.\n" unless -d '.git';
36die "There is no rsync checkout in the current directory.\n" unless -f 'rsyncd.conf.yo';
920071e2
WD
37
38if ($make_tar) {
6a2456c5 39 open(IN, '-|', 'git status') or die $!;
20c7d7fd
WD
40 my $status = join('', <IN>);
41 close IN;
42 die "The checkout is not clean:\n", $status unless $status =~ /\nnothing to commit \(working directory clean\)/;
43 die "The checkout is not on the master branch.\n" unless $status =~ /^# On branch master\n/;
44
67b9b26f
WD
45 my @extra_files;
46 open(IN, '<', 'Makefile.in') or die "Couldn't open Makefile.in: $!\n";
47 while (<IN>) {
48 if (s/^GENFILES=//) {
49 while (s/\\$//) {
50 $_ .= <IN>;
51 }
52 @extra_files = split(' ', $_);
53 last;
54 }
55 }
20c7d7fd 56 close IN;
20c7d7fd
WD
57
58 print "Creating $name.tar.gz\n";
9217ce30
WD
59 system "make $gen_target; rsync -a @extra_files $name/";
60 system "git archive --format=tar --prefix=$name/ HEAD | tar xf -";
61 system "support/git-set-file-times --prefix=$name/";
62 system "fakeroot tar czf $dest/$name.tar.gz $name; rm -rf $name";
63
80aff93b
WD
64 unlink($nightly_symlink);
65 symlink("$name.tar.gz", $nightly_symlink);
920071e2
WD
66}
67
920071e2 68foreach my $fn (qw( rsync.yo rsyncd.conf.yo )) {
20c7d7fd
WD
69 my $yo_tmp = "$dest/$fn";
70 (my $html_fn = "$dest/$fn") =~ s/\.yo/.html/;
920071e2 71
20c7d7fd 72 open(IN, '<', $fn) or die $!;
920071e2
WD
73 undef $/; $_ = <IN>; $/ = "\n";
74 close IN;
75
76 s/^(manpage\([^)]+\)\(\d+\)\()[^)]+(\).*)/$1$today$2/m;
77 #s/^(This man ?page is current for version) \S+ (of rsync)/$1 $version $2/m;
78
20c7d7fd 79 open(OUT, '>', $yo_tmp) or die $!;
920071e2
WD
80 print OUT $_;
81 close OUT;
82
20c7d7fd 83 system 'yodl2html', '-o', $html_fn, $yo_tmp;
920071e2 84
20c7d7fd 85 unlink($yo_tmp);
920071e2
WD
86}
87
20c7d7fd
WD
88chdir($dest) or die $!;
89
085e2fd5
WD
90my $cnt = 0;
91open(PIPE, '-|', 'ls -1t rsync-HEAD-*') or die $!;
92while (<PIPE>) {
93 chomp;
94 next if $cnt++ < 10;
95 unlink($_);
96}
97close PIPE;
98
920071e2
WD
99system 'ls -ltr';
100
101if ($upload) {
230328a3
WD
102 my $opt = '';
103 if (defined $ENV{RSYNC_PARTIAL_DIR}) {
104 $opt = " -f 'R $ENV{RSYNC_PARTIAL_DIR}'";
105 }
106 system "rsync$opt -aviHP --delete-after . samba.org:/home/ftp/pub/rsync/nightly";
920071e2
WD
107}
108
109exit;
110
111sub usage
112{
113 die <<EOT;
114Usage: nightly-rsync [OPTIONS]
115
20c7d7fd 116 -t, --make-tar create a new tar file in $dest
920071e2
WD
117 -u, --upload upload the revised nightly dir to samba.org
118 -h, --help display this help
119EOT
120}