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