]> git.donarmstrong.com Git - debhelper.git/blob - dh_fixperms
r496: * Man page cleanups, Closes: #119335
[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. Finally,
27 it removes the setuid and setgid bits from all files in the package.
28
29 =head1 OPTIONS
30
31 =over 4
32
33 =item B<-X>I<item>, B<--exclude> I<item>
34
35 Exclude files that contain "item" anywhere in their filename from having
36 their permissions changed. You may use this option multiple times to build
37 up a list of things to exclude.
38
39 =back
40
41 =cut
42
43 init();
44
45 foreach my $package (@{$dh{DOPACKAGES}}) {
46         my $tmp=tmpdir($package);
47
48         my $find_options='';
49         if (defined($dh{EXCLUDE_FIND}) && $dh{EXCLUDE_FIND} ne '') {
50                 $find_options="! \\( $dh{EXCLUDE_FIND} \\)";
51         }
52
53         # General permissions fixing.
54         complex_doit("find $tmp $find_options -print0",
55                 "2>/dev/null | xargs -0r chown --no-dereference 0.0");
56         complex_doit("find $tmp ! -type l $find_options -print0",
57                 "2>/dev/null | xargs -0r chmod go=rX,u+rw,a-s");
58                 
59         # Fix up premissions in usr/share/doc, setting everything to not
60         # executable by default, but leave examples directories alone.
61         complex_doit("find $tmp/usr/share/doc $tmp/usr/doc -type f $find_options ! -regex '.*/examples/.*' -print0",
62                 "2>/dev/null | xargs -0r chmod 644");
63         complex_doit("find $tmp/usr/share/doc $tmp/usr/doc -type d $find_options -print0",
64                 "2>/dev/null | xargs -0r chmod 755");
65
66         # Executable man pages are a bad thing..
67         complex_doit("find $tmp/usr/share/man $tmp/usr/man/ $tmp/usr/X11*/man/ -type f",
68                 "$find_options -print0 2>/dev/null | xargs -0r chmod 644");
69
70         # ..and so are executable shared and static libraries 
71         # (and .la files from libtool)
72         complex_doit("find $tmp -perm -5 -type f",
73                 "\\( -name '*.so*' -or -name '*.la' -or -name '*.a' \\) $find_options -print0",
74                 "2>/dev/null | xargs -0r chmod a-X");
75 }
76
77 =head1 SEE ALSO
78
79 L<debhelper(1)>
80
81 This program is a part of debhelper.
82
83 =head1 AUTHOR
84
85 Joey Hess <joeyh@debian.org>
86
87 =cut