#!/usr/bin/perl -w # # Update the workshop section of the website # # - Trawl the source directories # # - If there's a file in the workshop that's also in the source # directory, and the source directory version is newer, copy it # over. This allows me full control over what's in the website # while at the same time keeping it up-to-date # # - Also generate an entry on index.html for the file # # September 2002: # Sort the files by filename # 08/03/2004 Add timestamp to file listing # 16/11/2004 Woo, google adsense use File::Find; use File::Copy; use File::Temp qw( tempfile ); use strict; my $debug = $ENV{'DEBUG'}||0; my $doit = $ENV{'DOIT'} ||0; my $adsense =<<"ADVERT"; ADVERT find( { wanted=> \&whackshop, no_chdir => 1, follow_skip => 2 }, $ENV{'HOME'} . "/src" ); find( { wanted=> \&genindex, no_chdir => 1, follow_skip => 2 }, $ENV{'HOME'} . "/public_html/hacks/workshop" ); exit; # ============================================================================= sub whackshop { my $file = $_; # Things to ignore return if -d $file; return if $file =~ m{/(CVS|RCS)(/.*|)$}; # Skip it if it's not in the workshop already my $shopfile = $file; $shopfile =~ s|$ENV{'HOME'}/src|$ENV{'HOME'}/public_html/hacks/workshop|; return if ! -f $shopfile; print STDERR "Checking $shopfile..." if $debug; my ( undef, undef, undef, undef, undef, undef, undef, undef, undef, $mtime1, undef, undef, undef, undef ) = stat( $file ); my ( undef, undef, undef, undef, undef, undef, undef, undef, undef, $mtime2, undef, undef, undef, undef ) = stat( $shopfile ); # safety $mtime1 ||= 0; $mtime2 ||= 0; if ( $mtime1 > $mtime2 ) { print STDERR "newer version available" if $debug; unlink( $shopfile ); # in case it's write protected or whatever copy( $file, $shopfile ) or die "Failed to update $file: $!"; } print STDERR "\n" if $debug; } sub genindex { my $file = $_; return if ! -d $file; return if $file =~ /workshop$/; # don't touch this index! print STDERR "genindex in $file\n" if $debug; opendir( DIR, "$file" ); my @files = grep !/^(.\.?|index\.html-new|index\.html)$/, readdir( DIR ); closedir( DIR ); # Oog my $level = $file; $level =~ s|$ENV{'HOME'}/public_html/||; $level =~ s|[^/]+|..|g; my $title = $file; $title =~ s|^.*/||; $title .= " hacks"; my ( $fh, $filename ) = tempfile(); print $fh <<"HEADER";
$adsense
HEADER my $origin = $file; $origin =~ s@public_html/hacks/workshop@src@; if ( open( HEADER, "<$origin/header.html" )) { while ( my $l =This page contains links to some of my $title. It is autogenerated from the comments (if any) at the head of each file.
| Waider | Ugh. Did I write that? |