]> git.donarmstrong.com Git - debhelper.git/blob - dh_installmodules
r1603: * Typo. Closes: #207999
[debhelper.git] / dh_installmodules
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_installmodules - register modules with modutils
6
7
8 =cut
9
10 use strict;
11 use Debian::Debhelper::Dh_Lib;
12 use File::Find;
13
14 =head1 SYNOPSIS
15
16 B<dh_installmodules> [S<I<debhelper options>>] [B<-n>] [B<--name=>I<name>]
17
18 =head1 DESCRIPTION
19
20 dh_installmodules is a debhelper program that is responsible for
21 registering kernel modules with modutils.
22
23 Files named debian/package.modules will be installed as
24 etc/modutils/package in the package build directory.
25
26 Then postinst and postrm commands are automatically generated to register
27 the modules when the package is installed. See L<dh_installdeb(1)> for an
28 explanation of how this works. Note that this will be done for any
29 package this program acts on which has either the above-mentioned file, or
30 has .o files in /lib/modules.
31
32 =head1 OPTIONS
33
34 =over 4
35
36 =item B<-n>, B<--noscripts>
37
38 Do not modify postinst/postrm scripts.
39
40 =item B<--name=>I<name>
41
42 Use "name" as the filename the modules file is installed in
43 etc/modutils/. When this parameter is used, dh_installmodules looks for and
44 installs files named debian/package.name.modules instead of the usual
45 debian/package.modules.
46
47 =back
48
49 =head1 NOTES
50
51 Note that this command is not idempotent. "dh_clean -k" should be called
52 between invocations of this command. Otherwise, it may cause multiple
53 instances of the same text to be added to maintainer scripts.
54
55 =cut
56
57 init();
58
59 # Returns true if there are any .o files in the passed directory.
60 sub find_kernel_modules {
61         my $searchdir=shift;
62         my @results=();
63
64         return unless -d $searchdir;
65         find(sub { push @results, $_ if /\.o$/ }, $searchdir);
66         return @results > 0;
67 }
68
69 foreach my $package (@{$dh{DOPACKAGES}}) {
70         my $tmp=tmpdir($package);
71         my $file=pkgfile($package,"modules");
72
73         if (! -e $tmp) {
74                 doit("install","-d",$tmp);
75         }
76
77         if ($file) {
78                 if (! -e "$tmp/etc/modutils") {
79                         doit("install","-d","$tmp/etc/modutils");
80                 }
81                 doit("install","-m","0644",$file,"$tmp/etc/modutils/".pkgfilename($package));
82         }
83
84         if (! $dh{NOSCRIPTS} &&
85             ($file || find_kernel_modules("$tmp/lib/modules"))) {
86                         autoscript($package,"postinst","postinst-modules","s/#PACKAGE#/$package/");
87                         autoscript($package,"postrm","postrm-modules","s/#PACKAGE#/$package/");
88         }
89 }
90
91 =head1 SEE ALSO
92
93 L<debhelper(7)>
94
95 This program is a part of debhelper.
96
97 =head1 AUTHOR
98
99 Joey Hess <joeyh@debian.org>
100
101 =cut