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