5 dh_perms - set some special permissions after dh_fixperms
10 use Debian
::Debhelper
::Dh_Lib
;
14 B<dh_perms> [S<I<debhelper options>>]
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.
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.
31 None except the standard debhelper options.
43 # TODO: There should be a way to change this by command-line
44 my $permfile = "debian/permissions";
46 open PERMFILE
, $permfile or exit 0; #print "could not open permfile\n";
47 while (my $curline = <PERMFILE
>)
49 #NOTE: Broken lines are not always detected. (e.g. not defining anything valid)
53 # skip comments/empty lines
54 next if $curline =~ /^#/ || $curline !~ /\S/;
55 (my $filename, my $octmode, my $owner, my $group) = split (/\s+/, $curline);
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;
60 $owner = getpwnam($owner) if defined getpwnam($owner);
61 $owners{$filename} = $owner unless $owner eq "-" or not defined $owner;
63 $group = getgrnam($group) if defined getpwnam($group);
64 $groups{$filename} = $group unless $group eq "-" or not defined $group;
70 foreach my $package (@
{$dh{DOPACKAGES
}}) {
71 my $tmp=tmpdir
($package);
72 foreach my $file (keys %owners)
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}";
78 foreach my $file (keys %groups)
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}";
84 foreach my $file (keys %perms)
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);
98 This program is not yet part of debhelper.
102 Willi Mann <willi@wm1.at>