summaryrefslogtreecommitdiff
path: root/dh_bugfiles
blob: 83428f5151b5577ac46cc6bcae59369b5e13e343 (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
#!/usr/bin/perl -w

=head1 NAME

dh_bugfiles - install bug reporting customization files into package build directories

=cut

use strict;
use Debian::Debhelper::Dh_Lib;

=head1 SYNOPSIS

B<dh_bugfiles> [B<-A>] [S<I<debhelper options>>]

=head1 DESCRIPTION

B<dh_bugfiles> is a debhelper program that is responsible for installing
bug reporting customization files (bug scripts and/or bug control files
and/or presubj files) into package build directories.

=head1 FILES

=over 4

=item debian/I<package>.bug-script

This is the script to be run by the bug reporting program for generating a bug
report template. This file is installed as F<usr/share/bug/package> in the
package build directory if no other types of bug reporting customization
files are going to be installed for the package in question. Otherwise,
this file is installed as F<usr/share/bug/package/script>. Finally, the
installed script is given execute permissions.

=item debian/I<package>.bug-control

It is the bug control file containing some directions for the bug reporting
tool. This file is installed as F<usr/share/bug/package/control> in the
package build directory.

=item debian/I<package>.bug-presubj

The contents of this file are displayed to the user by the bug reporting
tool before allowing the user to write a bug report on the package to the
Debian Bug Tracking System. This file is installed as
F<usr/share/bug/package/presubj> in the package build directory.

=back

=head1 OPTIONS

=over 4

=item B<-A>, B<--all>

Install F<debian/bug-*> files to ALL packages acted on when respective
F<debian/package.bug-*> files do not exist. Normally, F<debian/bug-*> will
be installed to the first package only.

=back

=cut

init();

# Types of bug files this debhelper program handles.
# Hash value is the name of the pkgfile of the respective
# type.
my %bugfile_types = (
	"script" => "bug-script",
	"control" => "bug-control",
	"presubj" => "bug-presubj",
);
# PROMISE: DH NOOP WITHOUT bug-script bug-control bug-presubj

foreach my $package (@{$dh{DOPACKAGES}}) {
	next if is_udeb($package);

	my $tmp=tmpdir($package);
	my $dir="$tmp/usr/share/bug/$package";
	
	# Gather information which bug files are available for the
	# package in question
	my %bugfiles=();
	while (my ($type, $pkgfilename) = each(%bugfile_types)) {
		my $file=pkgfile($package,$pkgfilename);
		if ($file) {
			$bugfiles{$type}=$file;
		}
		elsif (-f "debian/$pkgfilename" && $dh{PARAMS_ALL}) {
			$bugfiles{$type}="debian/$pkgfilename";
		}
	}
	
	# If there is only a bug script to install, install it as
	# usr/share/bug/$package (unless this path is a directory)
	if (! -d $dir && scalar(keys(%bugfiles)) == 1 && exists $bugfiles{script}) {
		doit("install","-D","-p","-m755",$bugfiles{script},$dir);
	}
	elsif (scalar(keys(%bugfiles)) > 0) {
		if (-f $dir) {
			# Move usr/share/bug/$package to usr/share/bug/$package/script
			doit("mv", $dir, "${dir}.tmp");
			doit("install","-d",$dir);
			doit("mv", "${dir}.tmp", "$dir/script");
		}
		elsif (! -d $dir) {
			doit("install","-d",$dir);
		}
		while (my ($type, $srcfile) = each(%bugfiles)) {
			doit("install","-p","-m644",$srcfile, "$dir/$type");
		}
	}
	
	# Ensure that the bug script is executable
	if (-f $dir) {
		chmod 0755, $dir;
	}
	elsif (-f "$dir/script") {
		chmod 0755, "$dir/script";
	}
}

=head1 SEE ALSO

F</usr/share/doc/reportbug/README.developers.gz>

L<debhelper(1)>

This program is a part of debhelper.

=head1 AUTHOR

Modestas Vainius <modestas@vainius.eu>

=cut