]> git.donarmstrong.com Git - debhelper.git/blob - dh_debstd
r266: * FHS complience. Patch from Johnie Ingram <johnie@netgod.net>.
[debhelper.git] / dh_debstd
1 #!/usr/bin/perl -w
2 #
3 # Script to be called from debian/rules to setup all the debian specifc
4 # required files
5 # Christoph Lameter, <clameter@debian.org> October 10, 1996
6 #
7 # All the parameters are documentation files to be installed.
8 # (but doc files can also be listed in debian/docs)
9 #
10 # This has been gutted and extensively rewritten to function as a debhelper
11 # command by Joey Hess. And then completly rewritten in perl.
12
13 # Need to stay compatable with debstd, so force use of level 1.
14 $ENV{DH_COMAPT}=1;
15
16 # Pre-parse command line before we load Dh_lib, becuase we use a
17 # different style of arguments.
18 @argv=();
19 foreach (@ARGV) {
20         if ($_ eq '-p') {
21                 $ds{PERMS}=1;
22         }
23         elsif ($_ eq '-u') {
24                 $ds{UNDOC}=1;
25         }
26         elsif ($_ eq '-s') {
27                 $ds{SUMS}=1;
28         }
29         elsif ($_ eq '-m') {
30                 $ds{NOAUTOMAN}=1;
31         }
32         elsif ($_ eq '-c') {
33                 $ds{NOCOMPRESS}=1;
34         }
35         else {
36                 push @argv,$_;
37         }
38 }
39 @ARGV=@argv;
40
41 BEGIN { push @INC, "debian", "/usr/share/debhelper" }
42 use Dh_Lib;
43 init();
44
45 # Tolerate old style debstd invocations
46 if ($ARGV[0] && $dh{FIRSTPACKAGE} eq $ARGV[0]) {
47         shift;
48 }
49
50 # debinit handles the installation of an init.d script
51 sub debinit { my ($script, $filename, $package, @params)=@_;
52         @initparams=();
53         $norestart='';
54         open (IN,$filename) || warn("$filename: $!");
55         while (<IN>) {
56                 if (/^FLAGS=(.*)/) {
57                         push @initparams, $1;
58                 }
59                 if (/NO_RESTART_ON_UPGRADE/) {
60                         $norestart='--no-restart-on-upgrade';
61                 }
62         }
63         close IN;
64         $initparams='';
65         if (@initparams) {
66                 $initparams="--update-rcd-params='".join(" ",@initparams)."'";
67         }
68
69         doit("dh_installinit",$norestart,"-p$package",$initparams,"--init-script=$script",@params);
70 }
71
72 # Do package specific things for a package.
73 sub do_package { my ($package, $tmp, $prefix)=@_;
74         # Deal with scripts in etc directories
75         if (-d "$prefix/rc.boot") {
76                 warning("file $prefix/rc.boot was ignored.");
77         }
78
79         # etc files that could need some tweaking
80         foreach $f ('services','inittab','crontab','protocols','profile',
81                 'shells','rpc','syslog.conf','conf.modules','modules',
82                 'aliases','diversions','inetd.conf','X11/Xresources',
83                 'X11/config','X11/window-managers','X11/xinit','purge') {
84                 if ( -f "$prefix$f") {
85                         warning("file $prefix$f was ignored.");
86                 }
87         }
88
89         if (-f "${prefix}init.d") {
90                 debinit($package,"${prefix}init.d",$package,"");
91         }
92
93         # The case of a daemon without the final d
94         if (-f "${prefix}init") {
95                 $p=$package;
96                 if ($p=~s/d$//) {
97                         debinit($p,"${prefix}init",$package,"--remove-d");
98                 }
99         }
100
101         if (-f "${prefix}info") {
102                 warning("debhelper does not yet support info files, so ${prefix}info was ignored.");
103         }
104
105         # Set up undocumented man page symlinks.
106         if (defined($ds{UNDOC}) && $ds{UNDOC}) {
107                 open (FIND,"find $tmp -type f -perm +111 2>/dev/null |") || warning("find: $!");
108                 while (<FIND>) {
109                         chomp;
110                         ($binpath, $binname)=m:$tmp/(.*)/(.*):;
111         
112                         # Check if manpages exist
113                         $section='';
114                         if ($binpath eq 'sbin' || $binpath eq 'usr/sbin') {
115                                 $section=8;
116                         }
117                         elsif ($binpath eq 'usr/X11R6/bin') {
118                                 $section='1x';
119                         }
120                         elsif ($binpath eq 'bin' || $binpath eq 'usr/bin') {
121                                 $section=1;
122                         }
123                         elsif ($binpath eq 'usr/games') {
124                                 $section=6;
125                         }       
126                         if ($section && `find $tmp/usr/share/man $tmp/usr/X11R6/man -name "$binname.*" 2>/dev/null` eq '') {
127                                 doit("dh_undocumented","-p$package","$binname.$section");
128                         }
129                 }
130                 close FIND;
131         }
132 }
133
134 # Special case of changelog
135 $changelogfile='';
136 if ($ARGV[0] && $ARGV[0]=~m/change|news|history/) {
137         $changelogfile=shift;
138 }
139
140 doit("dh_installdirs"); # here just to make the debian/tmp, etc directories.
141 doit("dh_installdocs",@ARGV);
142 doit("dh_installexamples");
143 if ($changelogfile) {
144         doit("dh_installchangelogs",$changelogfile);
145 }
146 else {
147         doit("dh_installchangelogs");
148 }
149 doit("dh_installmenu");
150 doit("dh_installcron");
151
152 # Manpage scan
153 if (! $ds{NOAUTOMAN}) {
154         doit("dh_installmanpages","-p$dh{FIRSTPACKAGE}");
155 }
156
157 # Per-package stuff:
158 foreach $PACKAGE (@{$dh{DOPACKAGES}}) {
159         if ($PACKAGE eq $dh{FIRSTPACKAGE}) {
160                 if (-f "debian/clean") {
161                         warning("file debian/clean ignored.");
162                 }
163                 do_package($PACKAGE,"debian/tmp","debian/");
164         }
165         else {
166                 do_package($PACKAGE,"debian/$PACKAGE","debian/$PACKAGE.");
167                 if ( -x "debian/$PACKAGE.prebuild") {
168                         warning("file debian/$PACKAGE.prebuild ignored.");
169                 }
170         }
171 }
172
173 doit("dh_movefiles");
174 doit("dh_strip");
175
176 if (! $ds{NOCOMPRESS}) {
177         doit("dh_compress");
178 }
179
180 doit("dh_fixperms");
181 doit("dh_suidregister");
182 doit("dh_shlibdeps");
183 doit("dh_gencontrol");
184 doit("dh_makeshlibs");
185
186 # Check to see if the install scripts have #DEBHELPER# in them, if not,
187 # warn.
188 @filelist=();
189 foreach $PACKAGE (@{$dh{DOPACKAGES}}) {
190         foreach $file (qw{postinst postrm preinst prerm}) {
191                 $f=pkgfile($PACKAGE,$file);
192                 if ($f) {
193                         open (IN,$f);
194                         $found=undef;
195                         while (<IN>) {
196                                 if (/#DEBHELPER#/) {
197                                         $found=1;
198                                         last;
199                                 }
200                         }
201                         if (! $found) {
202                                 push @filelist, $f;
203                         }
204                 }
205         }
206 }
207 if (@filelist) {
208         warning("The following scripts do not contain \"#DEBHELPER#\" in them,");
209         warning("and so debhelper will not automatically add commands to them:");
210         warning(join(" ",@filelist));
211 }
212
213 doit("dh_installdeb");
214
215 if (! $ds{SUMS}) {
216         doit("dh_md5sums");
217 }
218
219 # This causes the main binary package to be built, which
220 # real debstd does not do. Shouldn't be a problem though,
221 # if that package gets built twice.
222 doit("dh_builddeb");