2 # Copyright (c) 2008, 2009, 2010 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@';
23 use Amanda::Config qw( :getconf :init );
24 use Amanda::Debug qw( :logging );
25 use Amanda::Util qw( :constants );
27 use Amanda::Constants;
30 # Implementation note: this application is a bit funny, because it does not
31 # set up Amanda fully until some time into processing. This lets it respond
32 # with build configuration information without a config file, and lets it set
33 # up debugging for the caller.
35 # The most obvious consequence is that, rather than calling die (which interfaces
36 # with Amanda::Debug), this file uses a locally defined 'fail' to print error
41 Usage: amgetconf [--client] [--execute-where client|server] [-l|--list] [-o configoption]* <config> <paramname>
42 (any ordering of options and arguments is acceptable)
44 --client is equivalent to --execute-where client
46 --execute-where tells amgetconf whether to operate on the client or the
47 server; the server is the default.
49 paramname can be one of
50 dbopen.APPNAME -- open a debug file
51 dbclose.APPNAME:FILENAME -- close debug file FILENAME
52 build.PARAM -- get a build parameter
53 PARAM -- get an Amanda configuration parameter
55 For all but Amanda configuration parameters, the <config> option is
56 ignored, but must be present. For Amanda configuration parameters,
57 values in subsections are specified in the form TYPE:NAME:PARAMETER.
59 With --list, PARAM can be one of
61 for my $name (keys %Amanda::Config::subsection_names) {
63 if $Amanda::Config::subsection_names{$name};
69 print STDERR @_, "\n";
75 fail("amgetconf: no such parameter \"$parameter\"");
81 # NOTE TO MAINTAINERS:
82 # If you add to this list, be sure to also add the new parameter
83 # amgetconf(8) manual page. Note that all keys are lower-case.
85 ## directories from Amanda::Paths
88 'sbindir' => $sbindir,
89 'libexecdir' => $libexecdir,
90 'amlibexecdir' => $amlibexecdir,
92 'amanda_tmpdir' => $AMANDA_TMPDIR,
93 'config_dir' => $CONFIG_DIR,
94 'amanda_dbgdir' => $AMANDA_DBGDIR,
95 'application_dir' => $APPLICATION_DIR,
96 'gnutar_listed_incremental_dir' => $GNUTAR_LISTED_INCREMENTAL_DIR,
97 'listed_inc_dir' => $GNUTAR_LISTED_INCREMENTAL_DIR, # (historical alias)
99 ## constants from Amanda::Constants
101 # build environment info
103 'cc' => $Amanda::Constants::CC,
104 'version' => $Amanda::Constants::VERSION,
105 'assertions' => $Amanda::Constants::ASSERTIONS,
106 'use_version_suffixes' => 'no', # for backward compatibility
107 'locking' => $Amanda::Constants::LOCKING,
111 'dump' => $Amanda::Constants::DUMP,
112 'restore' => $Amanda::Constants::RESTORE,
113 'vdump' => $Amanda::Constants::VDUMP,
114 'vrestore' => $Amanda::Constants::VRESTORE,
115 'xfsdump' => $Amanda::Constants::XFSDUMP,
116 'xfsrestore' => $Amanda::Constants::XFSRESTORE,
117 'vxdump' => $Amanda::Constants::VXDUMP,
118 'vxrestore' => $Amanda::Constants::VXRESTORE,
119 'samba_client' => $Amanda::Constants::SAMBA_CLIENT,
120 'gnutar' => $Amanda::Constants::GNUTAR,
121 'star' => $Amanda::Constants::STAR,
122 'compress_path' => $Amanda::Constants::COMPRESS_PATH,
123 'uncompress_path' => $Amanda::Constants::UNCOMPRESS_PATH,
124 'aix_backup' => $Amanda::Constants::AIX_BACKUP,
125 'dump_returns_1' => $Amanda::Constants::DUMP_RETURNS_1,
129 'bsd_security' => $Amanda::Constants::BSD_SECURITY,
130 'bsdudp_security' => $Amanda::Constants::BSDUDP_SECURITY,
131 'bsdtcp_security' => $Amanda::Constants::BSDTCP_SECURITY,
132 'krb5_security' => $Amanda::Constants::KRB5_SECURITY,
133 'ssh_security' => $Amanda::Constants::SSH_SECURITY,
134 'rsh_security' => $Amanda::Constants::RSH_SECURITY,
135 'use_amandahosts' => $Amanda::Constants::USE_AMANDAHOSTS,
137 # build-time constants
139 'amanda_debug_days' => $Amanda::Constants::AMANDA_DEBUG_DAYS,
140 'default_server' => $Amanda::Constants::DEFAULT_SERVER,
141 'default_amandates_file' => $Amanda::Constants::DEFAULT_AMANDATES_FILE,
142 'default_config' => $Amanda::Constants::DEFAULT_CONFIG,
143 'default_tape_server' => $Amanda::Constants::DEFAULT_TAPE_SERVER,
144 'default_tape_device' => $Amanda::Constants::DEFAULT_TAPE_DEVICE,
145 'client_login' => $Amanda::Constants::CLIENT_LOGIN,
146 'use_rundump' => $Amanda::Constants::USE_RUNDUMP,
147 'check_userid' => $Amanda::Constants::CHECK_USERID,
149 # compression information
151 'compress_suffix' => $Amanda::Constants::COMPRESS_SUFFIX,
152 'compress_fast_opt' => $Amanda::Constants::COMPRESS_FAST_OPT,
153 'compress_best_opt' => $Amanda::Constants::COMPRESS_BEST_OPT,
154 'uncompress_opt' => $Amanda::Constants::UNCOMPRESS_OPT,
156 # kerberos information
158 'ticket_lifetime' => $Amanda::Constants::TICKET_LIFETIME,
159 'server_host_principal' => $Amanda::Constants::SERVER_HOST_PRINCIPAL,
160 'server_host_instance' => $Amanda::Constants::SERVER_HOST_INSTANCE,
161 'server_host_key_file' => $Amanda::Constants::SERVER_HOST_KEY_FILE,
162 'client_host_principal' => $Amanda::Constants::CLIENT_HOST_PRINCIPAL,
163 'client_host_instance' => $Amanda::Constants::CLIENT_HOST_INSTANCE,
164 'client_host_key_file' => $Amanda::Constants::CLIENT_HOST_KEY_FILE,
165 # (historical typos:)
166 'server_host_principle' => $Amanda::Constants::SERVER_HOST_PRINCIPAL,
167 'client_host_principle' => $Amanda::Constants::CLIENT_HOST_PRINCIPAL,
168 # (for testing purposes)
174 my ($parameter, $opt_list) = @_;
177 usage() unless ($parameter eq "build");
179 for my $pname (sort keys %build_info) {
183 my ($pname) = $parameter =~ /^build\.(.*)/;
185 my $val = $build_info{lc $pname};
186 no_such_param($parameter) unless (defined($val));
195 my ($parameter, $opt_list) = @_;
196 my ($appname, $filename);
198 # copy amgetconf pname and pcontext
199 my $pname = Amanda::Util::get_pname();
200 my $pcontext = Amanda::Util::get_pcontext();
202 if (($appname) = $parameter =~ /^dbopen\.(.*)/) {
203 $appname =~ s/[^[:alnum:]]/_/g;
204 # set pname and pcontext for the application
205 Amanda::Util::set_pname($appname);
206 Amanda::Util::set_pcontext($CONTEXT_CMDLINE);
207 Amanda::Debug::dbopen("server");
208 print Amanda::Debug::dbfn(), "\n";
209 } elsif (($appname, $filename) = $parameter =~ /^dbclose\.([^:]*):(.*)/) {
210 fail("debug file $filename does not exist") unless (-f $filename);
211 # set pname and pcontext for the application
212 Amanda::Util::set_pname($appname);
213 Amanda::Util::set_pcontext($CONTEXT_CMDLINE);
214 Amanda::Debug::dbreopen($filename, '');
215 Amanda::Debug::dbclose();
218 fail("cannot parse $parameter");
220 # reset pname and pcontext for amgetconf
221 Amanda::Util::set_pcontext($pcontext);
222 Amanda::Util::set_pname($pname);
225 ## regular configuration parameters
228 my ($parameter, $opt_list) = @_;
231 # getconf_list will return an empty list for any unrecognized name,
232 # so first check that the user has supplied a real subsection
233 no_such_param($parameter)
234 unless defined($Amanda::Config::subsection_names{$parameter});
235 my @list = getconf_list($parameter);
237 for my $subsec (@list) {
241 no_such_param($parameter)
242 unless defined(getconf_byname($parameter));
243 my @strs = getconf_byname_strs($parameter, 0);
245 for my $str (@strs) {
251 ## Command-line parsing
254 my $config_overrides = new_config_overrides($#ARGV+1);
255 my $execute_where = undef;
257 Getopt::Long::Configure(qw{bundling});
259 'list|l' => \$opt_list,
260 'o=s' => sub { add_config_override_opt($config_overrides, $_[1]); },
261 'execute-where=s' => sub {
262 my $where = lc($_[1]);
263 fail("Invalid value ($_[1]) for --execute-where. Must be client or server.")
264 unless $where eq 'client' or $where eq 'server';
265 fail("--execute-where=server conflicts with --execute-where=client or --client.")
266 unless !defined($execute_where) || (
267 ($where eq 'client' && $execute_where) ||
268 ($where eq 'server' && !$execute_where));
269 $execute_where = ($where eq 'client')? $CONFIG_INIT_CLIENT : 0;
272 fail("--execute-where=server conflicts with --execute-where=client or --client.")
273 unless !defined($execute_where) || $execute_where;
274 $execute_where = $CONFIG_INIT_CLIENT;
282 $parameter = $ARGV[0];
283 } elsif (@ARGV >= 2) {
284 # note that we ignore any arguments past these two. Amdump lazily passes
285 # such arguments on to us, so we have no choice.
286 $config_name = $ARGV[0];
287 $parameter = $ARGV[1];
292 ## Now start looking at the parameter.
294 Amanda::Util::setup_application("amgetconf", "server", $CONTEXT_SCRIPTUTIL);
296 if ($parameter =~ /^build(?:\..*)?/) {
297 config_init(0|$execute_where, undef);
298 build_param($parameter, $opt_list);
299 Amanda::Util::finish_application();
303 if ($parameter =~ /^db(open|close)\./) {
304 config_init(0|$execute_where, undef);
305 db_param($parameter, $opt_list);
306 Amanda::Util::finish_application();
310 # finally, finish up the application startup procedure
311 set_config_overrides($config_overrides);
312 config_init($CONFIG_INIT_EXPLICIT_NAME | $CONFIG_INIT_USE_CWD | $execute_where, $config_name);
313 my ($cfgerr_level, @cfgerr_errors) = config_errors();
314 if ($cfgerr_level >= $CFGERR_WARNINGS) {
315 config_print_errors();
316 if ($cfgerr_level >= $CFGERR_ERRORS) {
317 die("errors processing config file");
321 Amanda::Util::finish_setup($RUNNING_AS_ANY);
323 conf_param($parameter, $opt_list);
325 Amanda::Util::finish_application();