2 # Copyright (c) 2008,2009 Zmanda, Inc. All Rights Reserved.
4 # This program is free software; you can redistribute it and/or modify it
5 # under the terms of the GNU General Public License version 2 as published
6 # by the Free Software Foundation.
8 # This program is distributed in the hope that it will be useful, but
9 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
10 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 # You should have received a copy of the GNU General Public License along
14 # with this program; if not, write to the Free Software Foundation, Inc.,
15 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 # Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
18 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
20 use lib '@amperldir@';
22 use Amanda::Config qw( :getconf :init );
23 use Amanda::Debug qw( :logging );
24 use Amanda::Util qw( :constants );
26 use Amanda::Constants;
29 # Implementation note: this application is a bit funny, because it does not
30 # set up Amanda fully until some time into processing. This lets it respond
31 # with build configuration information without a config file, and lets it set
32 # up debugging for the caller.
34 # The most obvious consequence is that, rather than calling die (which interfaces
35 # with Amanda::Debug), this file uses a locally defined 'fail' to print error
40 Usage: amgetconf [--client] [--execute-where client|server] [-l|--list] [-o configoption]* <config> <paramname>
41 (any ordering of options and arguments is acceptable)
43 --client is equivalent to --execute-where client
45 --execute-where tells amgetconf whether to operate on the client or the
46 server; the server is the default.
48 paramname can be one of
49 dbopen.APPNAME -- open a debug file
50 dbclose.APPNAME:FILENAME -- close debug file FILENAME
51 build.PARAM -- get a build parameter
52 PARAM -- get an Amanda configuration parameter
54 For all but Amanda configuration parameters, the <config> option is
55 ignored, but must be present. For Amanda configuration parameters,
56 values in subsections are specified in the form TYPE:NAME:PARAMETER.
58 With --list, PARAM can be one of
60 for my $name (keys %Amanda::Config::subsection_names) {
62 if $Amanda::Config::subsection_names{$name};
68 print STDERR @_, "\n";
74 fail("amgetconf: no such parameter \"$parameter\"");
80 # NOTE TO MAINTAINERS:
81 # If you add to this list, be sure to also add the new parameter
82 # amgetconf(8) manual page. Note that all keys are lower-case.
84 ## directories from Amanda::Paths
87 'sbindir' => $sbindir,
88 'libexecdir' => $libexecdir,
89 'amlibexecdir' => $amlibexecdir,
91 'amanda_tmpdir' => $AMANDA_TMPDIR,
92 'config_dir' => $CONFIG_DIR,
93 'amanda_dbgdir' => $AMANDA_DBGDIR,
94 'application_dir' => $APPLICATION_DIR,
95 'gnutar_listed_incremental_dir' => $GNUTAR_LISTED_INCREMENTAL_DIR,
96 'listed_inc_dir' => $GNUTAR_LISTED_INCREMENTAL_DIR, # (historical alias)
98 ## constants from Amanda::Constants
100 # build environment info
102 'cc' => $Amanda::Constants::CC,
103 'version' => $Amanda::Constants::VERSION,
104 'assertions' => $Amanda::Constants::ASSERTIONS,
105 'use_version_suffixes' => 'no', # for backward compatibility
106 'locking' => $Amanda::Constants::LOCKING,
110 'dump' => $Amanda::Constants::DUMP,
111 'restore' => $Amanda::Constants::RESTORE,
112 'vdump' => $Amanda::Constants::VDUMP,
113 'vrestore' => $Amanda::Constants::VRESTORE,
114 'xfsdump' => $Amanda::Constants::XFSDUMP,
115 'xfsrestore' => $Amanda::Constants::XFSRESTORE,
116 'vxdump' => $Amanda::Constants::VXDUMP,
117 'vxrestore' => $Amanda::Constants::VXRESTORE,
118 'samba_client' => $Amanda::Constants::SAMBA_CLIENT,
119 'gnutar' => $Amanda::Constants::GNUTAR,
120 'star' => $Amanda::Constants::STAR,
121 'compress_path' => $Amanda::Constants::COMPRESS_PATH,
122 'uncompress_path' => $Amanda::Constants::UNCOMPRESS_PATH,
123 'aix_backup' => $Amanda::Constants::AIX_BACKUP,
124 'dump_returns_1' => $Amanda::Constants::DUMP_RETURNS_1,
128 'bsd_security' => $Amanda::Constants::BSD_SECURITY,
129 'bsdudp_security' => $Amanda::Constants::BSDUDP_SECURITY,
130 'bsdtcp_security' => $Amanda::Constants::BSDTCP_SECURITY,
131 'krb5_security' => $Amanda::Constants::KRB5_SECURITY,
132 'ssh_security' => $Amanda::Constants::SSH_SECURITY,
133 'rsh_security' => $Amanda::Constants::RSH_SECURITY,
134 'use_amandahosts' => $Amanda::Constants::USE_AMANDAHOSTS,
136 # build-time constants
138 'amanda_debug_days' => $Amanda::Constants::AMANDA_DEBUG_DAYS,
139 'default_server' => $Amanda::Constants::DEFAULT_SERVER,
140 'default_amandates_file' => $Amanda::Constants::DEFAULT_AMANDATES_FILE,
141 'default_config' => $Amanda::Constants::DEFAULT_CONFIG,
142 'default_tape_server' => $Amanda::Constants::DEFAULT_TAPE_SERVER,
143 'default_tape_device' => $Amanda::Constants::DEFAULT_TAPE_DEVICE,
144 'client_login' => $Amanda::Constants::CLIENT_LOGIN,
145 'use_rundump' => $Amanda::Constants::USE_RUNDUMP,
146 'check_userid' => $Amanda::Constants::CHECK_USERID,
148 # compression information
150 'compress_suffix' => $Amanda::Constants::COMPRESS_SUFFIX,
151 'compress_fast_opt' => $Amanda::Constants::COMPRESS_FAST_OPT,
152 'compress_best_opt' => $Amanda::Constants::COMPRESS_BEST_OPT,
153 'uncompress_opt' => $Amanda::Constants::UNCOMPRESS_OPT,
155 # kerberos information
157 'ticket_lifetime' => $Amanda::Constants::TICKET_LIFETIME,
158 'server_host_principal' => $Amanda::Constants::SERVER_HOST_PRINCIPAL,
159 'server_host_instance' => $Amanda::Constants::SERVER_HOST_INSTANCE,
160 'server_host_key_file' => $Amanda::Constants::SERVER_HOST_KEY_FILE,
161 'client_host_principal' => $Amanda::Constants::CLIENT_HOST_PRINCIPAL,
162 'client_host_instance' => $Amanda::Constants::CLIENT_HOST_INSTANCE,
163 'client_host_key_file' => $Amanda::Constants::CLIENT_HOST_KEY_FILE,
164 # (historical typos:)
165 'server_host_principle' => $Amanda::Constants::SERVER_HOST_PRINCIPAL,
166 'client_host_principle' => $Amanda::Constants::CLIENT_HOST_PRINCIPAL,
167 # (for testing purposes)
173 my ($parameter, $opt_list) = @_;
176 usage() unless ($parameter eq "build");
178 for my $pname (sort keys %build_info) {
182 my ($pname) = $parameter =~ /^build\.(.*)/;
184 my $val = $build_info{lc $pname};
185 no_such_param($parameter) unless (defined($val));
194 my ($parameter, $opt_list) = @_;
195 my ($appname, $filename);
197 # copy amgetconf pname and pcontext
198 my $pname = Amanda::Util::get_pname();
199 my $pcontext = Amanda::Util::get_pcontext();
201 if (($appname) = $parameter =~ /^dbopen\.(.*)/) {
202 $appname =~ s/[^[:alnum:]]/_/g;
203 # set pname and pcontext for the application
204 Amanda::Util::set_pname($appname);
205 Amanda::Util::set_pcontext($CONTEXT_CMDLINE);
206 Amanda::Debug::dbopen("server");
207 print Amanda::Debug::dbfn(), "\n";
208 } elsif (($appname, $filename) = $parameter =~ /^dbclose\.([^:]*):(.*)/) {
209 fail("debug file $filename does not exist") unless (-f $filename);
210 # set pname and pcontext for the application
211 Amanda::Util::set_pname($appname);
212 Amanda::Util::set_pcontext($CONTEXT_CMDLINE);
213 Amanda::Debug::dbreopen($filename, '');
214 Amanda::Debug::dbclose();
217 fail("cannot parse $parameter");
219 # reset pname and pcontext for amgetconf
220 Amanda::Util::set_pcontext($pcontext);
221 Amanda::Util::set_pname($pname);
224 ## regular configuration parameters
227 my ($parameter, $opt_list) = @_;
230 # getconf_list will return an empty list for any unrecognized name,
231 # so first check that the user has supplied a real subsection
232 no_such_param($parameter)
233 unless defined($Amanda::Config::subsection_names{$parameter});
234 my @list = getconf_list($parameter);
236 for my $subsec (@list) {
240 no_such_param($parameter)
241 unless defined(getconf_byname($parameter));
242 my @strs = getconf_byname_strs($parameter, 0);
244 for my $str (@strs) {
250 ## Command-line parsing
253 my $config_overrides = new_config_overrides($#ARGV+1);
254 my $execute_where = undef;
256 Getopt::Long::Configure(qw{bundling});
258 'list|l' => \$opt_list,
259 'o=s' => sub { add_config_override_opt($config_overrides, $_[1]); },
260 'execute-where=s' => sub {
261 my $where = lc($_[1]);
262 fail("Invalid value ($_[1]) for --execute-where. Must be client or server.")
263 unless $where eq 'client' or $where eq 'server';
264 fail("--execute-where=server conflicts with --execute-where=client or --client.")
265 unless !defined($execute_where) || (
266 ($where eq 'client' && $execute_where) ||
267 ($where eq 'server' && !$execute_where));
268 $execute_where = ($where eq 'client')? $CONFIG_INIT_CLIENT : 0;
271 fail("--execute-where=server conflicts with --execute-where=client or --client.")
272 unless !defined($execute_where) || $execute_where;
273 $execute_where = $CONFIG_INIT_CLIENT;
281 $parameter = $ARGV[0];
282 } elsif (@ARGV >= 2) {
283 # note that we ignore any arguments past these two. Amdump lazily passes
284 # such arguments on to us, so we have no choice.
285 $config_name = $ARGV[0];
286 $parameter = $ARGV[1];
291 ## Now start looking at the parameter.
293 Amanda::Util::setup_application("amgetconf", "server", $CONTEXT_SCRIPTUTIL);
295 if ($parameter =~ /^build(?:\..*)?/) {
296 config_init(0|$execute_where, undef);
297 build_param($parameter, $opt_list);
298 Amanda::Util::finish_application();
302 if ($parameter =~ /^db(open|close)\./) {
303 config_init(0|$execute_where, undef);
304 db_param($parameter, $opt_list);
305 Amanda::Util::finish_application();
309 # finally, finish up the application startup procedure
310 set_config_overrides($config_overrides);
311 config_init($CONFIG_INIT_EXPLICIT_NAME | $CONFIG_INIT_USE_CWD | $execute_where, $config_name);
312 my ($cfgerr_level, @cfgerr_errors) = config_errors();
313 if ($cfgerr_level >= $CFGERR_WARNINGS) {
314 config_print_errors();
315 if ($cfgerr_level >= $CFGERR_ERRORS) {
316 die("errors processing config file");
320 Amanda::Util::finish_setup($RUNNING_AS_ANY);
322 conf_param($parameter, $opt_list);
324 Amanda::Util::finish_application();