]> git.donarmstrong.com Git - debhelper.git/blob - dh_fixperms
r574: * wiggy didn't take my hint about making update-modules send warnings to
[debhelper.git] / dh_fixperms
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_fixperms - fix permissions of files in package build directories
6
7 =cut
8
9 use strict;
10 use Debian::Debhelper::Dh_Lib;
11
12 =head1 SYNOPSIS
13
14 B<dh_fixperms> [S<I<debhelper options>>] [B<-X>I<item>]
15
16 =head1 DESCRIPTION
17
18 dh_fixperms is a debhelper program that is responsible for setting the
19 permissions of files and directories in package build directories to a
20 sane state -- a state that complies with Debian policy.
21
22 dh_fixperms makes all files in usr/share/doc in the package build directory
23 (excluding files in the examples/ directory) be mode 644. It also changes
24 the permissions of all man pages to mode 644. It makes all files be owned by
25 root, and it removes group and other write permission from all files.
26 It removes execute permissions from any libraries that have it set. It makes
27 all files in bin/ directories and etc/init.d executable (v4 only). Finally,
28 it removes the setuid and setgid bits from all files in the package.
29
30 =head1 OPTIONS
31
32 =over 4
33
34 =item B<-X>I<item>, B<--exclude> I<item>
35
36 Exclude files that contain "item" anywhere in their filename from having
37 their permissions changed. You may use this option multiple times to build
38 up a list of things to exclude.
39
40 =back
41
42 =cut
43
44 init();
45
46 foreach my $package (@{$dh{DOPACKAGES}}) {
47         my $tmp=tmpdir($package);
48
49         my $find_options='';
50         if (defined($dh{EXCLUDE_FIND}) && $dh{EXCLUDE_FIND} ne '') {
51                 $find_options="! \\( $dh{EXCLUDE_FIND} \\)";
52         }
53
54         # General permissions fixing.
55         complex_doit("find $tmp $find_options -print0",
56                 "2>/dev/null | xargs -0r chown --no-dereference 0.0");
57         complex_doit("find $tmp ! -type l $find_options -print0",
58                 "2>/dev/null | xargs -0r chmod go=rX,u+rw,a-s");
59                 
60         # Fix up premissions in usr/share/doc, setting everything to not
61         # executable by default, but leave examples directories alone.
62         complex_doit("find $tmp/usr/share/doc -type f $find_options ! -regex '$tmp/usr/share/doc/[^/]*/examples/.*' -print0 2>/dev/null",
63                 "| xargs -0r chmod 644");
64         complex_doit("find $tmp/usr/share/doc -type d $find_options -print0 2>/dev/null",
65                 "| xargs -0r chmod 755");
66
67         # Executable man pages are a bad thing..
68         complex_doit("find $tmp/usr/share/man $tmp/usr/man/ $tmp/usr/X11*/man/ -type f",
69                 "$find_options -print0 2>/dev/null | xargs -0r chmod 644");
70
71         # ..and so are executable shared and static libraries 
72         # (and .la files from libtool) ..
73         complex_doit("find $tmp -perm -5 -type f",
74                 "\\( -name '*.so*' -or -name '*.la' -or -name '*.a' \\) $find_options -print0",
75                 "2>/dev/null | xargs -0r chmod 644");
76         
77         # .. and perl modules.
78         complex_doit("find $tmp/usr/lib/perl5 $tmp/usr/share/perl5 -type f",
79                 "-perm -5 -name '*.pm' $find_options -print0",
80                 "2>/dev/null | xargs -0r chmod a-X");
81         
82         # v4 only
83         if (! compat(3)) {
84                 # Programs in the bin and init.d dirs should be executable..
85                 for my $dir (qw{usr/bin bin usr/sbin sbin etc/init.d}) {
86                         if (-d "$tmp/$dir") {
87                                 complex_doit("find $tmp/$dir -type f $find_options -print0 2>/dev/null",
88                                         "| xargs -0r chmod +x");
89                         }
90                 }
91         }
92         
93 }
94
95 =head1 SEE ALSO
96
97 L<debhelper(1)>
98
99 This program is a part of debhelper.
100
101 =head1 AUTHOR
102
103 Joey Hess <joeyh@debian.org>
104
105 =cut