]> git.donarmstrong.com Git - debhelper.git/blob - dh_installmodules
conffile moving idiocy
[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.modprobe will be installed in
24 etc/modprobe.d/package.conf in the package build directory, to be used by
25 module-init-tools's version of modprobe.
26
27 Kernel modules are searched for in the package build directory and if
28 found, postinst and postrm commands are automatically generated to 
29 run depmod and register the modules when the package is installed. 
30 These commands are inserted into the maintainer scripts by dh_installdeb.
31 See L<dh_installdeb(1)> for an explanation of how this works.
32
33 Previous versions of dh_installmodules also supported 
34 files named debian/package.modules, which were installed into 
35 etc/modutils/package in the package build directory. This was for use by
36 modutils, which is no longer in Debian. dh_installmodules will warn about
37 such files now.
38
39 =head1 OPTIONS
40
41 =over 4
42
43 =item B<-n>, B<--noscripts>
44
45 Do not modify postinst/postrm scripts.
46
47 =item B<--name=>I<name>
48
49 When this parameter is used, dh_installmodules looks for and
50 installs files named debian/package.name.modules and
51 debian/package.name.modprobe instead of the usual
52 debian/package.modules and debian/package.modprobe
53
54 =back
55
56 =head1 NOTES
57
58 Note that this command is not idempotent. L<dh_prep(1)> should be called
59 between invocations of this command. Otherwise, it may cause multiple
60 instances of the same text to be added to maintainer scripts.
61
62 =cut
63
64 init();
65
66 # Looks for kernel modules in the passed directory. If any are found,
67 # returns the kernel version (or versions) that the modules seem to be for.
68 sub find_kernel_modules {
69         my $searchdir=shift;
70         my %versions;
71
72         return unless -d $searchdir;
73         find(sub {
74                 if (/\.k?o$/) {
75                         my ($kvers)=$File::Find::dir=~m!lib/modules/([^/]+)/!;
76                         if (! defined $kvers || ! length $kvers) {
77                                 warning("Cannot determine kernel version for module $File::Find::name");
78                         }
79                         else {
80                                 $versions{$kvers}=1;
81                         }
82                 }
83         }, $searchdir);
84
85         return keys %versions;
86 }
87
88 foreach my $package (@{$dh{DOPACKAGES}}) {
89         my $tmp=tmpdir($package);
90         my $modutils_file=pkgfile($package,"modules");
91         my $modprobe_file=pkgfile($package,"modprobe");
92
93         if (! -e $tmp) {
94                 doit("install","-d",$tmp);
95         }
96
97         if ($modutils_file) {
98                 warning("ignoring $modutils_file, since modutils is no longer in Debian");
99         }
100
101         if ($modprobe_file) {
102                 if (! -e "$tmp/etc/modprobe.d") {
103                         doit("install","-d","$tmp/etc/modprobe.d");
104                 }
105                 my $old="/etc/modprobe.d/".pkgfilename($package);
106                 my $new=$old.".conf";
107                 doit("install","-m","0644",$modprobe_file,"$tmp/$new");
108                 autoscript($package,"preinst","preinst-moveconffile","s!#OLD#!$old!g;s!#PACKAGE#!$package!g");
109                 autoscript($package,"postinst","postinst-moveconffile","s!#OLD#!$old!g;s!#NEW#!$new!g");
110         }
111         
112         if (! $dh{NOSCRIPTS}) {
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