]> git.donarmstrong.com Git - debhelper.git/blob - dh_installudev
dh_installudev: With --name, install debian/<package>.<name>.udev to rules.d/<priorit...
[debhelper.git] / dh_installudev
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_installudev - install udev rules files
6
7 =cut
8
9 use strict;
10 use Debian::Debhelper::Dh_Lib;
11 use File::Find;
12
13 =head1 SYNOPSIS
14
15 B<dh_installudev> [S<I<debhelper options>>] [B<-n>] [B<--name=>I<name>] [B<--priority=>I<priority>]
16
17 =head1 DESCRIPTION
18
19 dh_installudev is a debhelper program that is responsible for
20 installing udev rules files.
21
22 Code is added to the preinst and postinst to handle the upgrade from the
23 old udev rules file location.
24
25 =head1 FILES
26
27 =over 4
28
29 =item debian/I<package>.udev
30
31 Installed into lib/udev/rules.d/ in the package build directory.
32
33 =back
34
35 =head1 OPTIONS
36
37 =over 4
38
39 =item B<--name=>I<name>
40
41 When this parameter is used, dh_installudev looks for and
42 installs files named debian/I<package>.I<name>.udev instead of the usual
43 debian/I<package>.udev.
44
45 =item B<--priority=>I<priority>
46
47 Sets the priority string of the rules.d symlink. Default is 60.
48
49 =item B<-n>, B<--noscripts>
50
51 Do not modify postinst/postrm scripts.
52
53 =back
54
55 =head1 NOTES
56
57 Note that this command is not idempotent. L<dh_prep(1)> should be called
58 between invocations of this command. Otherwise, it may cause multiple
59 instances of the same text to be added to maintainer scripts.
60
61 =cut
62
63 init();
64
65 # The priority used to look like z60_;
66 # we need to calculate that old value to handle
67 # conffile moves correctly.
68 my $old_priority=$dh{PRIORITY};
69
70 # In case a caller still uses the `z` prefix, remove it.
71 if (defined $dh{PRIORITY}) {
72         $dh{PRIORITY}=~s/^z//;
73 }
74
75 if (! defined $dh{PRIORITY}) {
76         $dh{PRIORITY}="60";
77         $old_priority="z60";
78 }
79 if ($dh{PRIORITY}) {
80         $dh{PRIORITY}.="-";
81         $old_priority.="_";
82 }
83
84 foreach my $package (@{$dh{DOPACKAGES}}) {
85         my $tmp=tmpdir($package);
86         my $rules_file=pkgfile($package,"udev");
87         my $filename=basename($rules_file);
88         if ($filename eq 'udev') {
89                 $filename = "$package.udev";
90         }
91         $filename=~s/\.udev$/.rules/;
92         my $oldfilename=$filename;
93         if (defined $dh{NAME}) {
94                 $filename="$dh{NAME}.rules";
95         }
96
97         if ($rules_file) {
98                 if (! -e "$tmp/lib/udev/rules.d") {
99                         doit("install","-d","$tmp/lib/udev/rules.d");
100                 }
101                 my $rule="/lib/udev/rules.d/$dh{PRIORITY}$filename";
102                 doit("install","-m","0644",$rules_file,$tmp.$rule);
103                 if (! $dh{NOSCRIPTS}) {
104                         # Remove old rule from /etc, unless it's modified,
105                         # in which case we rename it to match the new
106                         # file in /lib, so it will override.
107                         my $old="/etc/udev/rules.d/$old_priority$oldfilename";
108                         $rule=~s/^\/lib/\/etc/;
109                         autoscript($package,"preinst","preinst-moveconffile","s!#OLD#!$old!g;s!#NEW#!$rule!g;s!#PACKAGE#!$package!g");
110                         autoscript($package,"postinst","postinst-moveconffile","s!#OLD#!$old!g;s!#NEW#!$rule!g");
111                 }
112         }
113 }
114
115 =head1 SEE ALSO
116
117 L<debhelper(7)>
118
119 This program is a part of debhelper.
120
121 =head1 AUTHOR
122
123 Joey Hess <joeyh@debian.org>
124
125 =cut