{
    open (RD, "</etc/lilo.conf")
	|| warn "Cannot open input file /etc/lilo.conf: $!\n";

    @preamble = ();
    %preamble = ();
    %parts = ();
    %lines = ();
    @lines = ();
    my $image = undef;
    while (<RD>)
    {
	chop;
	if (/image=/)
	{
	    $image = 0 unless (defined $image);
	    $image++;
	    push @images, $image;
	}
	if ($image)
	{
	    $parts{$image} .= "$_\n";
	}
	else
	{
	    push @preamble, $_;
	    $preamble{$_} = 1;
	}
    }
    close(RD);
    my @header = (
	"#------------------------------------------------------------",
	"# BE CAREFUL WHEN MODIFYING THIS FILE! It is updated automatically",
	"# by the SME server software. A few settings are altered by the",
	"# template processing of the file and white space is removed,",
	"# but otherwise changes to the file are preserved.",
	"#",
	"# For more information, see http://www.e-smith.org/custom/ and",
	"# the template fragments in /etc/e-smith/templates/etc/lilo.conf/.",
	"# ",
	"# copyright (C) 2002 Mitel Networks Corporation",
	"#------------------------------------------------------------",
    );
    foreach my $line (@header)
    {
	# Print the header banner, and delete any of its lines from the
	# buffer, so that it isn't repeated.
	my $test = $line;
	$test =~ tr/()/../; # Avoid special interpretation of () in pattern
	@preamble = grep { !/^$test$/ } @preamble;
	$OUT .= "$line\n";
    }
    my @oldheader = (
	"#------------------------------------",
	"# DO NOT MODIFY THIS FILE! It is updated automatically by the",
	"# e-smith server and gateway software. Instead, modify the source",
	"# template in the /etc/e-smith/templates directory. For more",
	"# information, see http://www.e-smith.org.",
	"# ",
	"# copyright (C)",
	"# TEMPLATE END",
    );
    # Remove any remnant old template-begin or template-end
    foreach my $line (@oldheader)
    {
	my $test = $line;
	$test =~ tr/()/../; # Avoid special interpretation of () in pattern
	@preamble = grep { !/^$test/ } @preamble;
    }
}
