426e7833 |
1 | #!/usr/bin/perl -w |
2 | |
3 | =head1 NAME |
4 | |
5 | dh_perms - set some special permissions after dh_fixperms |
6 | |
7 | =cut |
8 | |
9 | use strict; |
10 | use Debian::Debhelper::Dh_Lib; |
11 | |
12 | =head1 SYNOPSIS |
13 | |
14 | B<dh_perms> [S<I<debhelper options>>] |
15 | |
16 | =head1 DESCRIPTION |
17 | |
18 | dh_perms is a debhelper program that is responsible for setting the |
19 | permissions of files and directories according to the information in |
20 | debian/permissions. It is intended to be run after dh_fixperms. |
21 | |
22 | The file debian/permissions is a tab seperated file where the first column |
23 | contains a filename, the second one the permissions in octal format, the |
24 | third one the owner and the fourth one the group. A dash in columns 2 to 4 |
25 | means that this information will not be modified. |
26 | |
27 | =head1 OPTIONS |
28 | |
29 | =over 4 |
30 | |
31 | None except the standard debhelper options. |
32 | |
33 | =back |
34 | |
35 | =cut |
36 | |
37 | init(); |
38 | |
39 | my %perms; |
40 | my %owners; |
41 | my %groups; |
42 | |
43 | # TODO: There should be a way to change this by command-line |
44 | my $permfile = "debian/permissions"; |
45 | |
46 | open PERMFILE, $permfile or exit 0; #print "could not open permfile\n"; |
47 | while (my $curline = <PERMFILE>) |
48 | { |
49 | #NOTE: Broken lines are not always detected. (e.g. not defining anything valid) |
50 | |
51 | # remove lineend |
52 | chomp($curline); |
53 | # skip comments/empty lines |
54 | next if $curline =~ /^#/ || $curline !~ /\S/; |
55 | (my $filename, my $octmode, my $owner, my $group) = split (/\s+/, $curline); |
56 | |
57 | die qq{$0: could not accept "$curline": wrong octmode $octmode\n} unless $octmode =~ /^[0-7]{3,4}$/; |
58 | $perms{$filename} = $octmode unless $octmode eq "-" or not defined $octmode; |
59 | |
60 | $owner = getpwnam($owner) if defined getpwnam($owner); |
61 | $owners{$filename} = $owner unless $owner eq "-" or not defined $owner; |
62 | |
63 | $group = getgrnam($group) if defined getpwnam($group); |
64 | $groups{$filename} = $group unless $group eq "-" or not defined $group; |
65 | |
66 | } |
67 | close PERMFILE; |
68 | |
69 | |
70 | foreach my $package (@{$dh{DOPACKAGES}}) { |
71 | my $tmp=tmpdir($package); |
72 | foreach my $file (keys %owners) |
73 | { |
74 | next unless -e $tmp.$file; |
75 | chown $owners{$file}, -1, $tmp.$file or die "failed to chown $file"; |
76 | verbose_print "chowned file $file to $owners{$file}"; |
77 | } |
78 | foreach my $file (keys %groups) |
79 | { |
80 | next unless -e $tmp.$file; |
81 | chown -1, $groups{$file}, $tmp.$file or die "failed to chgrp $file"; |
82 | verbose_print "chgrped file $file to $groups{$file}"; |
83 | } |
84 | foreach my $file (keys %perms) |
85 | { |
86 | next unless -e $tmp.$file; |
87 | my $nummod = oct("0".$perms{$file}); |
88 | chmod $nummod, $tmp.$file or die "failed to chmod $file"; |
89 | verbose_print "chmoded file $file to ".sprintf("0%o", $nummod); |
90 | } |
91 | |
92 | } |
93 | |
94 | =head1 SEE ALSO |
95 | |
96 | L<debhelper(7)> |
97 | |
98 | This program is not yet part of debhelper. |
99 | |
100 | =head1 AUTHOR |
101 | |
102 | Willi Mann <willi@wm1.at> |
103 | |
104 | =cut |
105 | |