5 dh_fixperms - fix permissions of files in package build directories
10 use Debian::Debhelper::Dh_Lib;
14 B<dh_fixperms> [S<I<debhelper options>>] [B<-X>I<item>]
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.
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.
35 =item B<-X>I<item>, B<--exclude> I<item>
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.
47 foreach my $package (@{$dh{DOPACKAGES}}) {
48 my $tmp=tmpdir($package);
51 if (defined($dh{EXCLUDE_FIND}) && $dh{EXCLUDE_FIND} ne '') {
52 $find_options="! \\( $dh{EXCLUDE_FIND} \\)";
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");
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");
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");
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");
78 # ..and header files ..
79 complex_doit("find $tmp/usr/include -type f $find_options -print0",
80 "2>/dev/null | xargs -0r chmod 644");
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");
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");
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}) {
96 complex_doit("find $tmp/$dir -type f $find_options -print0 2>/dev/null",
97 "| xargs -0r chmod a+x");
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");
114 This program is a part of debhelper.
118 Joey Hess <joeyh@debian.org>