]> git.donarmstrong.com Git - debhelper.git/blob - dh_fixperms
Merge branch 'master' of ssh://git.debian.org/git/debhelper/debhelper
[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
25 by root, and it removes group and other write permission from all files. It
26 removes execute permissions from any libraries, headers, perl modules, or
27 desktop files that have it set. It makes all files in bin/ directories,
28 /usr/games/ and etc/init.d executable (since v4). Finally, it removes the
29 setuid and setgid bits from all files in the package.
30
31 =head1 OPTIONS
32
33 =over 4
34
35 =item B<-X>I<item>, B<--exclude> I<item>
36
37 Exclude files that contain "item" anywhere in their filename from having
38 their permissions changed. You may use this option multiple times to build
39 up a list of things to exclude.
40
41 =back
42
43 =cut
44
45 init();
46
47 foreach my $package (@{$dh{DOPACKAGES}}) {
48         my $tmp=tmpdir($package);
49
50         my $find_options='';
51         if (defined($dh{EXCLUDE_FIND}) && $dh{EXCLUDE_FIND} ne '') {
52                 $find_options="! \\( $dh{EXCLUDE_FIND} \\)";
53         }
54
55         # General permissions fixing.
56         complex_doit("find $tmp $find_options -print0",
57                 "2>/dev/null | xargs -0r chown --no-dereference 0:0");
58         complex_doit("find $tmp ! -type l $find_options -print0",
59                 "2>/dev/null | xargs -0r chmod go=rX,u+rw,a-s");
60         
61         # Fix up premissions in usr/share/doc, setting everything to not
62         # executable by default, but leave examples directories alone.
63         complex_doit("find $tmp/usr/share/doc -type f $find_options ! -regex '$tmp/usr/share/doc/[^/]*/examples/.*' -print0 2>/dev/null",
64                 "| xargs -0r chmod 644");
65         complex_doit("find $tmp/usr/share/doc -type d $find_options -print0 2>/dev/null",
66                 "| xargs -0r chmod 755");
67
68         # Executable man pages are a bad thing..
69         complex_doit("find $tmp/usr/share/man $tmp/usr/man/ $tmp/usr/X11*/man/ -type f",
70                 "$find_options -print0 2>/dev/null | xargs -0r chmod 644");
71
72         # ..and so are executable shared and static libraries 
73         # (and .la files from libtool) ..
74         complex_doit("find $tmp -perm -5 -type f",
75                 "\\( -name '*.so*' -or -name '*.la' -or -name '*.a' \\) $find_options -print0",
76                 "2>/dev/null | xargs -0r chmod 644");
77         
78         # ..and header files ..
79         complex_doit("find $tmp/usr/include -type f $find_options -print0",
80                 "2>/dev/null | xargs -0r chmod 644");
81         
82         # ..and desktop files ..
83         complex_doit("find $tmp/usr/share/applications -type f $find_options -print0",
84                 "2>/dev/null | xargs -0r chmod 644");
85         
86         # .. and perl modules.
87         complex_doit("find $tmp/usr/lib/perl5 $tmp/usr/share/perl5 -type f",
88                 "-perm -5 -name '*.pm' $find_options -print0",
89                 "2>/dev/null | xargs -0r chmod a-X");
90         
91         # v4 and up
92         if (! compat(3)) {
93                 # Programs in the bin and init.d dirs should be executable..
94                 for my $dir (qw{usr/bin bin usr/sbin sbin usr/games etc/init.d}) {
95                         if (-d "$tmp/$dir") {
96                                 complex_doit("find $tmp/$dir -type f $find_options -print0 2>/dev/null",
97                                         "| xargs -0r chmod a+x");
98                         }
99                 }
100         }
101         
102         # ADA ali files should be mode 444 to avoid recompilation
103         if (-d "$tmp/usr/lib/ada") {
104                 complex_doit("find $tmp/usr/lib/ada -type f",
105                         "-name '*.ali' $find_options -print0",
106                         "2>/dev/null | xargs -0r chmod uga-w");
107         }
108
109         # Lintian overrides should never be executable, too.
110         if (-d "$tmp/usr/share/lintian") {
111                 complex_doit("find $tmp/usr/share/lintian/overrides",
112                         "-type f $find_options -print0",
113                         "2>/dev/null | xargs -0r chmod 644");
114         }
115 }
116
117 =head1 SEE ALSO
118
119 L<debhelper(7)>
120
121 This program is a part of debhelper.
122
123 =head1 AUTHOR
124
125 Joey Hess <joeyh@debian.org>
126
127 =cut