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