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