#!/usr/bin/perl =head1 NAME site_build - builds the mod_perl docs =head1 SYNOPSIS perl bin/site_build --src=/path/to/docs_src --dst=/path/to/pubsub =cut # # this script does different things depending on how it was named (or # a symlink) if the name includes: # force - the whole site is rebuilt # pdf - builds pdfs # index - builds the index # verbose - turn the verbose mode on # # the easiest way is to use symlinks to the same script # # by default it only updates the changed files use strict; use warnings; use Getopt::Long; use Pod::Usage; # Config options my $string = 0; my ($src, $dst, $help, $man); pod2usage(1) unless @ARGV; GetOptions( 'src=s' => \$src, 'dst=s' => \$dst, 'help' => \$help, 'man' => \$man, ) or pod2usage(2); pod2usage(1) if $help; pod2usage( -verbose => 2) if $man; my $rel = "$src/dst_html"; my %fs = ( 'minotaur.apache.org' => '/x1', ); umask 0002; chdir $src; # Do different things depending on our name my ($name) = $0 =~ m|([^/]+)$|; update($name); # we must not try to sync the files when the filesystem is full, or # the whole online version may get rendered broken, since some files # will be simply truncated to 0 die "online fs is full, cannot sync the online site" if fs_is_full(); online_sync(); sub update { my ($name) = shift; my $reindex = $name =~ /index/ ? 1 : 0; my $flags = ''; $flags .= 'f' if $name =~ /force/; $flags .= 'd' if $name =~ /pdf/; $flags .= 'v' if $name =~ /verbose/; $flags = $flags ? "-$flags" : ""; system("svn update >/dev/null 2>&1"); system("bin/build $flags"); system("bin/makeindex") if $reindex; } sub online_sync { # for some reason we are having problems to preserve the timestamps :( # system("cp -pr $rel/ $dst/"); system("cp -r $rel/ $dst/"); system("find $dst -type d -exec chmod g+rwx {} \\; >/dev/null 2>&1"); system("find $dst -type f -exec chmod g+wr {} \\; >/dev/null 2>&1"); } sub fs_is_full { require Sys::Hostname; my $hostname = Sys::Hostname::hostname(); # don't check on local systems return 0 unless $hostname && $fs{$hostname}; # get available disk space my $disk = qx{ df | grep $fs{$hostname} }; my ($disk_avail) = ($disk =~ /(\d+)\s+\d+\%/); # avail is before capacity # get size of site my $site = qx{ du -c $rel | grep total }; my ($site_size) = ($site =~ /^(\d+)/); # give us a margin of 50MB return 0 unless $site_size + 50*1024 > $disk_avail; warn "site_size = $site_size , disk_avail = $disk_avail\n"; return 1; }