1 | #!/usr/bin/perl -w |
---|
2 | # Copyright © 2007-2008 Anders Kaseorg <andersk@mit.edu> and |
---|
3 | # Tim Abbott <tabbott@mit.edu> |
---|
4 | # Copyright © 2011-2012 Geoffrey Thomas <geofft@mit.edu> |
---|
5 | # |
---|
6 | # This program is free software; you can redistribute it and/or |
---|
7 | # modify it under the terms of the GNU General Public License as |
---|
8 | # published by the Free Software Foundation; either version 2, or (at |
---|
9 | # your option) any later version. |
---|
10 | # |
---|
11 | # This program is distributed in the hope that it will be useful, but |
---|
12 | # WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
14 | # General Public License for more details. |
---|
15 | # |
---|
16 | # You should have received a copy of the GNU General Public License |
---|
17 | # along with this program; if not, write to the Free Software |
---|
18 | # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA |
---|
19 | # 02111-1307 USA. |
---|
20 | |
---|
21 | |
---|
22 | =head1 NAME |
---|
23 | |
---|
24 | dh_configpackage - add maintainer script rules to displace, hide, or transform files |
---|
25 | |
---|
26 | =cut |
---|
27 | |
---|
28 | use strict; |
---|
29 | use Debian::Debhelper::Dh_Lib; |
---|
30 | use Debian::Debhelper::config_package; |
---|
31 | |
---|
32 | =head1 SYNOPSIS |
---|
33 | |
---|
34 | B<dh_configpackage> [S<I<debhelper options>>] [B<-n>] |
---|
35 | |
---|
36 | =head1 DESCRIPTION |
---|
37 | |
---|
38 | B<dh_configpackage> needs more docs. |
---|
39 | |
---|
40 | =head1 OPTIONS |
---|
41 | |
---|
42 | =over 4 |
---|
43 | |
---|
44 | =item B<-n>, B<--noscripts> |
---|
45 | |
---|
46 | Do not modify maintainer scripts. |
---|
47 | |
---|
48 | =back |
---|
49 | |
---|
50 | =cut |
---|
51 | |
---|
52 | init(); |
---|
53 | |
---|
54 | # We default the displace extension to a period followed by the first |
---|
55 | # word of the package name, on the assumption that it is probably the |
---|
56 | # site name (e.g., "debathena-kerberos-config" displaces to |
---|
57 | # ".debathena"). You can set this extension explicitly in |
---|
58 | # debian/$package.displace-extension or debian/displace-extension. |
---|
59 | sub displace_extension { |
---|
60 | my $package = shift; |
---|
61 | my $file = pkgfile($package, "displace-extension"); |
---|
62 | if ($file) { |
---|
63 | open(my $fh, $file); |
---|
64 | my $ret = <$fh>; |
---|
65 | chomp $ret; |
---|
66 | close $fh; |
---|
67 | return $ret; |
---|
68 | } |
---|
69 | $package =~ s/-.*//; |
---|
70 | return ".$package"; |
---|
71 | } |
---|
72 | |
---|
73 | # Replace only the last instance of the displace extension in the |
---|
74 | # filename, to make it possible to displace /path/foo.divert to |
---|
75 | # foo.divert.divert-orig |
---|
76 | sub displace_files_replace_name { |
---|
77 | my ($package, $filename, $replacement) = @_; |
---|
78 | my $extension = displace_extension($package); |
---|
79 | $filename =~ s/(.*)\Q$extension\E/$1$replacement/; |
---|
80 | return $filename; |
---|
81 | } |
---|
82 | |
---|
83 | # Encode a full path into the path it should be diverted to if it's |
---|
84 | # hidden |
---|
85 | sub hide_files_name { |
---|
86 | my ($filename, $package) = @_; |
---|
87 | return "/usr/share/$package/" . encode($filename); |
---|
88 | } |
---|
89 | |
---|
90 | # At compatibility levels 6 and above, prerms take effect in the |
---|
91 | # opposite order from postinsts |
---|
92 | sub reverse_if_6 { |
---|
93 | if (compat(5)) { |
---|
94 | return @_; |
---|
95 | } else { |
---|
96 | return reverse @_; |
---|
97 | } |
---|
98 | } |
---|
99 | |
---|
100 | foreach my $package (@{$dh{DOPACKAGES}}) { |
---|
101 | my (@displacefiles, @hidefiles, @undisplacefiles, @unhidefiles); |
---|
102 | |
---|
103 | my $displacefile = pkgfile($package, "displace"); |
---|
104 | @displacefiles = filearray($displacefile) if $displacefile; |
---|
105 | my $hidefile = pkgfile($package, "hide"); |
---|
106 | @hidefiles = filearray($hidefile) if $hidefile; |
---|
107 | my $undisplacefile = pkgfile($package, "undisplace"); |
---|
108 | @undisplacefiles = filearray($undisplacefile) if $undisplacefile; |
---|
109 | my $unhidefile = pkgfile($package, "unhide"); |
---|
110 | @unhidefiles = filearray($unhidefile) if $unhidefile; |
---|
111 | |
---|
112 | my $tmp = tmpdir($package); |
---|
113 | my $extension = displace_extension($package); |
---|
114 | |
---|
115 | if (! $dh{ONLYSCRIPTS} && @hidefiles) { |
---|
116 | doit("install", "-d", "$tmp/usr/share/$package"); |
---|
117 | } |
---|
118 | |
---|
119 | # Add code to postinst to add/remove diversions as appropriate |
---|
120 | if (! $dh{NOSCRIPTS}) { |
---|
121 | if (@undisplacefiles || @unhidefiles || @displacefiles || @hidefiles) { |
---|
122 | my $postinst = escape_shell(join "\\n", ( |
---|
123 | 'if [ "$1" = "configure" ]; then', |
---|
124 | (map {" check_undisplace_unlink " . displace_files_replace_name($package, $_, " ")} @undisplacefiles), |
---|
125 | (map {" check_undisplace_unhide $_ " . hide_files_name($_, $package)} @unhidefiles), |
---|
126 | (map {" displace_link " . displace_files_replace_name($package, $_, " ")} @displacefiles), |
---|
127 | (map {" displace_hide $_ " . hide_files_name($_, $package)} @hidefiles), |
---|
128 | 'fi' |
---|
129 | )); |
---|
130 | autoscript($package, "postinst", "displace.sh.in", |
---|
131 | "s/#PACKAGE#/$package/g; s/#DEB_DISPLACE_EXTENSION#/$extension/g; \\\$a\"$postinst\""); |
---|
132 | } |
---|
133 | if (@displacefiles || @hidefiles) { |
---|
134 | my $prerm = escape_shell(join "\\n", ( |
---|
135 | 'if [ "$1" = "remove" ] || [ "$1" = "deconfigure" ]; then', |
---|
136 | (map {" undisplace_unlink " . displace_files_replace_name($package, $_, " ")} reverse_if_6 (@displacefiles)), |
---|
137 | (map {" undisplace_unhide $_ $package"} reverse_if_6 (@hidefiles)), |
---|
138 | 'fi' |
---|
139 | )); |
---|
140 | autoscript($package, "prerm", "displace.sh.in", |
---|
141 | "s/#PACKAGE#/$package/g; s/#DEB_DISPLACE_EXTENSION#/$extension/g; \\\$a\"$prerm\""); |
---|
142 | } |
---|
143 | } |
---|
144 | |
---|
145 | # Add an encoding of the names of the diverted files to the Provides: |
---|
146 | # and Conflicts: lists. This prevents two packages diverting the same |
---|
147 | # file from being installed simultaneously (it cannot work, and this |
---|
148 | # produces a much less ugly error). Requires in debian/control: |
---|
149 | # Provides: ${diverted-files} |
---|
150 | # Conflicts: ${diverted-files} |
---|
151 | foreach my $file (@displacefiles, @hidefiles) { |
---|
152 | my $encodedfile = encode(displace_files_replace_name($package, $file, "")); |
---|
153 | addsubstvar($package, "diverted-files", "diverts-$encodedfile"); |
---|
154 | } |
---|
155 | } |
---|
156 | |
---|
157 | =head1 SEE ALSO |
---|
158 | |
---|
159 | L<debhelper(7)> |
---|
160 | |
---|
161 | This program is a part of config-package-dev. |
---|
162 | |
---|
163 | =head1 AUTHOR |
---|
164 | |
---|
165 | config-package-dev was written by Anders Kaseorg <andersk@mit.edu> and |
---|
166 | Tim Abbott <tabbott@mit.edu>. The debhelper port is by Geoffrey Thomas |
---|
167 | <geofft@mit.edu>. |
---|
168 | |
---|
169 | =cut |
---|