]> git.donarmstrong.com Git - debhelper.git/blob - dh_installinit
r420: big monsta changes
[debhelper.git] / dh_installinit
1 #!/usr/bin/perl -w
2 #
3 # Install debian/init[.d], and set up the postinst and postrm for init
4 # scripts.
5
6 use strict;
7 use Debian::Debhelper::Dh_Lib;
8 init();
9
10 foreach my $package (@{$dh{DOPACKAGES}}) {
11         my $tmp=tmpdir($package);
12
13         # Figure out what filename to install it as.
14         my $script;
15         if ($dh{D_FLAG}) {
16                 # -d on the command line sets D_FLAG. We will 
17                 # remove a trailing 'd' from the package name and 
18                 # use that as the name.
19                 $script=$package;
20                 if ($script=~m/(.*)d$/) {
21                         $script=$1;
22                 }
23                 else {
24                         warning("\"$package\" has no final d' in its name, but -d was specified.");
25                 }
26         }       
27         elsif ($dh{INIT_SCRIPT}) {
28                 $script=$dh{INIT_SCRIPT};
29         }
30         else {
31                 $script=$package;
32         }       
33
34         my $init=pkgfile($package,$script) || pkgfile($package,"init") ||
35               pkgfile($package,"init.d");
36
37         if ($init ne '') {
38                 if (! -d "$tmp/etc/init.d") {
39                         doit("install","-d","$tmp/etc/init.d");
40                 }
41
42                 doit("install","-p","-m755",$init,"$tmp/etc/init.d/$script");
43
44                 # This is set by the -u "foo" command line switch, it's
45                 # the parameters to pass to update-rc.d. If not set,
46                 # we have to say "defaults".
47                 my $params='';
48                 if (defined($dh{U_PARAMS})) {
49                         $params=join(' ',@{$dh{U_PARAMS}});
50                 }       
51                 if ($params eq '') {
52                         $params="defaults";
53                 }
54
55                 if (! $dh{NOSCRIPTS}) {
56                         # -r on the command line sets R_FLAG. If it's set, there
57                         # is no restart on upgrade.
58                         if ($dh{R_FLAG}) {
59                                 autoscript($package,"postinst", "postinst-init-norestart",
60                                         "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
61                                 autoscript($package,"postrm","postrm-init",
62                                         "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
63                                 autoscript($package,"prerm","prerm-init-norestart",
64                                         "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
65                         }
66                         else {
67                                 autoscript($package,"postinst","postinst-init",
68                                         "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
69                                 autoscript($package,"postrm","postrm-init",
70                                         "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
71                                 autoscript($package,"prerm","prerm-init",
72                                         "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
73                         }
74                 }
75         }
76 }