diff -r b1234b9824f0 -r c02caf4e0eb6 mkready --- a/mkready Mon Aug 02 13:45:47 2010 +0200 +++ b/mkready Wed Aug 04 11:27:21 2010 +0200 @@ -1,32 +1,49 @@ #!/usr/bin/perl use strict; +use FindBin; + +# liest die Konfiguration ein +my @configs = ("$FindBin::Bin/dnstools.conf", "/etc/dnstools.conf"); my %config; -open (CONFIG, "dnstools.conf"); + +foreach (grep {-f} @configs) { + open(CONFIG, $_) or die "Can't open $_: $!\n"; +} + +unless (seek(CONFIG,0 ,0 )) { + die "Can't open config (searched: @configs)\n" +} + while () { chomp; s/#.*//; s/\t//g; s/\s//g; - next unless length; my ($cname, $ccont) = split (/\s*=\s*/, $_,2); $config{$cname} = $ccont; } close (CONFIG); - my $bind_dir = $config{bind_dir}; my $conf_dir = $config{zone_conf_dir}; my $master_dir = $config{master_dir}; -chomp (my @conf_dir_files = `ls $conf_dir`); + +unless (-d $master_dir and -r $master_dir) { + die "$master_dir: $!\n"; +} + +unless (-d $bind_dir and -r $bind_dir) { + die "$bind_dir: $!\n"; +} # prueft jede domain, die ein verzeichnis in $master_dir hat, ob es eine # datei $zone_file.signed gibt und ob diese datei in $config_file eingetragen # ist. # passt die eintraege in $config_file falls noetig an. -for (<$master_dir/*>) { +while (<$master_dir/*>) { s#($master_dir/)(.*)#$2#; my $zone = $_; @@ -34,9 +51,13 @@ my $conf_file = "$conf_dir/$zone"; my @c_content; - if (-e "$zone_file.signed") { + unless (-f "$conf_file" ) { + die "$conf_file: $! \n"; + } - open (FILE, $conf_file); + if (-f "$zone_file.signed") { + + open (FILE, "<$conf_file") or die "$conf_file: $!\n"; @c_content = ; close (FILE); @@ -46,15 +67,15 @@ $_ = "$1$2.signed$3\n"; } - open (FILE, ">$conf_file"); + open (FILE, ">$conf_file") or die "$conf_file: $!\n"; print FILE @c_content; close (FILE); } + } + else { - } else { - - open (FILE, $conf_file); + open (FILE, "<$conf_file") or die "$conf_file: $!\n"; @c_content = ; close (FILE); @@ -65,22 +86,22 @@ } } - open (FILE, ">$conf_file"); + open (FILE, ">$conf_file") or die "$conf_file: $!\n"; print FILE @c_content; close (FILE); } } # erzeugt eine named.conf-datei aus den entsprechenden vorlagen. -open( TO, ">$bind_dir/named.conf.zones"); -for (@conf_dir_files) { - open (FROM, "$conf_dir/$_"); +open( TO, ">$bind_dir/named.conf.zones") or die "$bind_dir/named.conf.zones: $!\n"; +while (<$conf_dir/*>) { + open (FROM, "$_") or die "$_: $! \n"; print TO ; close (FROM); } close(TO); -print `named-checkconf`; -print `named-checkconf -z`; -print `rndc reload`; +system "named-checkconf"; +system "named-checkconf -z"; +system "rndc reload";