5 dh_usrlocal - migrate usr/local directories to maintainer scripts
11 use Debian::Debhelper::Dh_Lib;
17 B<dh_usrlocal> [S<I<debhelper options>>] [B<-n>]
21 dh_usrlocal is a debhelper program that can be used for building packages
22 that will provide a subdirectory in /usr/local when installed.
24 It finds subdirectories of usr/local in the package build directory, and
25 removes them, replacing them with maintainer script snippets (unless B<-n>
26 is used) to create the directories at install time, and remove them when
27 the package is removed, in a manner compliant with Debian policy. These
28 snippets are inserted into the maintainer scripts by dh_installdeb. See
29 L<dh_installdeb(1)> for an explanation of Debhelper maintainer script
32 If the directories found in the build tree have unusual owners, groups, or
33 permissions, then those values will be preserved in the directories made by
34 the postinst script. However, as a special exception, if a directory is owned
35 by root.root, it will be treated as if it is owned by root.staff and is mode
36 2775. This is useful, since that is the group and mode policy recommends for
37 directories in /usr/local.
43 =item B<-n>, B<--noscripts>
45 Do not modify F<postinst>/F<prerm> scripts.
51 Note that this command is not idempotent. L<dh_prep(1)> should be called
52 between invocations of this command. Otherwise, it may cause multiple
53 instances of the same text to be added to maintainer scripts.
57 Debian policy, version 2.2
63 foreach my $package (@{$dh{DOPACKAGES}}) {
64 my $tmp = tmpdir($package);
66 if (-d "$tmp/usr/local") {
67 my (@dirs, @justdirs);
71 my $fn = $File::Find::name;
74 my $user = getpwuid $stat->uid;
75 my $group = getgrgid $stat->gid;
76 my $mode = sprintf "%04lo", ($stat->mode & 07777);
78 if ($stat->uid == 0 && $stat->gid == 0) {
84 return if $fn eq '/usr/local';
86 # @dirs is in parents-first order for dir creation...
87 unshift @dirs, "$fn $mode $user $group";
88 # ...whereas @justdirs is depth-first for removal.
93 warning("$fn is not a directory");
95 }}, "$tmp/usr/local");
96 doit("rmdir $tmp/usr/local");
98 my $bs = "\\"; # A single plain backslash
99 my $ebs = $bs x 2; # Escape the backslash from the shell
100 # This constructs the body of a 'sed' c\ expression which
101 # is parsed by the shell in double-quotes
102 my $dirs = join("$ebs\n", @dirs);
103 pop @justdirs; # don't remove directories directly in /usr/local
104 my $justdirs = join("$ebs\n", @justdirs);
105 if (! $dh{NOSCRIPTS}) {
106 autoscript($package,"postinst", "postinst-usrlocal",
107 "/#DIRS#/ c${ebs}\n${dirs}");
108 autoscript($package,"prerm", "prerm-usrlocal",
109 "/#JUSTDIRS#/ c${ebs}\n${justdirs}") if length $justdirs;
118 This program is a part of debhelper.
122 Andrew Stribblehill <ads@debian.org>