]> git.donarmstrong.com Git - debhelper.git/blob - dh_installmodules
r576: * Rename debhelper.1 to debhelper.7.
[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>]
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 =back
41
42 =head1 NOTES
43
44 Note that this command is not idempotent. "dh_clean -k" should be called
45 between invocations of this command. Otherwise, it may cause multiple
46 instances of the same text to be added to maintainer scripts.
47
48 =cut
49
50 init();
51
52 # Returns true if there are any .o files in the passed directory.
53 sub find_kernel_modules {
54         my $searchdir=shift;
55         my @results=();
56
57         return unless -d $searchdir;
58         find(sub { push @results, $_ if /\.o$/ }, $searchdir);
59         return @results > 0;
60 }
61
62 foreach my $package (@{$dh{DOPACKAGES}}) {
63         my $tmp=tmpdir($package);
64         my $file=pkgfile($package,"modules");
65
66         if (! -e $tmp) {
67                 doit("install","-d",$tmp);
68         }
69
70         if ($file) {
71                 if (! -e "$tmp/etc/modutils") {
72                         doit("install","-d","$tmp/etc/modutils");
73                 }
74                 doit("install","-m","0644",$file,"$tmp/etc/modutils/$package");
75         }
76
77         if (! $dh{NOSCRIPTS} &&
78             ($file || find_kernel_modules("$tmp/lib/modules"))) {
79                         autoscript($package,"postinst","postinst-modules","s/#PACKAGE#/$package/");
80                         autoscript($package,"postrm","postrm-modules","s/#PACKAGE#/$package/");
81         }
82 }
83
84 =head1 SEE ALSO
85
86 L<debhelper(7)>
87
88 This program is a part of debhelper.
89
90 =head1 AUTHOR
91
92 Joey Hess <joeyh@debian.org>
93
94 =cut