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