summaryrefslogtreecommitdiff
path: root/dh_installinit
blob: e7f9b70b1a8b99d8f17d199240059fa5daac73ae (plain)
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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#!/usr/bin/perl -w
#
# Install debian/init[.d], and set up the postinst and postrm for init
# scripts.

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 ($dh{D_FLAG}) {
		# -d on the command line sets D_FLAG. We will 
		# remove a trailing 'd' from the package name and 
		# use that as the name.
		$script=$package;
		if ($script=~m/(.*)d$/) {
			$script=$1;
		}
		else {
			warning("\"$package\" has no final d' in its name, but -d was specified.");
		}
	}       
	elsif ($dh{INIT_SCRIPT}) {
		$script=$dh{INIT_SCRIPT};
	}
	else {
		$script=$package;
	}       

	my $init=pkgfile($package,$script) || pkgfile($package,"init") ||
	      pkgfile($package,"init.d");

	if ($init ne '') {
		if (! -d "$tmp/etc/init.d") {
			doit("install","-d","$tmp/etc/init.d");
		}

		doit("install","-p","-m755",$init,"$tmp/etc/init.d/$script");

		# This is set by the -u "foo" command line switch, it's
		# the parameters to pass to update-rc.d. If not set,
		# we have to say "defaults".
		my $params='';
		if (defined($dh{U_PARAMS})) {
			$params=join(' ',@{$dh{U_PARAMS}});
		}	
		if ($params eq '') {
			$params="defaults";
		}

		if (! $dh{NOSCRIPTS}) {
			# -r on the command line sets R_FLAG. If it's set, there
			# is no restart on upgrade.
			if ($dh{R_FLAG}) {
				autoscript($package,"postinst", "postinst-init-norestart",
					"s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
				autoscript($package,"postrm","postrm-init",
					"s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
				autoscript($package,"prerm","prerm-init-norestart",
					"s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
			}
			else {
				autoscript($package,"postinst","postinst-init",
					"s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
				autoscript($package,"postrm","postrm-init",
					"s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
				autoscript($package,"prerm","prerm-init",
					"s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
			}
		}
	}
}