Debian Codegraph @

debconf-show

raw
1 #!/usr/bin/perl
2
3 =head1 NAME
4
5 debconf-show - query the debconf database
6
7 =head1 SYNOPSIS
8
9 debconf-show packagename [...] [--db=dbname]
10 debconf-show --listowners [--db=dbname]
11 debconf-show --listdbs
12
13 =head1 DESCRIPTION
14
15 B<debconf-show> lets you query the debconf database in different ways.
16
17 The most common use is "debconf-show packagename", which displays all items
18 in the debconf database owned by a given package, and their current values.
19 Questions that have been asked already are prefixed with an '*'.
20
21 This can be useful as a debugging aid, and especially handy in bug reports
22 involving a package's use of debconf.
23
24 =head1 OPTIONS
25
26 =over 4
27
28 =item B<--db=>I<dbname>
29
30 Specify the database to query. By default, debconf-show queries the main
31 database.
32
33 =item B<--listowners>
34
35 Lists all owners of questions in the database. Generally an owner is
36 equivalent to a debian package name.
37
38 =item B<--listdbs>
39
40 Lists all available databases.
41
42 =back
43
44 =cut
45
46 use strict;
47 use warnings;
48 use Debconf::Db;
49 use Debconf::Template;
50 use Debconf::Question;
51 use Getopt::Long;
52
53 sub usage {
54 print STDERR <<EOF;
55 Usage:
56 debconf-show packagename [...] [--db=dbname]
57 debconf-show --listowners [--db=dbname]
58 debconf-show --listdbs
59 EOF
60 exit(1);
61 }
62
63 my $db='';
64 my $listowners=0;
65 my @packages;
66 my $listdbs=0;
67
68 # command options
69 GetOptions(
70 "db=s" => \$db,
71 "listowners" => \$listowners,
72 "listdbs" => \$listdbs,
73 ) || usage();
74
75 unless ($listowners or $listdbs) {
76 @packages=@ARGV;
77 usage() unless @packages;
78 }
79
80 Debconf::Db->load(readonly => 'true');
81
82 my %drivers = %Debconf::DbDriver::drivers;
83 my $conf = Debconf::Config->config;
84
85 # Recursive function to get the config tree.
86 sub tree {
87 my $node=shift;
88 my $string=shift || "";
89 my $driver = Debconf::DbDriver->driver($node);
90 my $name = $driver->{name};
91
92 $string = $string.$name;
93 print $string."\n";
94
95 # If the node is a stack, call tree again to get the subtree.
96 if ($driver->isa("Debconf::DbDriver::Stack")) {
97 $string=$string.'/';
98 map { tree($_->{name},$string) } @{$driver->{stack}};
99 }
100 }
101
102 # If a specific database is given (with --db), redefine the global config
103 # database to use it.
104 if ($db) {
105 my $driver = $drivers{$db};
106 die $db.": unknown database" unless defined($driver);
107 $Debconf::Db::config = $driver;
108 }
109
110 my $qi=Debconf::Question->iterator;
111
112 if ($listdbs) {
113 # Display the config tree.
114 tree($conf);
115 }
116 elsif (@packages) {
117 while (my $q=$qi->iterate) {
118 foreach my $package (@packages) {
119 # Show the questions of a package.
120 if (grep { $package eq $_} split(/, /, $q->owners)) {
121 if ($q->flag("seen") eq 'true') {
122 print "* ";
123 }
124 else {
125 print " ";
126 }
127 print $q->name.":";
128 if ($q->type eq 'password') {
129 print " (password omitted)";
130 }
131 elsif (length $q->value) {
132 print " ".$q->value;
133 }
134 print "\n";
135 }
136 }
137 }
138 }
139 elsif ($listowners) {
140 # Show all the owners in the database.
141 my %seen;
142 while (my $q=$qi->iterate) {
143 foreach (split(/, /, $q->owners)) {
144 unless ($seen{$_}) {
145 print "$_\n";
146 $seen{$_}=1;
147 }
148 }
149 }
150 }
151
152 =head1 AUTHOR
153
154 Joey Hess <[email protected]> and Sylvain Ferriol
155
156 =cut