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