summaryrefslogtreecommitdiff
path: root/dh_debstd
blob: 12e99ffd7b9b7798e3fc0edadfc21a1a106d8d3a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
#!/usr/bin/perl -w
#
# Script to be called from debian/rules to setup all the debian specifc
# required files
# Christoph Lameter, <clameter@debian.org> October 10, 1996
#
# All the parameters are documentation files to be installed.
# (but doc files can also be listed in debian/docs)
#
# This has been gutted and extensively rewritten to function as a debhelper
# command by Joey Hess. And then completly rewritten in perl.

# Need to stay compatable with debstd, so force use of level 1.
$ENV{DH_COMAPT}=1;

# Pre-parse command line before we load Dh_lib, becuase we use a
# different style of arguments.
@argv=();
foreach (@ARGV) {
	if ($_ eq '-p') {
		$ds{PERMS}=1;
	}
	elsif ($_ eq '-u') {
		$ds{UNDOC}=1;
	}
	elsif ($_ eq '-s') {
		$ds{SUMS}=1;
	}
	elsif ($_ eq '-m') {
		$ds{NOAUTOMAN}=1;
	}
	elsif ($_ eq '-c') {
		$ds{NOCOMPRESS}=1;
	}
	else {
		push @argv,$_;
	}
}
@ARGV=@argv;

BEGIN { push @INC, "debian", "/usr/share/debhelper" }
use Dh_Lib;
init();

# Tolerate old style debstd invocations
if ($ARGV[0] && $dh{FIRSTPACKAGE} eq $ARGV[0]) {
	shift;
}

# debinit handles the installation of an init.d script
sub debinit { my ($script, $filename, $package, @params)=@_;
	@initparams=();
	$norestart='';
	open (IN,$filename) || warn("$filename: $!");
	while (<IN>) {
		if (/^FLAGS=(.*)/) {
			push @initparams, $1;
		}
		if (/NO_RESTART_ON_UPGRADE/) {
			$norestart='--no-restart-on-upgrade';
		}
	}
	close IN;
	$initparams='';
	if (@initparams) {
		$initparams="--update-rcd-params='".join(" ",@initparams)."'";
	}

	doit("dh_installinit",$norestart,"-p$package",$initparams,"--init-script=$script",@params);
}

# Do package specific things for a package.
sub do_package { my ($package, $tmp, $prefix)=@_;
	# Deal with scripts in etc directories
	if (-d "$prefix/rc.boot") {
		warning("file $prefix/rc.boot was ignored.");
	}

	# etc files that could need some tweaking
	foreach $f ('services','inittab','crontab','protocols','profile',
		'shells','rpc','syslog.conf','conf.modules','modules',
		'aliases','diversions','inetd.conf','X11/Xresources',
		'X11/config','X11/window-managers','X11/xinit','purge') {
		if ( -f "$prefix$f") {
			warning("file $prefix$f was ignored.");
		}
	}

	if (-f "${prefix}init.d") {
		debinit($package,"${prefix}init.d",$package,"");
	}

	# The case of a daemon without the final d
	if (-f "${prefix}init") {
		$p=$package;
		if ($p=~s/d$//) {
			debinit($p,"${prefix}init",$package,"--remove-d");
		}
	}

	if (-f "${prefix}info") {
		warning("debhelper does not yet support info files, so ${prefix}info was ignored.");
	}

	# Set up undocumented man page symlinks.
	if (defined($ds{UNDOC}) && $ds{UNDOC}) {
		open (FIND,"find $tmp -type f -perm +111 2>/dev/null |") || warning("find: $!");
		while (<FIND>) {
			chomp;
			($binpath, $binname)=m:$tmp/(.*)/(.*):;
	
			# Check if manpages exist
			$section='';
			if ($binpath eq 'sbin' || $binpath eq 'usr/sbin') {
				$section=8;
			}
			elsif ($binpath eq 'usr/X11R6/bin') {
				$section='1x';
			}
			elsif ($binpath eq 'bin' || $binpath eq 'usr/bin') {
				$section=1;
			}
			elsif ($binpath eq 'usr/games') {
				$section=6;
			}	
			if ($section && `find $tmp/usr/share/man $tmp/usr/X11R6/man -name "$binname.*" 2>/dev/null` eq '') {
				doit("dh_undocumented","-p$package","$binname.$section");
			}
		}
		close FIND;
	}
}

# Special case of changelog
$changelogfile='';
if ($ARGV[0] && $ARGV[0]=~m/change|news|history/) {
	$changelogfile=shift;
}

doit("dh_installdirs"); # here just to make the debian/tmp, etc directories.
doit("dh_installdocs",@ARGV);
doit("dh_installexamples");
if ($changelogfile) {
	doit("dh_installchangelogs",$changelogfile);
}
else {
	doit("dh_installchangelogs");
}
doit("dh_installmenu");
doit("dh_installcron");

# Manpage scan
if (! $ds{NOAUTOMAN}) {
	doit("dh_installmanpages","-p$dh{FIRSTPACKAGE}");
}

# Per-package stuff:
foreach $PACKAGE (@{$dh{DOPACKAGES}}) {
	if ($PACKAGE eq $dh{FIRSTPACKAGE}) {
		if (-f "debian/clean") {
			warning("file debian/clean ignored.");
		}
		do_package($PACKAGE,"debian/tmp","debian/");
	}
	else {
		do_package($PACKAGE,"debian/$PACKAGE","debian/$PACKAGE.");
		if ( -x "debian/$PACKAGE.prebuild") {
			warning("file debian/$PACKAGE.prebuild ignored.");
		}
	}
}

doit("dh_movefiles");
doit("dh_strip");

if (! $ds{NOCOMPRESS}) {
	doit("dh_compress");
}

doit("dh_fixperms");
doit("dh_suidregister");
doit("dh_shlibdeps");
doit("dh_gencontrol");
doit("dh_makeshlibs");

# Check to see if the install scripts have #DEBHELPER# in them, if not,
# warn.
@filelist=();
foreach $PACKAGE (@{$dh{DOPACKAGES}}) {
	foreach $file (qw{postinst postrm preinst prerm}) {
		$f=pkgfile($PACKAGE,$file);
		if ($f) {
			open (IN,$f);
			$found=undef;
			while (<IN>) {
				if (/#DEBHELPER#/) {
					$found=1;
					last;
				}
			}
			if (! $found) {
				push @filelist, $f;
			}
		}
	}
}
if (@filelist) {
	warning("The following scripts do not contain \"#DEBHELPER#\" in them,");
	warning("and so debhelper will not automatically add commands to them:");
	warning(join(" ",@filelist));
}

doit("dh_installdeb");

if (! $ds{SUMS}) {
	doit("dh_md5sums");
}

# This causes the main binary package to be built, which
# real debstd does not do. Shouldn't be a problem though,
# if that package gets built twice.
doit("dh_builddeb");