~ikhatib/+junk/dkms-raring

« back to all changes in this revision

Viewing changes to debian/scripts/dh_dkms

  • Committer: Ismail Khatib
  • Date: 2013-06-11 23:42:54 UTC
  • Revision ID: ikhatib@gmail.com-20130611234254-ljmxk7sve5olw6eq
Initial import, version 2.2.0.3-1.1ubuntu2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/perl -w
 
2
 
 
3
=head1 NAME
 
4
 
 
5
dh_dkms - correctly handle DKMS usage by a kernel module package
 
6
 
 
7
=cut
 
8
 
 
9
use strict;
 
10
use Debian::Debhelper::Dh_Lib;
 
11
 
 
12
=head1 SYNOPSIS
 
13
 
 
14
B<dh_dkms> [S<I<debhelper options>>] [S<B<-l>>] [S<B<-V>[I<version>]>] [S<B<--> I<file>>]
 
15
 
 
16
=head1 DESCRIPTION
 
17
 
 
18
dh_dkms is a debhelper program that is responsible for correctly setting
 
19
postinst, postrm and dependencies in kernel module packages using DKMS.
 
20
 
 
21
If a file named debian/package.dkms exists, then different actions are
 
22
performed, depending on its contents.
 
23
 
 
24
=head1 FILES
 
25
 
 
26
=over 4
 
27
 
 
28
=item debian/I<package>.dkms
 
29
 
 
30
=item debian/dkms
 
31
 
 
32
It can be a proper configuration file, and in this case it would be installed
 
33
in the proper directory as dkms.conf.
 
34
 
 
35
It can also point to another file (this should be used when the configuration
 
36
is provided by upstream), and in this case that file will be installed as dkms.conf
 
37
in the propery directory.
 
38
 
 
39
This file can only miss if a filename is provided when calling dh_dkms.
 
40
 
 
41
=back
 
42
 
 
43
=head1 OPTIONS
 
44
 
 
45
=over 4
 
46
 
 
47
=item B<-l>, B<--legacy>
 
48
 
 
49
Add code to also support DKMS versions < 2.1.0.0.
 
50
 
 
51
=item B<-V>, B<-V> I<version>
 
52
 
 
53
If C<PACKAGE_VERSION> in F<dkms.conf> is set to C<#MODULE_VERSION#>, set it to
 
54
the given I<version> or, if none is given, default to the upstream version of
 
55
the current package. Otherwise, leave the value specified in F<dkms.conf>.
 
56
 
 
57
=item B<--> I<file>
 
58
 
 
59
Don't look for debian/I<package>.dkms or debian/dkms, but install I<file> as dkms.conf.
 
60
 
 
61
=back
 
62
 
 
63
=head1 NOTES
 
64
 
 
65
Note that this command is not idempotent. L<dh_prep(1)> should be called
 
66
between invocations of this command. Otherwise, it may cause multiple
 
67
instances of the same text to be added to maintainer scripts.
 
68
 
 
69
=cut
 
70
 
 
71
init(options => {
 
72
        "l|legacy" => \$dh{LEGACY_DKMS},
 
73
});
 
74
 
 
75
foreach my $package (@{$dh{DOPACKAGES}}) {
 
76
        #next if is_udeb($package);
 
77
 
 
78
        my $tmp = tmpdir($package);
 
79
        my $dkms_dir = "/usr/lib/dkms/";
 
80
        my $dkms_conf = pkgfile($package, "dkms");
 
81
        my $is_snippet = 0;
 
82
        my @other_conf;
 
83
        my $name;
 
84
        my $package_name;
 
85
        my $package_version;
 
86
 
 
87
        if ($dkms_conf) {
 
88
                # let's see if it's a proper snippet
 
89
                open(IN, "< $dkms_conf");
 
90
                while (my $l = <IN>) {
 
91
                        $l =~ /PACKAGE_NAME=(["'])(.*)\1/ && ($is_snippet = 1);
 
92
                }
 
93
                close(IN);
 
94
 
 
95
                if ($is_snippet) {
 
96
                        $name = $dkms_conf;
 
97
                }
 
98
                else {
 
99
                        @other_conf = filearray($dkms_conf);
 
100
                        if ($#other_conf > 1) {
 
101
                                error "cannot list more than one file in $dkms_conf!";
 
102
                        }
 
103
                        else {
 
104
                                $name = $other_conf[0];
 
105
                        }
 
106
                }
 
107
        }
 
108
        elsif ($#ARGV == 0) {
 
109
                $name = $ARGV[0];
 
110
        }
 
111
        else {
 
112
                next;
 
113
        }
 
114
        verbose_print "installing $name as dkms.conf";
 
115
 
 
116
        # now, parse our configuration file
 
117
        open(IN, "< $name");
 
118
        while (my $l = <IN>) {
 
119
                $l =~ /PACKAGE_NAME=(["'])(.*)\1/ && ($is_snippet = 1 && $package_name = $2);
 
120
                $l =~ /PACKAGE_VERSION=(["'])(.*)\1/ && ($package_version = $2);
 
121
        }
 
122
        close(IN);
 
123
 
 
124
        #$ENV{DH_AUTOSCRIPTDIR} = "debian/scripts/";
 
125
        if ($dh{LEGACY_DKMS}) {
 
126
                doit("install", "-p", "-D", "-m755", "$dkms_dir/common.postinst", "$tmp/usr/share/$package/postinst");
 
127
                addsubstvar($package, "misc:Depends", "dkms");
 
128
        }
 
129
        else {
 
130
                addsubstvar($package, "misc:Depends", "dkms", ">= 2.1.0.0");
 
131
        }
 
132
 
 
133
        if ($dh{V_FLAG_SET}) {
 
134
                $package_version = $dh{V_FLAG};
 
135
                if ($package_version eq "") {
 
136
                        # Call isnative because it sets $dh{VERSION}
 
137
                        # as a side effect.
 
138
                        isnative($package);
 
139
                        $package_version = $dh{VERSION};
 
140
                        # Remove the Debian revision
 
141
                        $package_version =~ s/-[^-]+$//;
 
142
                }
 
143
 
 
144
                my $old_name = $name;
 
145
                $name = "debian/".pkgext($package)."dkms.debhelper";
 
146
                doit("cp", "-a", $old_name, $name);
 
147
                doit("sed", "-i", "s/#MODULE_VERSION#/$package_version/g", $name);
 
148
        }
 
149
 
 
150
        autoscript($package, "prerm", "prerm-dkms",
 
151
            "s/#MODULE_NAME#/$package_name/;s/#MODULE_VERSION#/$package_version/");
 
152
        autoscript($package, "postinst", "postinst-dkms",
 
153
            "s/#MODULE_NAME#/$package_name/;s/#MODULE_VERSION#/$package_version/");
 
154
        doit("install", "-p", "-D", "-m644", "$name", "$tmp/usr/src/$package_name-$package_version/dkms.conf");
 
155
}
 
156
 
 
157
=head1 SEE ALSO
 
158
 
 
159
L<debhelper(1)>
 
160
 
 
161
This program is part of the Debian DKMS package.
 
162
 
 
163
L<dkms(8)>
 
164
 
 
165
=head1 AUTHOR
 
166
 
 
167
David Paleino <dapal@debian.org>
 
168
 
 
169
=cut