lintian doesn't like orphan packages with uploaders...
[debian/amanda] / common-src / amgetconf.pl
index 1b519a390062187b53dffba8f859157fbcbfdb9d..0a8b1a5b36e05dc1989d905f4f3333064a578570 100644 (file)
@@ -1,9 +1,10 @@
 #! @PERL@
-# Copyright (c) 2008,2009 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
 
 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
@@ -236,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));
@@ -247,14 +268,18 @@ sub conf_param {
     }
 }
 
+Amanda::Util::setup_application("amgetconf", "server", $CONTEXT_SCRIPTUTIL);
+
 ## Command-line parsing
 
 my $opt_list = '';
 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_override_opt($config_overrides, $_[1]); },
     'execute-where=s' => sub {
@@ -290,8 +315,6 @@ if (@ARGV == 1) {
 
 ## Now start looking at the parameter.
 
-Amanda::Util::setup_application("amgetconf", "server", $CONTEXT_SCRIPTUTIL);
-
 if ($parameter =~ /^build(?:\..*)?/) {
     config_init(0|$execute_where, undef);
     build_param($parameter, $opt_list);
@@ -308,7 +331,17 @@ if ($parameter =~ /^db(open|close)\./) {
 
 # finally, finish up the application startup procedure
 set_config_overrides($config_overrides);
-config_init($CONFIG_INIT_EXPLICIT_NAME | $CONFIG_INIT_USE_CWD | $execute_where, $config_name);
+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();
@@ -319,6 +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();