]> git.donarmstrong.com Git - debhelper.git/blob - dh_installinit
r1603: * Typo. Closes: #207999
[debhelper.git] / dh_installinit
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_installinit - install init scripts into package build directories
6
7 =cut
8
9 use strict;
10 use Debian::Debhelper::Dh_Lib;
11
12 =head1 SYNOPSIS
13
14 B<dh_installinit> [S<I<debhelper options>>] [B<--name=>I<name>] [B<-n>] [B<-r>] [B<-d>] [S<B<--> I<params>>]
15
16 =head1 DESCRIPTION
17
18 dh_installinit is a debhelper program that is responsible for installing
19 init scripts and associated defaults files into package build directories.
20
21 It also automatically generates the postinst and postrm and prerm commands
22 needed to set up the symlinks in /etc/rc*.d/ and to start and stop the init
23 scripts.
24
25 If a file named debian/package.init exists, then it is installed into
26 etc/init.d/package in the package build directory, with "package" replaced
27 by the package name.
28
29 If a file named debian/package.default exists, then it is installed into
30 etc/default/package in the package build directory, with "package" replaced
31 by the package name.
32
33 =head1 OPTIONS
34
35 =over 4
36
37 =item B<-n>, B<--noscripts>
38
39 Do not modify postinst/postrm/prerm scripts.
40
41 =item B<-r>, B<--no-restart-on-upgrade>
42
43 Do not restart init script on upgrade.
44
45 =item B<--no-start>
46
47 Do not start the init script on install or upgrade, or stop it on removal.
48 Only call update-rc.d. Useful for rcS scripts.
49
50 =item B<-d>, B<--remove-d>
51
52 Remove trailing "d" from the name of the package, and use the result for the
53 filename the init script is installed as in etc/init.d/ , and the default file
54 is installed as in etc/default/ . This may be useful for daemons with names
55 ending in "d". (Note: this takes precedence over the --init-script parameter
56 described below.)
57
58 =item B<-u>I<params> B<--update-rcd-params=>I<params>
59
60 =item B<--> I<params>
61
62 Pass "params" to L<update-rc.d(8)>. If not specified, "defaults" will be
63 passed to L<update-rc.d(8)>.
64
65 =item B<--name=>I<name>
66
67 Install the init script (and default file) using the filename I<name>
68 instead of the default filename, which is the package name. When this
69 parameter is used, dh_installinit looks for and installs files named
70 debian/package.name.init and debian/package.name.default, instead of the
71 usual debian/package.init and debian/package.default.
72
73 =item B<--init-script=>I<scriptname>
74
75 Use "scriptname" as the filename the init script is installed as in
76 etc/init.d/ (and also use it as the filename for the defaults file, if it
77 is installed). If you use this parameter, dh_installinit will look to see
78 if a file in the debian/ directory exists that looks like
79 "package.scriptname" and if so will install it as the init script in
80 preference to the files it normally installs.
81
82 This parameter is deprecated, use the --name parameter instead.
83
84 =back
85
86 =head1 NOTES
87
88 Note that this command is not idempotent. "dh_clean -k" should be called
89 between invocations of this command. Otherwise, it may cause multiple
90 instances of the same text to be added to maintainer scripts.
91
92 =cut
93
94 init();
95
96 foreach my $package (@{$dh{DOPACKAGES}}) {
97         my $tmp=tmpdir($package);
98
99         # Figure out what filename to install it as.
100         my $script;
101         if (defined $dh{NAME}) {
102                 $script=$dh{NAME};
103         }
104         elsif ($dh{D_FLAG}) {
105                 # -d on the command line sets D_FLAG. We will 
106                 # remove a trailing 'd' from the package name and 
107                 # use that as the name.
108                 $script=$package;
109                 if ($script=~m/(.*)d$/) {
110                         $script=$1;
111                 }
112                 else {
113                         warning("\"$package\" has no final d' in its name, but -d was specified.");
114                 }
115         }       
116         elsif ($dh{INIT_SCRIPT}) {
117                 $script=$dh{INIT_SCRIPT};
118         }
119         else {
120                 $script=$package;
121         }       
122         
123         my $init=pkgfile($package,$script) || pkgfile($package,"init") ||
124               pkgfile($package,"init.d");
125         my $default=pkgfile($package,'default');
126
127         if ($default ne '') {
128                 if (! -d "$tmp/etc/default") {
129                         doit("install","-d","$tmp/etc/default");
130                 }
131                 doit("install","-p","-m644",$default,"$tmp/etc/default/$script");
132         }
133
134         if ($init ne '') {
135                 if (! -d "$tmp/etc/init.d") {
136                         doit("install","-d","$tmp/etc/init.d");
137                 }
138
139                 doit("install","-p","-m755",$init,"$tmp/etc/init.d/$script");
140
141                 # This is set by the -u "foo" command line switch, it's
142                 # the parameters to pass to update-rc.d. If not set,
143                 # we have to say "defaults".
144                 my $params='';
145                 if (defined($dh{U_PARAMS})) {
146                         $params=join(' ',@{$dh{U_PARAMS}});
147                 }       
148                 if ($params eq '') {
149                         $params="defaults";
150                 }
151
152                 if (! $dh{NOSCRIPTS}) {
153                         if (! $dh{NO_START}) {
154                                 # update-rc.d, and start script
155                                 autoscript($package,"postinst", "postinst-init",
156                                         "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
157                         
158                                 if ($dh{R_FLAG}) {
159                                         # stops script only on remove
160                                         autoscript($package,"prerm","prerm-init-norestart",
161                                                 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
162                                 }
163                                 else {
164                                         # always stops script
165                                         autoscript($package,"prerm","prerm-init",
166                                                 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
167                                 }
168                         }
169                         else {
170                                 # just update-rc.d
171                                 autoscript($package,"postinst", "postinst-init-nostart",
172                                         "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
173                         }
174
175                         # removes rc.d links
176                         autoscript($package,"postrm","postrm-init",
177                                 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
178                 }
179         }
180 }
181
182 =head1 SEE ALSO
183
184 L<debhelper(7)>
185
186 This program is a part of debhelper.
187
188 =head1 AUTHOR
189
190 Joey Hess <joeyh@debian.org>
191
192 =cut