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