update-serial.pl
branchhs12
changeset 71 e25fc893e203
parent 70 bffb3f2cca90
child 72 d3d2108f07da
equal deleted inserted replaced
70:bffb3f2cca90 71:e25fc893e203
    10 use Getopt::Long;
    10 use Getopt::Long;
    11 use File::Temp;
    11 use File::Temp;
    12 use IO::File;
    12 use IO::File;
    13 use POSIX qw(strftime);
    13 use POSIX qw(strftime);
    14 use if $ENV{DEBUG} => "Smart::Comments";
    14 use if $ENV{DEBUG} => "Smart::Comments";
       
    15 use my::Config qw(get_config);
    15 
    16 
    16 sub uniq(@);
    17 sub uniq(@);
    17 sub read_conf(@);
       
    18 sub zones(@);
    18 sub zones(@);
    19 sub changed_zones();
    19 sub changed_zones();
    20 sub update_index($);
    20 sub update_index($);
    21 sub signature_expired($);
    21 sub signature_expired($);
    22 sub need_rollover();
    22 sub need_rollover();
    49             );
    49             );
    50         },
    50         },
    51     ) or pod2usage;
    51     ) or pod2usage;
    52 
    52 
    53     # merge the config and the defined options from commandline
    53     # merge the config and the defined options from commandline
    54     %config = (
    54     %config = get_config("$FindBin::Bin/dnstools.conf", "/etc/dnstools.conf", \%opt);
    55         read_conf("$FindBin::Bin/dnstools.conf", "/etc/dnstools.conf"),
    55 
    56         map { $_ => $opt{$_} } grep { defined $opt{$_} } keys %opt
    56     ### %config
    57     );
    57     exit;
    58 
    58 
    59     our $bind_dir = $config{bind_dir};
    59     our $bind_dir = $config{bind_dir};
    60     our $conf_dir = $config{zone_conf_dir};
    60     our $conf_dir = $config{zone_conf_dir};
    61 
    61 
    62     my @candidates = @ARGV ? zones(@ARGV) : changed_zones;
    62     my @candidates = @ARGV ? zones(@ARGV) : changed_zones;
    86 
    86 
    87     # remove duplicate entries
    87     # remove duplicate entries
    88     my %all;
    88     my %all;
    89     @all{@_} = ();
    89     @all{@_} = ();
    90     keys %all;
    90     keys %all;
    91 }
       
    92 
       
    93 sub read_conf(@) {
       
    94     my @configs = @_;
       
    95     my %config;
       
    96 
       
    97     my ($config) = grep { -f } @configs
       
    98       or die "No config found (looked at @configs)\n";
       
    99 
       
   100     open(my $fh => $config) or die "$config: $!\n";
       
   101 
       
   102     while (<$fh>) {
       
   103         chomp;
       
   104         s/#.*//;
       
   105         s/\s//g;
       
   106         my ($k, $v) = split(/\s*=\s*/, $_, 2) or next;
       
   107         $config{$k} = $v;
       
   108     }
       
   109 
       
   110     return %config;
       
   111 }
    91 }
   112 
    92 
   113 sub zones(@) {
    93 sub zones(@) {
   114 
    94 
   115     # check whether the zones in argv are managed zones and
    95     # check whether the zones in argv are managed zones and