| 1 |
#!/usr/bin/perl |
| 2 |
# debbugsconfig: copies debbugs configuration files from templates, and |
| 3 |
# creates documentation in HTML and text |
| 4 |
# Copyright (C) 1999 Darren Benham |
| 5 |
# Copyright (C) 2000 Josip Rodin |
| 6 |
# Licensed under the version 2 of the GNU General Public License as |
| 7 |
# published by the Free Software Foundation |
| 8 |
|
| 9 |
use POSIX qw(strftime); |
| 10 |
use File::Path; |
| 11 |
|
| 12 |
if (@ARGV) { |
| 13 |
print STDOUT <<EOF; |
| 14 |
Usage: $0 |
| 15 |
|
| 16 |
debbugsconfig will copy basic debbugs configuration files from templates |
| 17 |
if they don't exist. |
| 18 |
|
| 19 |
It will also create BTS user documentation in HTML and text. |
| 20 |
|
| 21 |
EOF |
| 22 |
exit(0); |
| 23 |
} |
| 24 |
|
| 25 |
$gConfigDir = "/etc/debbugs" if (!defined($gConfigDir)); |
| 26 |
$config_dir="/usr/share/debbugs/examples"; |
| 27 |
&template("config", $gConfigDir); |
| 28 |
require "$gConfigDir/config"; |
| 29 |
unshift @INC, $gConfigDir; |
| 30 |
|
| 31 |
&template("text", $gConfigDir); |
| 32 |
require "text"; |
| 33 |
|
| 34 |
&template("Maintainers", $gConfigDir); |
| 35 |
&template("Maintainers.override", $gConfigDir); |
| 36 |
&template("pseudo-packages.description", $gConfigDir); |
| 37 |
&template("sources", "$gConfigDir/indices"); |
| 38 |
|
| 39 |
&template("nextnumber", $gSpoolDir); |
| 40 |
&touch("$gSpoolDir/index.archive.realtime"); |
| 41 |
&touch("$gSpoolDir/index.db.realtime"); |
| 42 |
print "Creating directories in $gSpoolDir:\n"; |
| 43 |
for my $num (0 .. 99) { |
| 44 |
&spooldirectory(sprintf('archive/%02d', $num)); |
| 45 |
&spooldirectory(sprintf('db-h/%02d', $num)); |
| 46 |
} |
| 47 |
print "\n"; |
| 48 |
|
| 49 |
# stuff used when testing (comment out the above) |
| 50 |
#unshift @INC, "../"; |
| 51 |
#require "../scripts/config.in"; |
| 52 |
#require "../scripts/text.in"; |
| 53 |
#$gWebDir = "gWebDir"; |
| 54 |
#$gDocDir = "gWebDir"; |
| 55 |
|
| 56 |
my $dtime = strftime "%a, %e %b %Y %T UTC", localtime; |
| 57 |
$gHTMLTail =~ s/SUBSTITUTE_DTIME/$dtime/; |
| 58 |
|
| 59 |
print "Creating files in $gWebDir:\n"; |
| 60 |
require('html/index.html.in'); |
| 61 |
&writefiles ('index', '', $gIndexHtml ); |
| 62 |
require('html/Access.html.in'); |
| 63 |
&writefiles ('Access', 'bug-log-access', $gAccessHtml ); |
| 64 |
require('html/Developer.html.in'); |
| 65 |
&writefiles ('Developer', 'bug-maint-info', $gDeveloperHtml ); |
| 66 |
require('html/Reporting.html.in'); |
| 67 |
&writefiles ('Reporting', 'bug-reporting', $gReportingHtml ); |
| 68 |
require('html/server-control.html.in'); |
| 69 |
&writefiles ('server-control', 'bug-maint-mailcontrol', $gControlHtml ); |
| 70 |
require('html/server-refcard.html.in'); |
| 71 |
&writefiles ('server-refcard', 'bug-mailserver-refcard', $gRefcardHtml ); |
| 72 |
require('html/server-request.html.in'); |
| 73 |
&writefiles ('server-request', 'bug-log-mailserver', $gRequestHtml ); |
| 74 |
print "\n"; |
| 75 |
|
| 76 |
exit(0); |
| 77 |
|
| 78 |
# -------------------------------------------------------------------------- # |
| 79 |
|
| 80 |
sub template { |
| 81 |
my ($name, $destdir) = @_; |
| 82 |
if (! -f "$destdir/$name") { |
| 83 |
if (! -d $destdir ) { |
| 84 |
File::Path::make_path($destdir, {'mode' => 0755 }); |
| 85 |
print "created $destdir/.\n"; |
| 86 |
} |
| 87 |
system("install -m644 $config_dir/$name $destdir/$name") == 0 || |
| 88 |
die "$!"; |
| 89 |
print "created $destdir/$name from template.\n"; |
| 90 |
} |
| 91 |
} |
| 92 |
|
| 93 |
sub touch { |
| 94 |
my $name = shift; |
| 95 |
unless (-f $name) { |
| 96 |
open TOUCH, ">> $name" or die "open $name: $!"; |
| 97 |
close TOUCH; |
| 98 |
print "created empty $name.\n"; |
| 99 |
} |
| 100 |
} |
| 101 |
|
| 102 |
sub spooldirectory { |
| 103 |
my $name = shift; |
| 104 |
unless (-d "$gSpoolDir/$name") { |
| 105 |
mkpath("$gSpoolDir/$name"); |
| 106 |
print "$name "; |
| 107 |
} |
| 108 |
} |
| 109 |
|
| 110 |
sub writefiles { |
| 111 |
local ($html, $text, $name) = @_; |
| 112 |
# first HTML |
| 113 |
unlink("$gWebDir/$html.html"); |
| 114 |
open(DEST, ">$gWebDir/$html.html") || die "\n$gWebDir/$html.html: $!"; |
| 115 |
print DEST $name; |
| 116 |
close(DEST); |
| 117 |
print "$html.html "; |
| 118 |
# now text |
| 119 |
return if ($text eq ""); # for index.html |
| 120 |
# This should be done with pipes instead of a temporary files, but lynx |
| 121 |
# doesn't read HTML from stdin :/ |
| 122 |
open(DEST, ">$gDocDir/$text.html") || die "\n$gDocDir/$text.html: $!"; |
| 123 |
$name =~ s,\nOther pages:\n.*?<hr>,,si; |
| 124 |
print DEST $name; |
| 125 |
close(DEST); |
| 126 |
unlink("$gDocDir/$text.txt"); |
| 127 |
$ENV{'HOME'} = "/tmp"; |
| 128 |
$ENV{'TERM'} = "linux"; |
| 129 |
if (-x "/usr/bin/links") { |
| 130 |
system ("rm -rf /tmp/.links/") == 0 || die; |
| 131 |
system ("links -dump $gDocDir/$text.html > $gDocDir/$text.txt") == 0 || |
| 132 |
die "\nunable to write $gDocDir/$text.txt\n"; |
| 133 |
system ("rm -rf /tmp/.links/"); |
| 134 |
} elsif (-x "/usr/bin/lynx") { |
| 135 |
system ("lynx -nolist -dump -cfg=/dev/null $gDocDir/$text.html > $gDocDir/$text.txt") == 0 || |
| 136 |
die "\nunable to write $gDocDir/$text.txt\n"; |
| 137 |
} else { |
| 138 |
print "unable to write text versions of the HTMLs!"; |
| 139 |
print "if you need them, install links or lynx and run debbugsconfig again"; |
| 140 |
return; |
| 141 |
} |
| 142 |
unlink("$gDocDir/$text.html") || die "\ncan't remove temporary file $gDocDir/$text.html: $!"; |
| 143 |
print "$text.txt "; |
| 144 |
} |