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