]> git.donarmstrong.com Git - debhelper.git/blob - dh_fixperms
r1695: * dh_gconf: gconf schemas moved to /usr/share/gconf/schemas. Relocate
[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 that have it set. It makes
27 all files in bin/ directories, /usr/games/ and etc/init.d executable (v4
28 only). Finally, it removes the setuid and setgid bits from all files in the
29 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",
80                 "-name '*.h' $find_options -print0",
81                 "2>/dev/null | xargs -0r chmod 644");
82         
83         # .. and perl modules.
84         complex_doit("find $tmp/usr/lib/perl5 $tmp/usr/share/perl5 -type f",
85                 "-perm -5 -name '*.pm' $find_options -print0",
86                 "2>/dev/null | xargs -0r chmod a-X");
87         
88         # v4 only
89         if (! compat(3)) {
90                 # Programs in the bin and init.d dirs should be executable..
91                 for my $dir (qw{usr/bin bin usr/sbin sbin usr/games etc/init.d}) {
92                         if (-d "$tmp/$dir") {
93                                 complex_doit("find $tmp/$dir -type f $find_options -print0 2>/dev/null",
94                                         "| xargs -0r chmod +x");
95                         }
96                 }
97         }
98         
99         # ADA ali files should be mode 444 to avoid recompilation
100         if (-d "$tmp/usr/lib/ada") {
101                 complex_doit("find $tmp/usr/lib/ada -type f",
102                         "-name '*.ali' $find_options -print0",
103                         "2>/dev/null | xargs -0r chmod uga-w");
104         }
105 }
106
107 =head1 SEE ALSO
108
109 L<debhelper(7)>
110
111 This program is a part of debhelper.
112
113 =head1 AUTHOR
114
115 Joey Hess <joeyh@debian.org>
116
117 =cut