]> git.donarmstrong.com Git - debhelper.git/blob - dh_installinit
r575: * Removed vegistal substvars stuff from dh_inistallinit.
[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 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<--init-script=>I<scriptname>
66
67 Use "scriptname" as for the filename the init script is installed as in
68 etc/init.d/ (and also use it as the filename for the defaults file, if it
69 is installed). This is useful if you need to have an init script with a name
70 different from the package's name. Note that if you use this parameter,
71 dh_installinit will look to see if a file in the debian/ directory exists
72 that looks like "package.scriptname" and if so will install it as the init
73 script in preference to the files it normally installs. This feature is really
74 only useful if you need a single package to install more than one init script.
75
76 =back
77
78 =head1 NOTES
79
80 Note that this command is not idempotent. "dh_clean -k" should be called
81 between invocations of this command. Otherwise, it may cause multiple
82 instances of the same text to be added to maintainer scripts.
83
84 =cut
85
86 init();
87
88 foreach my $package (@{$dh{DOPACKAGES}}) {
89         my $tmp=tmpdir($package);
90
91         # Figure out what filename to install it as.
92         my $script;
93         if ($dh{D_FLAG}) {
94                 # -d on the command line sets D_FLAG. We will 
95                 # remove a trailing 'd' from the package name and 
96                 # use that as the name.
97                 $script=$package;
98                 if ($script=~m/(.*)d$/) {
99                         $script=$1;
100                 }
101                 else {
102                         warning("\"$package\" has no final d' in its name, but -d was specified.");
103                 }
104         }       
105         elsif ($dh{INIT_SCRIPT}) {
106                 $script=$dh{INIT_SCRIPT};
107         }
108         else {
109                 $script=$package;
110         }       
111
112         my $init=pkgfile($package,$script) || pkgfile($package,"init") ||
113               pkgfile($package,"init.d");
114         my $default=pkgfile($package,'default');
115
116         if ($default ne '') {
117                 if (! -d "$tmp/etc/default") {
118                         doit("install","-d","$tmp/etc/default");
119                 }
120                 doit("install","-p","-m644",$default,"$tmp/etc/default/$script");
121         }
122
123         if ($init ne '') {
124                 if (! -d "$tmp/etc/init.d") {
125                         doit("install","-d","$tmp/etc/init.d");
126                 }
127
128                 doit("install","-p","-m755",$init,"$tmp/etc/init.d/$script");
129
130                 # This is set by the -u "foo" command line switch, it's
131                 # the parameters to pass to update-rc.d. If not set,
132                 # we have to say "defaults".
133                 my $params='';
134                 if (defined($dh{U_PARAMS})) {
135                         $params=join(' ',@{$dh{U_PARAMS}});
136                 }       
137                 if ($params eq '') {
138                         $params="defaults";
139                 }
140
141                 if (! $dh{NOSCRIPTS}) {
142                         if (! $dh{NO_START}) {
143                                 # update-rc.d, and start script
144                                 autoscript($package,"postinst", "postinst-init",
145                                         "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
146                         
147                                 if ($dh{R_FLAG}) {
148                                         # stops script only on remove
149                                         autoscript($package,"prerm","prerm-init-norestart",
150                                                 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
151                                 }
152                                 else {
153                                         # always stops script
154                                         autoscript($package,"prerm","prerm-init",
155                                                 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
156                                 }
157                         }
158                         else {
159                                 # just update-rc.d
160                                 autoscript($package,"postinst", "postinst-init-nostart",
161                                         "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
162                         }
163
164                         # removes rc.d links
165                         autoscript($package,"postrm","postrm-init",
166                                 "s/#SCRIPT#/$script/;s/#INITPARMS#/$params/");
167                 }
168         }
169 }
170
171 =head1 SEE ALSO
172
173 L<debhelper(1)>
174
175 This program is a part of debhelper.
176
177 =head1 AUTHOR
178
179 Joey Hess <joeyh@debian.org>
180
181 =cut