#!/usr/bin/perl -w

=head1 NAME

dh_installxsp - install host files into /etc/xsp/conf.d and 
/etc/mono-server/conf.d

=cut

use strict;
use Debian::Debhelper::Dh_Lib;

=head1 SYNOPSIS

B<dh_installxsp> [S<B<debhelper options>>] [B<--name=>I<name>]

=head1 DESCRIPTION

dh_installxsp is a debhelper program that will install host configuration
files in /etc/xsp/conf.d and /etc/monoserver/conf.d. So, if xsp is 
install or will be installed, when xsp starts it automatically starts 
the daemon with the host file. The files debian/package.hostxsp are installed.

=head1 OPTIONS

=over 4

=item B<--name=>I<name>

Look for files named debian/package.hostxsp and install them as
/etc/xsp/conf.d/package/hostfile.

=back

=cut

init();

my $depname="net:XspServer";

foreach my $package (@{$dh{DOPACKAGES}}) {
	my $tmp=tmpdir($package);
	my $hostfile=pkgfile($package,"hostxsp");
	if ($hostfile) {
    delsubstvar( $package, $depname );    # for idempotency
    addsubstvar( $package, $depname, 
      "mono-xsp | mono-apache-server" );
	    if( ! -d "$tmp/etc/xsp/conf.d" ) {
		doit("install","-d","$tmp/etc/xsp/conf.d");
	    }
	    if( ! -d "$tmp/etc/xsp/conf.d/".pkgfilename($package)) {
		doit("install","-d","$tmp/etc/xsp/conf.d/".pkgfilename($package));
	    }
	    doit("install","-m",644,$hostfile,"$tmp/etc/xsp/conf.d/".pkgfilename($package)."/10_".pkgfilename($package));

	    if( ! -d "$tmp/etc/mono-server/conf.d" ) {
		doit("install","-d","$tmp/etc/mono-server/conf.d");
	    }
	    if( ! -d "$tmp/etc/mono-server/conf.d/".pkgfilename($package)) {
		doit("install","-d","$tmp/etc/mono-server/conf.d/".pkgfilename($package));
	    }
	    
	    doit("install","-m",644,$hostfile,"$tmp/etc/mono-server/conf.d/".pkgfilename($package)."/10_".pkgfilename($package));

	    if ($hostfile ne '') {
                if (! $dh{NOSCRIPTS}) {
		    autoscript($package,"postinst","postinst-monoxsp",
			       "s/#PACKAGE#/$package/");
		    autoscript($package,"postrm","postrm-monoxsp",
			       "s/#PACKAGE#/$package/");
                }
	    }

	}	
}

=head1 SEE ALSO

L<debhelper(7)>

This program is a part of mono-utils.

=head1 AUTHOR

Pablo Fischer <pablo@pablo.com.mx>

=cut
