]> git.donarmstrong.com Git - debhelper.git/blob - dh_installinit
r1853: * Fix dangling markup in dh_installinit pod. Closes: #348073
[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<-o>, B<--onlyscripts>
42
43 Only modify postinst/postrm/prerm scripts, do not actually install any init
44 script or default files. May be useful if the init script is shipped and/or
45 installed by upstream in a way that doesn't make it easy to let
46 dh_installinit find it.
47
48 =item B<-r>, B<--no-restart-on-upgrade>
49
50 Do not restart init script on upgrade.
51
52 =item B<--no-start>
53
54 Do not start the init script on install or upgrade, or stop it on removal.
55 Only call update-rc.d. Useful for rcS scripts.
56
57 =item B<-d>, B<--remove-d>
58
59 Remove trailing "d" from the name of the package, and use the result for the
60 filename the init script is installed as in etc/init.d/ , and the default file
61 is installed as in etc/default/ . This may be useful for daemons with names
62 ending in "d". (Note: this takes precedence over the --init-script parameter
63 described below.)
64
65 =item B<-u>I<params> B<--update-rcd-params=>I<params>
66
67 =item B<--> I<params>
68
69 Pass "params" to L<update-rc.d(8)>. If not specified, "defaults" will be
70 passed to L<update-rc.d(8)>.
71
72 =item B<--name=>I<name>
73
74 Install the init script (and default file) using the filename I<name>
75 instead of the default filename, which is the package name. When this
76 parameter is used, dh_installinit looks for and installs files named
77 debian/package.name.init and debian/package.name.default, instead of the
78 usual debian/package.init and debian/package.default.
79
80 =item B<--init-script=>I<scriptname>
81
82 Use "scriptname" as the filename the init script is installed as in
83 etc/init.d/ (and also use it as the filename for the defaults file, if it
84 is installed). If you use this parameter, dh_installinit will look to see
85 if a file in the debian/ directory exists that looks like
86 "package.scriptname" and if so will install it as the init script in
87 preference to the files it normally installs.
88
89 This parameter is deprecated, use the --name parameter instead.
90
91 =item B<--error-handler=>I<function>
92
93 Call the named shell function if running the init script fails. The
94 function should be provided in the prerm and postinst scripts, before the
95 #DEBHELPER# token.
96
97 =back
98
99 =head1 NOTES
100
101 Note that this command is not idempotent. "dh_clean -k" should be called
102 between invocations of this command. Otherwise, it may cause multiple
103 instances of the same text to be added to maintainer scripts.
104
105 =cut
106
107 init();
108
109 foreach my $package (@{$dh{DOPACKAGES}}) {
110         my $tmp=tmpdir($package);
111
112         # Figure out what filename to install it as.
113         my $script;
114         if (defined $dh{NAME}) {
115                 $script=$dh{NAME};
116         }
117         elsif ($dh{D_FLAG}) {
118                 # -d on the command line sets D_FLAG. We will 
119                 # remove a trailing 'd' from the package name and 
120                 # use that as the name.
121                 $script=$package;
122                 if ($script=~m/(.*)d$/) {
123                         $script=$1;
124                 }
125                 else {
126                         warning("\"$package\" has no final d' in its name, but -d was specified.");
127                 }
128         }       
129         elsif ($dh{INIT_SCRIPT}) {
130                 $script=$dh{INIT_SCRIPT};
131         }
132         else {
133                 $script=$package;
134         }       
135         
136         my $init=pkgfile($package,$script) || pkgfile($package,"init") ||
137               pkgfile($package,"init.d");
138         my $default=pkgfile($package,'default');
139
140         if ($default ne '' && ! $dh{ONLYSCRIPTS}) {
141                 if (! -d "$tmp/etc/default") {
142                         doit("install","-d","$tmp/etc/default");
143                 }
144                 doit("install","-p","-m644",$default,"$tmp/etc/default/$script");
145         }
146
147         if ($init ne '' || $dh{ONLYSCRIPTS}) {
148                 if (! $dh{ONLYSCRIPTS}) {
149                         if (! -d "$tmp/etc/init.d") {
150                                 doit("install","-d","$tmp/etc/init.d");
151                         }
152                 
153                         doit("install","-p","-m755",$init,"$tmp/etc/init.d/$script");
154                 }
155                 
156                 # This is set by the -u "foo" command line switch, it's
157                 # the parameters to pass to update-rc.d. If not set,
158                 # we have to say "defaults".
159                 my $params='';
160                 if (defined($dh{U_PARAMS})) {
161                         $params=join(' ',@{$dh{U_PARAMS}});
162                 }       
163                 if ($params eq '') {
164                         $params="defaults";
165                 }
166                 
167                 if (! $dh{NOSCRIPTS}) {
168                         if (! $dh{NO_START}) {
169                                 # update-rc.d, and start script
170                                 autoscript($package,"postinst", "postinst-init",
171                                         "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
172                         
173                                 if ($dh{R_FLAG}) {
174                                         # stops script only on remove
175                                         autoscript($package,"prerm","prerm-init-norestart",
176                                                 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
177                                 }
178                                 else {
179                                         # always stops script
180                                         autoscript($package,"prerm","prerm-init",
181                                                 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
182                                 }
183                         }
184                         else {
185                                 # just update-rc.d
186                                 autoscript($package,"postinst", "postinst-init-nostart",
187                                         "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
188                         }
189
190                         # removes rc.d links
191                         autoscript($package,"postrm","postrm-init",
192                                 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/;s/#ERROR_HANDLER#/$dh{ERROR_HANDLER}/");
193                 }
194         }
195 }
196
197 =head1 SEE ALSO
198
199 L<debhelper(7)>
200
201 This program is a part of debhelper.
202
203 =head1 AUTHOR
204
205 Joey Hess <joeyh@debian.org>
206
207 =cut