lintian doesn't like orphan packages with uploaders...
[debian/amanda] / common-src / amgetconf.pl
index 86870e1e3e1633c3178ab0b7926ab15968459c62..0a8b1a5b36e05dc1989d905f4f3333064a578570 100644 (file)
@@ -1,9 +1,10 @@
 #! @PERL@
-# Copyright (c) 2005-2008 Zmanda Inc.  All Rights Reserved.
+# Copyright (c) 2008-2012 Zmanda, Inc.  All Rights Reserved.
 #
-# This program is free software; you can redistribute it and/or modify it
-# under the terms of the GNU General Public License version 2 as published
-# by the Free Software Foundation.
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
 #
 # This program is distributed in the hope that it will be useful, but
 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 # with this program; if not, write to the Free Software Foundation, Inc.,
 # 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
 #
-# Contact information: Zmanda Inc., 465 S Mathlida Ave, Suite 300
+# Contact information: Zmanda Inc., 465 S. Mathilda Ave., Suite 300
 # Sunnyvale, CA 94086, USA, or: http://www.zmanda.com
 
 use lib '@amperldir@';
 use strict;
+use warnings;
 use Amanda::Config qw( :getconf :init );
 use Amanda::Debug qw( :logging );
 use Amanda::Util qw( :constants );
 use Amanda::Paths;
 use Amanda::Constants;
+eval 'use Amanda::Disklist;';  # can fail if compiled for client only
 use Getopt::Long;
 
 # Implementation note: this application is a bit funny, because it does not
@@ -58,7 +61,8 @@ values in subsections are specified in the form TYPE:NAME:PARAMETER.
 With --list, PARAM can be one of
 EOF
     for my $name (keys %Amanda::Config::subsection_names) {
-       print "    $name\n";
+       print "    $name\n"
+           if $Amanda::Config::subsection_names{$name};
     }
     exit(1);
 }
@@ -101,7 +105,7 @@ my %build_info = (
     'cc' => $Amanda::Constants::CC,
     'version' => $Amanda::Constants::VERSION,
     'assertions' => $Amanda::Constants::ASSERTIONS,
-    'use_version_suffixes' => $Amanda::Constants::USE_VERSION_SUFFIXES,
+    'use_version_suffixes' => 'no', # for backward compatibility
     'locking' => $Amanda::Constants::LOCKING,
 
     # executable paths
@@ -127,7 +131,6 @@ my %build_info = (
     'bsd_security' => $Amanda::Constants::BSD_SECURITY,
     'bsdudp_security' => $Amanda::Constants::BSDUDP_SECURITY,
     'bsdtcp_security' => $Amanda::Constants::BSDTCP_SECURITY,
-    'krb4_security' => $Amanda::Constants::KRB4_SECURITY,
     'krb5_security' => $Amanda::Constants::KRB5_SECURITY,
     'ssh_security' => $Amanda::Constants::SSH_SECURITY,
     'rsh_security' => $Amanda::Constants::RSH_SECURITY,
@@ -193,18 +196,32 @@ sub build_param {
 sub db_param {
     my ($parameter, $opt_list) = @_;
     my ($appname, $filename);
+
+    # copy amgetconf pname and pcontext
+    my $pname = Amanda::Util::get_pname();
+    my $pcontext = Amanda::Util::get_pcontext();
+
     if (($appname) = $parameter =~ /^dbopen\.(.*)/) {
        $appname =~ s/[^[:alnum:]]/_/g;
-       Amanda::Util::setup_application($appname, "server", $CONTEXT_CMDLINE);
+       # set pname and pcontext for the application
+       Amanda::Util::set_pname($appname);
+       Amanda::Util::set_pcontext($CONTEXT_CMDLINE);
+       Amanda::Debug::dbopen("server");
        print Amanda::Debug::dbfn(), "\n";
     } elsif (($appname, $filename) = $parameter =~ /^dbclose\.([^:]*):(.*)/) {
        fail("debug file $filename does not exist") unless (-f $filename);
+       # set pname and pcontext for the application
+       Amanda::Util::set_pname($appname);
+       Amanda::Util::set_pcontext($CONTEXT_CMDLINE);
        Amanda::Debug::dbreopen($filename, '');
        Amanda::Debug::dbclose();
        print "$filename\n";
     } else {
        fail("cannot parse $parameter");
     }
+    # reset pname and pcontext for amgetconf
+    Amanda::Util::set_pcontext($pcontext);
+    Amanda::Util::set_pname($pname);
 }
 
 ## regular configuration parameters
@@ -222,6 +239,24 @@ sub conf_param {
        for my $subsec (@list) {
            print "$subsec\n";
        }
+    } elsif ($parameter =~ /^property:/i) {
+       my %properties = %{ getconf($CNF_PROPERTY)};
+       my $propname = $parameter;
+       $propname =~ s/^property://i;
+       $propname = lc($propname);
+       if (exists $properties{$propname}) {
+           print $properties{$propname}->{'values'}[0], "\n";
+       }
+    } elsif ($parameter =~ /^device-property:/i ||
+            $parameter =~ /^device_property:/i) {
+       my %properties = %{ getconf($CNF_DEVICE_PROPERTY) };
+       my $propname = $parameter;
+       $propname =~ s/^device-property://i;
+       $propname =~ s/^device_property://i;
+       $propname = lc($propname);
+       if (exists $properties{$propname}) {
+           print $properties{$propname}->{'values'}[0], "\n";
+       }
     } else {
        no_such_param($parameter)
            unless defined(getconf_byname($parameter));
@@ -233,16 +268,20 @@ sub conf_param {
     }
 }
 
+Amanda::Util::setup_application("amgetconf", "server", $CONTEXT_SCRIPTUTIL);
+
 ## Command-line parsing
 
 my $opt_list = '';
-my $config_overwrites = new_config_overwrites($#ARGV+1);
+my $config_overrides = new_config_overrides($#ARGV+1);
 my $execute_where = undef;
 
+debug("Arguments: " . join(' ', @ARGV));
 Getopt::Long::Configure(qw{bundling});
 GetOptions(
+    'version' => \&Amanda::Util::version_opt,
     'list|l' => \$opt_list,
-    'o=s' => sub { add_config_overwrite_opt($config_overwrites, $_[1]); },
+    'o=s' => sub { add_config_override_opt($config_overrides, $_[1]); },
     'execute-where=s' => sub {
         my $where = lc($_[1]);
         fail("Invalid value ($_[1]) for --execute-where. Must be client or server.") 
@@ -277,19 +316,32 @@ if (@ARGV == 1) {
 ## Now start looking at the parameter.
 
 if ($parameter =~ /^build(?:\..*)?/) {
+    config_init(0|$execute_where, undef);
     build_param($parameter, $opt_list);
+    Amanda::Util::finish_application();
     exit(0);
 } 
 
 if ($parameter =~ /^db(open|close)\./) {
+    config_init(0|$execute_where, undef);
     db_param($parameter, $opt_list);
+    Amanda::Util::finish_application();
     exit(0);
 }
 
 # finally, finish up the application startup procedure
-Amanda::Util::setup_application("amgetconf", "server", $CONTEXT_SCRIPTUTIL);
-config_init($CONFIG_INIT_EXPLICIT_NAME | $CONFIG_INIT_USE_CWD | $execute_where, $config_name);
-apply_config_overwrites($config_overwrites);
+set_config_overrides($config_overrides);
+if ($execute_where == $CONFIG_INIT_CLIENT &&
+    defined($config_name) && $config_name eq '.') {
+    config_init($CONFIG_INIT_USE_CWD | $execute_where, undef);
+} elsif ($execute_where == $CONFIG_INIT_CLIENT &&
+    defined($config_name) && $config_name ne '.') {
+    config_init($CONFIG_INIT_EXPLICIT_NAME | $execute_where, $config_name);
+} elsif ($execute_where == $CONFIG_INIT_CLIENT) {
+    config_init($execute_where, undef);
+} else {
+    config_init($CONFIG_INIT_EXPLICIT_NAME | $CONFIG_INIT_USE_CWD | $execute_where, $config_name);
+}
 my ($cfgerr_level, @cfgerr_errors) = config_errors();
 if ($cfgerr_level >= $CFGERR_WARNINGS) {
     config_print_errors();
@@ -300,4 +352,14 @@ if ($cfgerr_level >= $CFGERR_WARNINGS) {
 
 Amanda::Util::finish_setup($RUNNING_AS_ANY);
 
+if ($execute_where != $CONFIG_INIT_CLIENT) {
+    my $diskfile = Amanda::Config::config_dir_relative(getconf($CNF_DISKFILE));
+    $cfgerr_level = Amanda::Disklist::read_disklist('filename' => $diskfile);
+#    if ($cfgerr_level >= $CFGERR_ERRORS) {
+#      die "Errors processing disklist";
+#    }
+}
+
 conf_param($parameter, $opt_list);
+
+Amanda::Util::finish_application();