#!/usr/bin/perl

use Date::Format;

my $phlegm_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>$phlegm_version<!E_VSTAMP>/g;
        s/<!B_DSTAMP>.*<!E_DSTAMP>/<!B_DSTAMP>$date_string<!E_DSTAMP>/g;
        s/phlegm-(.*-)?.*\.zip/phlegm-$1$phlegm_version.zip/g;
        s/phlegm-src-.*.tar.gz/phlegm-src-$phlegm_version.tar.gz/g;
        print HTMLFILE $_;
    }
    close BAKFILE;
    close HTMLFILE;
    unlink "$filename.bak";
}
