1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
|
#!/usr/bin/perl
# postinst for sgml-data
$action = $ARGV[0];
if ( $action eq "configure" ) {
@args = ("install-sgmlcatalog", "--quiet", "--install",
"/usr/lib/sgml-data/sgml.catalog", "sgml-data");
system(@args) == 0 or
die("sgml-data postinst: @args failed: $?");
# now we check if there's junk in the /etc/sgml.catalog
open(CAT, "</etc/sgml.catalog") or
die("sgml-data postinst: open of /etc/sgml.catalog failed: $!");
$junkincat = 0;
while (<CAT>) {
if ( m|dtd/html-3.2.dtd| ) {
$junkincat = 1;
last;
}
last if ( m/START SGML CATALOG ENTRY/ );
}
close CAT;
if ( $junkincat ) {
warn("sgml-data: found old junk in /etc/sgml.catalog, removing...\n");
# now we have the tough job of actually removing the bad entries
open(IN, "</etc/sgml.catalog") or
die("sgml-data postinst: open of /etc/sgml.catalog failed: $!");
open(OUT, ">/etc/sgml.catalog.new") or
die("sgml-data postinst: write of /etc/sgml.catalog.new failed: $!");
# variable to track whether we're cutting out or not
$writing = 1;
# variable to track if we have not yet hit the first package entry
$prepackage = 1;
while (<IN>) {
chomp;
if ( m/-- The SGML Declaration File/ && $prepackage ) {
$writing = 0;
}
if ( m/START SGML CATALOG ENTRY/ ) {
$prepackage = 0;
$writing = 1;
}
} continue {
$writing && print OUT $_ . "\n";
}
close IN;
close OUT;
@args = ("mv", "--backup", "-S", ".dpkg-old",
"/etc/sgml.catalog.new", "/etc/sgml.catalog");
system(@args) == 0 or
die("sgml-data postinst: @args failed: $?");
}
}
exit(0);
|