#!/scratchbox/tools/bin/perl -w

=head1 NAME

dh_instalupstart - install upstart scripts into package build directories

=cut

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

init();

foreach my $package (@{$dh{DOPACKAGES}}) {
	my $tmp=tmpdir($package);

	# Figure out what filename to install it as.
	my $script;
	if (defined $dh{NAME}) {
		$script=$dh{NAME};
	}
	elsif ($dh{INIT_SCRIPT}) {
		$script=$dh{INIT_SCRIPT};
	}
	else {
		$script=$package;
	}       
	
	my $init=pkgfile($package,$script) || pkgfile($package,"upstart") ||
	      pkgfile($package,"event.d");

	if ($init ne '') {
		if (! $dh{ONLYSCRIPTS}) {
			if (! -d "$tmp/etc/event.replace.d") {
				doit("install","-d","$tmp/etc/event.replace.d");
			}
		
			doit("install","-p","-m644",$init,"$tmp/etc/event.replace.d/$script");
		}
		
		if (! $dh{NOSCRIPTS}) {
			autoscript($package,"postinst","postinst-upstart",
				"s/#SCRIPT#/$script/g");
		}
	}
}

=head1 SEE ALSO

L<debhelper(7)>

This program is a part of debhelper.

=head1 AUTHOR

Joey Hess <joeyh@debian.org>

=cut
