]> git.donarmstrong.com Git - debhelper.git/blob - dh_installinit
r496: * Man page cleanups, Closes: #119335
[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<--init-script=>I<scriptname>] [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 daemon on upgrade.
44
45 =item B<-d>, B<--remove-d>
46
47 Remove trailing "d" from the name of the package, and use the result for the
48 filename the init script is installed as in etc/init.d/ , and the default file
49 is installed as in etc/default/ . This may be useful for daemons with names
50 ending in "d". (Note: this takes precedence over the --init-script parameter
51 described below.)
52
53 =item B<-u>I<params> B<--update-rcd-params=>I<params>
54
55 =item B<--> I<params>
56
57 Pass "params" to L<update-rc.d(8)>. If not specified, "defaults" will be
58 passed to L<update-rc.d(8)>.
59
60 =item B<--init-script=>I<scriptname>
61
62 Use "scriptname" as for the filename the init script is installed as in
63 etc/init.d/ (and also use it as the filename for the defaults file, if it
64 is installed). This is useful if you need to have an init script with a name
65 different from the package's name. Note that if you use this parameter,
66 dh_installinit will look to see if a file in the debian/ directory exists
67 that looks like "package.scriptname" and if so will install it as the init
68 script in preference to the files it normally installs. This feature is really
69 only useful if you need a single package to install more than one init script.
70
71 =back
72
73 =head1 NOTES
74
75 Note that this command is not idempotent. "dh_clean -k" should be called
76 between invocations of this command. Otherwise, it may cause multiple
77 instances of the same text to be added to maintainer scripts.
78
79 =cut
80
81 init();
82
83 foreach my $package (@{$dh{DOPACKAGES}}) {
84         my $tmp=tmpdir($package);
85
86         # Figure out what filename to install it as.
87         my $script;
88         if ($dh{D_FLAG}) {
89                 # -d on the command line sets D_FLAG. We will 
90                 # remove a trailing 'd' from the package name and 
91                 # use that as the name.
92                 $script=$package;
93                 if ($script=~m/(.*)d$/) {
94                         $script=$1;
95                 }
96                 else {
97                         warning("\"$package\" has no final d' in its name, but -d was specified.");
98                 }
99         }       
100         elsif ($dh{INIT_SCRIPT}) {
101                 $script=$dh{INIT_SCRIPT};
102         }
103         else {
104                 $script=$package;
105         }       
106
107         my $init=pkgfile($package,$script) || pkgfile($package,"init") ||
108               pkgfile($package,"init.d");
109         my $default=pkgfile($package,'default');
110
111         if ($default ne '') {
112                 if (! -d "$tmp/etc/default") {
113                         doit("install","-d","$tmp/etc/default");
114                 }
115                 doit("install","-p","-m644",$default,"$tmp/etc/default/$script");
116         }
117
118         if ($init ne '') {
119                 if (! -d "$tmp/etc/init.d") {
120                         doit("install","-d","$tmp/etc/init.d");
121                 }
122
123                 doit("install","-p","-m755",$init,"$tmp/etc/init.d/$script");
124
125                 # This is set by the -u "foo" command line switch, it's
126                 # the parameters to pass to update-rc.d. If not set,
127                 # we have to say "defaults".
128                 my $params='';
129                 if (defined($dh{U_PARAMS})) {
130                         $params=join(' ',@{$dh{U_PARAMS}});
131                 }       
132                 if ($params eq '') {
133                         $params="defaults";
134                 }
135
136                 if (! $dh{NOSCRIPTS}) {
137                         # -r on the command line sets R_FLAG. If it's set, there
138                         # is no restart on upgrade.
139                         if ($dh{R_FLAG}) {
140                                 autoscript($package,"postinst", "postinst-init-norestart",
141                                         "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
142                                 autoscript($package,"postrm","postrm-init",
143                                         "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
144                                 autoscript($package,"prerm","prerm-init-norestart",
145                                         "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
146                         }
147                         else {
148                                 autoscript($package,"postinst","postinst-init",
149                                         "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
150                                 autoscript($package,"postrm","postrm-init",
151                                         "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
152                                 autoscript($package,"prerm","prerm-init",
153                                         "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
154                         }
155                 }
156         }
157 }
158
159 =head1 SEE ALSO
160
161 L<debhelper(1)>
162
163 This program is a part of debhelper.
164
165 =head1 AUTHOR
166
167 Joey Hess <joeyh@debian.org>
168
169 =cut