]> git.donarmstrong.com Git - debhelper.git/blob - dh_bugfiles
Add dh_bugfiles - a helper for reportbug files
[debhelper.git] / dh_bugfiles
1 #!/usr/bin/perl -w
2
3 =head1 NAME
4
5 dh_bugfiles - install bug reporting customization files into package build directories
6
7 =cut
8
9 use strict;
10 use Debian::Debhelper::Dh_Lib;
11
12 =head1 SYNOPSIS
13
14 B<dh_bugfiles> [B<-A>] [S<I<debhelper options>>]
15
16 =head1 DESCRIPTION
17
18 dh_bugfiles is a debhelper program that is responsible for installing
19 bug reporting customization files (bug scripts and/or bug control files
20 and/or presubj files) into package build directories.
21
22 This helper program installs the following files if they are found:
23
24 =over 3
25
26 =item B<debian/package.bug-script>, B<debian/bug-script>
27
28 It is the script to be run by the bug reporting program for generating a bug
29 report template. This file is installed as F<usr/share/bug/package> into the
30 package build directory if no other types of bug reporting customization
31 files are going to be installed for the package in question. Otherwise,
32 this file is installed as F<usr/share/bug/package/script>. Finally, the
33 installed script is given execute permissions.
34
35 =item B<debian/package.bug-control>, B<debian/bug-control>
36
37 It is the bug control file containing some directions for the bug reporting
38 tool. This file is installed as F<usr/share/bug/package/control> into the
39 package build directory.
40
41 =item B<debian/package.bug-presubj>, B<debian/bug-presubj> 
42
43 The contents of this file are displayed to the user by the bug reporting
44 tool before allowing the user to write a bug report on the package to the
45 Debian Bug Tracking System. This file is installed as
46 F<usr/share/bug/package/control> into the package build directory.
47
48 =back
49
50 =head1 OPTIONS
51
52 =over 4
53
54 =item B<-A>, B<--all>
55
56 Install debian/bug-* files to ALL packages acted on when respective
57 debian/package.bug-* files do not exist. Normally, debian/bug-* will
58 be installed to the first package only.
59
60 =back
61
62 =cut
63
64 init();
65
66 # Types of bug files this debhelper program handles.
67 # Hash value is the name of the pkgfile of the respective
68 # type.
69 my %bugfile_types = (
70         "script" => "bug-script",
71         "control" => "bug-control",
72         "presubj" => "bug-presubj",
73 );
74
75 foreach my $package (@{$dh{DOPACKAGES}}) {
76         next if is_udeb($package);
77
78         my $tmp=tmpdir($package);
79         my $dir="$tmp/usr/share/bug/$package";
80         
81         # Gather information which bug files are available for the
82         # package in question
83         my %bugfiles=();
84         while (my ($type, $pkgfilename) = each(%bugfile_types)) {
85                 my $file=pkgfile($package,$pkgfilename);
86                 if ($file) {
87                         $bugfiles{$type}=$file;
88                 } elsif (-f "debian/$pkgfilename" && $dh{PARAMS_ALL}) {
89                         $bugfiles{$type}="debian/$pkgfilename";
90                 }
91         }
92         
93         # If there is only a bug script to install, install it as
94         # /usr/share/bug/$package (unless this path is a directory)
95         if (! -d $dir && scalar(keys(%bugfiles)) == 1 && exists $bugfiles{script}) {
96                 doit("install","-D","-p","-m755",$bugfiles{script},$dir);
97         } elsif (scalar(keys(%bugfiles)) > 0) {
98                 if (-f $dir) {
99                         # Move usr/share/bug/$package to usr/share/bug/$package/script
100                         doit("mv", $dir, "${dir}.tmp");
101                         doit("install","-d",$dir);
102                         doit("mv", "${dir}.tmp", "$dir/script");
103                 } elsif (! -d $dir) {
104                         doit("install","-d",$dir);
105                 }
106                 while (my ($type, $srcfile) = each(%bugfiles)) {
107                         doit("install","-p","-m644",$srcfile, "$dir/$type");
108                 }
109         }
110         
111         # Ensure that the bug script is executable
112         if (-f $dir) {
113                 chmod 0755, $dir;
114         } elsif (-f "$dir/script") {
115                 chmod 0755, "$dir/script";
116         }
117 }
118
119 =head1 SEE ALSO
120
121 F</usr/share/doc/reportbug/README.developers.gz> (needs B<reportbug> package installed)
122
123 L<debhelper(1)>
124
125 This program is a part of debhelper.
126
127 =head1 AUTHOR
128
129 Modestas Vainius <modestas@vainius.eu>
130
131 =cut