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. See
28 L<dh_installdeb(1)> for an explanation of Debhelper maintainer script
31 If the directories found in the build tree have unusual owners, groups, or
32 permissions, then those values will be preserved in the directories made by
33 the postinst script. However, as a special exception, if a directory is owned
34 by root.root, it will be treated as if it is owned by root.staff and is mode
35 2775. This is useful, since that is the group and mode policy recommends for
36 directories in /usr/local.
42 =item B<-n>, B<--noscripts>
44 Do not modify F<postinst>/F<prerm> scripts.
50 Note that this command is not idempotent. "dh_clean -k" should be called
51 between invocations of this command. Otherwise, it may cause multiple
52 instances of the same text to be added to maintainer scripts.
56 Debian policy, version 2.2
62 foreach my $package (@{$dh{DOPACKAGES}}) {
63 my $tmp = tmpdir($package);
65 if (-d "$tmp/usr/local") {
66 my (@dirs, @justdirs);
70 my $fn = $File::Find::name;
73 my $user = getpwuid $stat->uid;
74 my $group = getgrgid $stat->gid;
75 my $mode = sprintf "%04lo", ($stat->mode & 07777);
77 if ($stat->uid == 0 && $stat->gid == 0) {
83 return if $fn eq '/usr/local';
85 # @dirs is in parents-first order for dir creation...
86 unshift @dirs, "$fn $mode $user $group";
87 # ...whereas @justdirs is depth-first for removal.
92 warning("$fn is not a directory");
94 }}, "$tmp/usr/local");
95 doit("rmdir $tmp/usr/local");
97 my $bs = "\\"; # A single plain backslash
98 my $ebs = $bs x 2; # Escape the backslash from the shell
99 # This constructs the body of a 'sed' c\ expression which
100 # is parsed by the shell in double-quotes
101 my $dirs = join("$ebs\n", @dirs);
102 pop @justdirs; # don't remove directories directly in /usr/local
103 my $justdirs = join("$ebs\n", @justdirs);
104 if (! $dh{NOSCRIPTS}) {
105 autoscript($package,"postinst", "postinst-usrlocal",
106 "/#DIRS#/ c${ebs}\n${dirs}");
107 autoscript($package,"prerm", "prerm-usrlocal",
108 "/#JUSTDIRS#/ c${ebs}\n${justdirs}") if length $justdirs;
117 This program is a part of debhelper.
121 Andrew Stribblehill <ads@debian.org>