#!/usr/bin/perl
# $Id: html-control.in,v 1.12 2004/10/26 14:00:05 cjwatson Exp $
use POSIX qw(strftime tzset ENOENT);
$ENV{"TZ"} = 'UTC';
tzset();
$config_path = '/etc/debbugs';
$lib_path = '/usr/lib/debbugs';
require("$config_path/config");
require("$lib_path/errorlib");
$ENV{'PATH'} = $lib_path.':'.$ENV{'PATH'};
chdir("$gSpoolDir") || die "chdir spool: $!\n";
#push(@INC,"$lib_path");
&filelock("html.fcntl-lock");
unlink("html-data.gz") || $!==&ENOENT or die "remove html-data.gz: $!";
sub nonawful ($) {
rename("stamp.html.run","stamp.html") or warn "warning: put back stamp.html: $!";
die $_[0];
}
if (open(US,'updateseqs') && -f 'stamp.html') {
chop($lastmain=);
chop($lastsub=);
close(US);
$lastsub++;
$args= "-diff -stampfile=stamp.html.run";
rename("stamp.html","stamp.html.run") or die "rename stamp.html: $!";
} else {
$lastsub=0;
$lastmain = strftime "%Y%m%d%H%M%S", localtime;
$args= '-full';
unlink('stamp.html') || $!==&ENOENT or die "excise stale stamp.html: $!";
}
open(X,">stamp.html.new") or die "stamp.html.new: $!";
close(X) or die "close stamp.html.new: $!";
open(US,'>updateseqs.new') || die "create updateseqs.new: $!";
print(US "$lastmain\n$lastsub\n") || die "write updateseqs.new: $!";
close(US) || die "close updateseqs.new: $!";
rename('updateseqs.new','updateseqs') or nonawful("install updateseqs: $!");
sub runshell ($&) {
my ($cmd,$errhref) = @_;
print "xx $cmd\n";
system $cmd;
!$? && !length($stderr) or &$errhref("$cmd failed - gave $? / $stderr");
}
$sequences="$lastmain $lastsub";
$seqmid= $sequences; $seqmid =~ y/ /-/;
open(MM,">html-data.mail") or nonawful("open html-data.mail: $!");
if ( length( $gListDomain ) > 0 && length( $gMirrorList ) > 0 ) {
print(MM <
X-$gProject-PR: update $sequences
END
) or nonawful("write html-data.mail header: $!");
} else {
print(MM <
X-$gProject-PR: update $sequences
END
) or nonawful("write html-data.mail header: $!");
}
close(MM) or nonawful("close html-data.mail: $!");
runshell("$lib_path/db2html $args 2>&1 >html-data $gWebDir/db",
sub { &nonawful; });
runshell("$lib_path/html-install $gWebDir/db &1",sub { &quit; });
#runshell("gzip -9 html-data 2>&1",sub { &quit; });
#runshell("btoa 2>&1 >html-data.mail",sub { &quit; });
#runshell('2>&1 '.join(' ',('/usr/lib/sendmail','-f'."$gMaintainerEmail")).' -oem -oi -t