]> git.donarmstrong.com Git - debbugs.git/blob - scripts/html-control
Add Debbugs::BugWalker to abstract out bug-walking code in
[debbugs.git] / scripts / html-control
1 #!/usr/bin/perl
2 # $Id: html-control.in,v 1.12 2004/10/26 14:00:05 cjwatson Exp $
3
4 use POSIX qw(strftime tzset ENOENT);
5 $ENV{"TZ"} = 'UTC';
6 tzset();
7
8 $config_path = '/etc/debbugs';
9 $lib_path = '/usr/lib/debbugs';
10
11 require("$config_path/config");
12 require("$lib_path/errorlib");
13 $ENV{'PATH'} = $lib_path.':'.$ENV{'PATH'};
14
15 chdir("$gSpoolDir") || die "chdir spool: $!\n";
16 #push(@INC,"$lib_path");
17
18 &filelock("html.fcntl-lock");
19
20 unlink("html-data.gz") || $!==&ENOENT or die "remove html-data.gz: $!";
21
22 sub nonawful ($) {
23     rename("stamp.html.run","stamp.html") or warn "warning: put back stamp.html: $!";
24     die $_[0];
25 }
26
27 if (open(US,'updateseqs') && -f 'stamp.html') {
28     chop($lastmain=<US>);
29     chop($lastsub=<US>);
30     close(US);
31
32     $lastsub++;
33     $args= "-diff -stampfile=stamp.html.run";
34     rename("stamp.html","stamp.html.run") or die "rename stamp.html: $!";
35 } else {
36     $lastsub=0;
37     $lastmain = strftime "%Y%m%d%H%M%S", localtime;
38     $args= '-full';
39     unlink('stamp.html') || $!==&ENOENT or die "excise stale stamp.html: $!";
40 }
41
42 open(X,">stamp.html.new") or die "stamp.html.new: $!";
43 close(X) or die "close stamp.html.new: $!";
44
45 open(US,'>updateseqs.new') || die "create updateseqs.new: $!";
46 print(US "$lastmain\n$lastsub\n") || die "write updateseqs.new: $!";
47 close(US) || die "close updateseqs.new: $!";
48 rename('updateseqs.new','updateseqs') or nonawful("install updateseqs: $!");
49
50 sub runshell ($&) {
51     my ($cmd,$errhref) = @_;
52     print "xx $cmd\n";
53     system $cmd;
54     !$? && !length($stderr) or &$errhref("$cmd failed - gave $? / $stderr");
55 }
56
57 $sequences="$lastmain $lastsub";
58 $seqmid= $sequences; $seqmid =~ y/ /-/;
59 open(MM,">html-data.mail") or nonawful("open html-data.mail: $!");
60 if ( length( $gListDomain ) > 0 && length( $gMirrorList ) > 0 ) {
61 print(MM <<END
62 From: $gMaintainerEmail ($gProject $gBug Tracking System)
63 To: $gMirrorList\@$gListDomain
64 Subject: $gProject $gBugs autoupdate 259012
65 Message-ID: <handle.htmlup.$seqmid\@$gEmailDomain>
66 X-$gProject-PR: update $sequences
67
68 END
69       ) or nonawful("write html-data.mail header: $!");
70 } else {
71 print(MM <<END
72 From: $gMaintainerEmail ($gProject $gBug Tracking System)
73 To: $gMaintainerEmail
74 Subject: $gProject $gBugs autoupdate 259012
75 Message-ID: <handle.htmlup.$seqmid\@$gEmailDomain>
76 X-$gProject-PR: update $sequences
77
78 END
79       ) or nonawful("write html-data.mail header: $!");
80 }
81 close(MM) or nonawful("close html-data.mail: $!");
82
83 runshell("$lib_path/db2html $args 2>&1 >html-data $gWebDir/db",
84          sub { &nonawful; });
85 runshell("$lib_path/html-install $gWebDir/db <html-data 2>&1",sub { &quit; });
86 #runshell("gzip -9 html-data 2>&1",sub { &quit; });
87 #runshell("btoa 2>&1 <html-data.gz >>html-data.mail",sub { &quit; });
88 #runshell('2>&1 '.join(' ',('/usr/lib/sendmail','-f'."$gMaintainerEmail")).' -oem -oi -t <html-data.mail',
89 #         sub { &quit; });
90
91 rename("stamp.html.new","stamp.html") or die "install new stamp.html: $!";
92
93 unlink("html-data") or warn "remove html-data: $!";
94 #unlink("html-data.gz") or warn "remove html-data.gz: $!";
95 #unlink("html-data.mail") or warn "remove html-data.mail: $!";
96 unlink("stamp.html.run") || $!==&ENOENT or warn "remove stamp.html.run: $!";
97
98 print "sequences $lastmain $lastsub\n";
99
100 &unfilelock();
101 exit(0);