]> git.donarmstrong.com Git - debhelper.git/blob - dh_installmodules
r1968: * dh_fixperms: Make all files in /usr/include 644, not only .h files.
[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.
22
23 Files named debian/package.modules will be installed as
24 etc/modutils/package in the package build directory. This is for use by
25 modutils. Files named debian/package.modprobe will be installed in
26 etc/modprobe.d/package in the package build directory, to be used by
27 module-init-tools's version of modprobe.
28
29 Kernel modules are searched for in the package build directory and if
30 found, postinst and postrm commands are automatically generated to 
31 run depmod and register the modules when the package is installed. 
32 These commands are inserted into the maintainer scripts by dh_installdeb.
33 See L<dh_installdeb(1)> for an explanation of how this works.
34
35 =head1 OPTIONS
36
37 =over 4
38
39 =item B<-n>, B<--noscripts>
40
41 Do not modify postinst/postrm scripts.
42
43 =item B<--name=>I<name>
44
45 When this parameter is used, dh_installmodules looks for and
46 installs files named debian/package.name.modules and
47 debian/package.name.modprobe instead of the usual
48 debian/package.modules and debian/package.modprobe
49
50 =back
51
52 =head1 NOTES
53
54 Note that this command is not idempotent. "dh_clean -k" should be called
55 between invocations of this command. Otherwise, it may cause multiple
56 instances of the same text to be added to maintainer scripts.
57
58 =cut
59
60 init();
61
62 # Looks for kernel modules in the passed directory. If any are found,
63 # returns the kernel version (or versions) that the modules seem to be for.
64 sub find_kernel_modules {
65         my $searchdir=shift;
66         my %versions;
67
68         return unless -d $searchdir;
69         find(sub {
70                 if (/\.k?o$/) {
71                         my ($kvers)=$File::Find::dir=~m!lib/modules/([^/]+)/!;
72                         if (! defined $kvers || ! length $kvers) {
73                                 warning("Cannot determine kernel version for module $File::Find::name");
74                         }
75                         else {
76                                 $versions{$kvers}=1;
77                         }
78                 }
79         }, $searchdir);
80
81         return keys %versions;
82 }
83
84 foreach my $package (@{$dh{DOPACKAGES}}) {
85         my $tmp=tmpdir($package);
86         my $modutils_file=pkgfile($package,"modules");
87         my $modprobe_file=pkgfile($package,"modprobe");
88
89         if (! -e $tmp) {
90                 doit("install","-d",$tmp);
91         }
92
93         if ($modutils_file) {
94                 if (! -e "$tmp/etc/modutils") {
95                         doit("install","-d","$tmp/etc/modutils");
96                 }
97                 doit("install","-m","0644",$modutils_file,"$tmp/etc/modutils/".pkgfilename($package));
98         }
99
100         if ($modprobe_file) {
101                 if (! -e "$tmp/etc/modprobe.d") {
102                         doit("install","-d","$tmp/etc/modprobe.d");
103                 }
104                 doit("install","-m","0644",$modprobe_file,"$tmp/etc/modprobe.d/".pkgfilename($package));
105         }
106         
107         if (! $dh{NOSCRIPTS}) {
108                 if ($modutils_file) {
109                         autoscript($package,"postinst","postinst-update-modules");
110                         autoscript($package,"postrm","postrm-update-modules");
111                 }
112
113                 foreach my $kvers (find_kernel_modules("$tmp/lib/modules")) {
114                         autoscript($package,"postinst","postinst-modules","s/#KVERS#/$kvers/g");
115                         autoscript($package,"postrm","postrm-modules","s/#KVERS#/$kvers/g");
116                 }
117         }
118 }
119
120 =head1 SEE ALSO
121
122 L<debhelper(7)>
123
124 This program is a part of debhelper.
125
126 =head1 AUTHOR
127
128 Joey Hess <joeyh@debian.org>
129
130 =cut