2 # Copyright (c) 2005-2008 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 Mathlida 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) {
67 print STDERR @_, "\n";
73 fail("amgetconf: no such parameter \"$parameter\"");
79 # NOTE TO MAINTAINERS:
80 # If you add to this list, be sure to also add the new parameter
81 # amgetconf(8) manual page. Note that all keys are lower-case.
83 ## directories from Amanda::Paths
86 'sbindir' => $sbindir,
87 'libexecdir' => $libexecdir,
88 'amlibexecdir' => $amlibexecdir,
90 'amanda_tmpdir' => $AMANDA_TMPDIR,
91 'config_dir' => $CONFIG_DIR,
92 'amanda_dbgdir' => $AMANDA_DBGDIR,
93 'application_dir' => $APPLICATION_DIR,
94 'gnutar_listed_incremental_dir' => $GNUTAR_LISTED_INCREMENTAL_DIR,
95 'listed_inc_dir' => $GNUTAR_LISTED_INCREMENTAL_DIR, # (historical alias)
97 ## constants from Amanda::Constants
99 # build environment info
101 'cc' => $Amanda::Constants::CC,
102 'version' => $Amanda::Constants::VERSION,
103 'assertions' => $Amanda::Constants::ASSERTIONS,
104 'use_version_suffixes' => $Amanda::Constants::USE_VERSION_SUFFIXES,
105 'locking' => $Amanda::Constants::LOCKING,
109 'dump' => $Amanda::Constants::DUMP,
110 'restore' => $Amanda::Constants::RESTORE,
111 'vdump' => $Amanda::Constants::VDUMP,
112 'vrestore' => $Amanda::Constants::VRESTORE,
113 'xfsdump' => $Amanda::Constants::XFSDUMP,
114 'xfsrestore' => $Amanda::Constants::XFSRESTORE,
115 'vxdump' => $Amanda::Constants::VXDUMP,
116 'vxrestore' => $Amanda::Constants::VXRESTORE,
117 'samba_client' => $Amanda::Constants::SAMBA_CLIENT,
118 'gnutar' => $Amanda::Constants::GNUTAR,
119 'star' => $Amanda::Constants::STAR,
120 'compress_path' => $Amanda::Constants::COMPRESS_PATH,
121 'uncompress_path' => $Amanda::Constants::UNCOMPRESS_PATH,
122 'aix_backup' => $Amanda::Constants::AIX_BACKUP,
123 'dump_returns_1' => $Amanda::Constants::DUMP_RETURNS_1,
127 'bsd_security' => $Amanda::Constants::BSD_SECURITY,
128 'bsdudp_security' => $Amanda::Constants::BSDUDP_SECURITY,
129 'bsdtcp_security' => $Amanda::Constants::BSDTCP_SECURITY,
130 'krb4_security' => $Amanda::Constants::KRB4_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);
196 if (($appname) = $parameter =~ /^dbopen\.(.*)/) {
197 $appname =~ s/[^[:alnum:]]/_/g;
198 Amanda::Util::setup_application($appname, "server", $CONTEXT_CMDLINE);
199 print Amanda::Debug::dbfn(), "\n";
200 } elsif (($appname, $filename) = $parameter =~ /^dbclose\.([^:]*):(.*)/) {
201 fail("debug file $filename does not exist") unless (-f $filename);
202 Amanda::Debug::dbreopen($filename, '');
203 Amanda::Debug::dbclose();
206 fail("cannot parse $parameter");
210 ## regular configuration parameters
213 my ($parameter, $opt_list) = @_;
216 # getconf_list will return an empty list for any unrecognized name,
217 # so first check that the user has supplied a real subsection
218 no_such_param($parameter)
219 unless defined($Amanda::Config::subsection_names{$parameter});
220 my @list = getconf_list($parameter);
222 for my $subsec (@list) {
226 no_such_param($parameter)
227 unless defined(getconf_byname($parameter));
228 my @strs = getconf_byname_strs($parameter, 0);
230 for my $str (@strs) {
236 ## Command-line parsing
239 my $config_overwrites = new_config_overwrites($#ARGV+1);
240 my $execute_where = undef;
242 Getopt::Long::Configure(qw{bundling});
244 'list|l' => \$opt_list,
245 'o=s' => sub { add_config_overwrite_opt($config_overwrites, $_[1]); },
246 'execute-where=s' => sub {
247 my $where = lc($_[1]);
248 fail("Invalid value ($_[1]) for --execute-where. Must be client or server.")
249 unless $where eq 'client' or $where eq 'server';
250 fail("--execute-where=server conflicts with --execute-where=client or --client.")
251 unless !defined($execute_where) || (
252 ($where eq 'client' && $execute_where) ||
253 ($where eq 'server' && !$execute_where));
254 $execute_where = ($where eq 'client')? $CONFIG_INIT_CLIENT : 0;
257 fail("--execute-where=server conflicts with --execute-where=client or --client.")
258 unless !defined($execute_where) || $execute_where;
259 $execute_where = $CONFIG_INIT_CLIENT;
267 $parameter = $ARGV[0];
268 } elsif (@ARGV >= 2) {
269 # note that we ignore any arguments past these two. Amdump lazily passes
270 # such arguments on to us, so we have no choice.
271 $config_name = $ARGV[0];
272 $parameter = $ARGV[1];
277 ## Now start looking at the parameter.
279 if ($parameter =~ /^build(?:\..*)?/) {
280 build_param($parameter, $opt_list);
284 if ($parameter =~ /^db(open|close)\./) {
285 db_param($parameter, $opt_list);
289 # finally, finish up the application startup procedure
290 Amanda::Util::setup_application("amgetconf", "server", $CONTEXT_SCRIPTUTIL);
291 config_init($CONFIG_INIT_EXPLICIT_NAME | $CONFIG_INIT_USE_CWD | $execute_where, $config_name);
292 apply_config_overwrites($config_overwrites);
293 my ($cfgerr_level, @cfgerr_errors) = config_errors();
294 if ($cfgerr_level >= $CFGERR_WARNINGS) {
295 config_print_errors();
296 if ($cfgerr_level >= $CFGERR_ERRORS) {
297 die("errors processing config file");
301 Amanda::Util::finish_setup($RUNNING_AS_ANY);
303 conf_param($parameter, $opt_list);