#!/usr/bin/perl

use Date::Format;

my $anproxy_version = shift || die "Must pass version number!";

my @html_files = ( "index.htm" );

my $date_string = time2str("%a, %e %b %Y %T -0400", time);

# Replace the version and datestamps in each file
foreach $filename (@html_files) {
    print "$filename\n";
    rename "$filename", "$filename.bak";
    open (BAKFILE, "$filename.bak");
    open (HTMLFILE, ">$filename");
    while (<BAKFILE>) {
        s/<!B_VSTAMP>.*<!E_VSTAMP>/<!B_VSTAMP>$anproxy_version<!E_VSTAMP>/g;
        s/<!B_DSTAMP>.*<!E_DSTAMP>/<!B_DSTAMP>$date_string<!E_DSTAMP>/g;
        s/anproxy-(.*-)?.*\.zip/anproxy-$1$anproxy_version.zip/g;
        s/anproxy-src-.*.tar.gz/anproxy-src-$anproxy_version.tar.gz/g;
        print HTMLFILE $_;
    }
    close BAKFILE;
    close HTMLFILE;
    unlink "$filename.bak";
}
