# HG changeset patch # User Heiko Schlittermann # Date 1288937390 -3600 # Node ID 638a74f94981d8bb2c98648d71bd659e9e1964fe # Parent d7e673f7e596fcdbea3da95cb9da8acfba183a03 [perltidy] diff -r d7e673f7e596 -r 638a74f94981 update-serial.pl --- a/update-serial.pl Fri Nov 05 07:09:24 2010 +0100 +++ b/update-serial.pl Fri Nov 05 07:09:50 2010 +0100 @@ -5,12 +5,12 @@ # … work in progress do integrate dnssec (branch suess) # # Update the serial numbers in zone files -# The serial number needs to match a specified pattern (see +# The serial number needs to match a specified pattern (see # the line marked w/ PATTERN) -# +# # Limitations: # - the zonefile needs to fit entirely into memory -# +# # ToDo: # . test against an md5 sum, not just the date of the stamp file @@ -25,18 +25,18 @@ #my $dnssec_sign = "../dnstools/dnssec-sign"; my $ME = basename $0; -my $master_dir = "/etc/bind/master"; +my $master_dir = "/etc/bind/master"; my $opt_verbose = 0; -my $opt_reload = 0; -my $opt_dnssec = 0; - +my $opt_reload = 0; +my $opt_dnssec = 0; { - my @cleanup; - sub cleanup(@) { - return push @cleanup, @_ if @_; - unlink @cleanup; - } + my @cleanup; + + sub cleanup(@) { + return push @cleanup, @_ if @_; + unlink @cleanup; + } } END { cleanup(); } @@ -45,51 +45,51 @@ MAIN: { - GetOptions( - "verbose!" => \$opt_verbose, - "yes|reload!" => \$opt_reload, - "dnssec!" => \$opt_dnssec, - ) or pod2usage(); + GetOptions( + "verbose!" => \$opt_verbose, + "yes|reload!" => \$opt_reload, + "dnssec!" => \$opt_dnssec, + ) or pod2usage(); - warn "DNSSEC support is currently disabled!\n" - if not $opt_dnssec; + warn "DNSSEC support is currently disabled!\n" + if not $opt_dnssec; - -d $master_dir or die "directory $master_dir not found\n" if not @ARGV; - my @files = map { (-d) ? glob("$_/*") : $_ } @ARGV ? @ARGV : $master_dir; + -d $master_dir or die "directory $master_dir not found\n" if not @ARGV; + my @files = map { (-d) ? glob("$_/*") : $_ } @ARGV ? @ARGV : $master_dir; - my $changed = 0; - foreach my $file (@files) { + my $changed = 0; + foreach my $file (@files) { - $file = undef, next if basename($file) !~ /\./; - $file = undef, next if $file =~ /\.bak|~$/; + $file = undef, next if basename($file) !~ /\./; + $file = undef, next if $file =~ /\.bak|~$/; - # zone file could be - # $master_dir/xxx.de - # or $master_dir/xxx.de/xxx.de - $file = "$file/" . basename($file) if -d $file; + # zone file could be + # $master_dir/xxx.de + # or $master_dir/xxx.de/xxx.de + $file = "$file/" . basename($file) if -d $file; - my $stamp_file = dirname($file) . "/.stamp/" . basename($file); - print "$file:" if $opt_verbose; + my $stamp_file = dirname($file) . "/.stamp/" . basename($file); + print "$file:" if $opt_verbose; - if (stat $stamp_file and (stat _)[9] >= (stat $file)[9]) { - print " fresh, skipping." if $opt_verbose; - next; - } + if (stat $stamp_file and (stat _)[9] >= (stat $file)[9]) { + print " fresh, skipping." if $opt_verbose; + next; + } - $_ = dirname($stamp_file); - mkdir or die "mkdir $_: $!\n" if not -d; + $_ = dirname($stamp_file); + mkdir or die "mkdir $_: $!\n" if not -d; - my $now = time; + my $now = time; - open(my $in, "+<", $file) or do { - print "??: $!" if $opt_verbose; - next; - }; + open(my $in, "+<", $file) or do { + print "??: $!" if $opt_verbose; + next; + }; - $_ = join "", <$in>; + $_ = join "", <$in>; - # this pattern is too complicated - s/^(?!;)(?
			# skip lines starting with comment
+        # this pattern is too complicated
+        s/^(?!;)(?
			# skip lines starting with comment
 			 (?:\S+)?			# label
 			 (?:\s+\d+.)?		# ttl
 			 (?:\s+in)?			# class
@@ -101,53 +101,65 @@
 			 (?\d{10})		# serial
 		/$+{pre} . next_serial($+{serial})/exims or next;
 
-		print "$+{serial} ⇒ @{[next_serial($+{serial})]}" if $opt_verbose;
+        print "$+{serial} ⇒ @{[next_serial($+{serial})]}" if $opt_verbose;
 
-		copy($file => "$file~") or die("Can't copy $file -> $file~: $!\n");
-		seek($in, 0, 0) or die "Can't seek in $file: $!\n";
-		truncate($in, 0) or die "Can't truncate $file: $!\n";
-		print $in $_;
+        copy($file => "$file~") or die("Can't copy $file -> $file~: $!\n");
+        seek($in, 0, 0) or die "Can't seek in $file: $!\n";
+        truncate($in, 0) or die "Can't truncate $file: $!\n";
+        print $in $_;
+
+        open(my $out, ">$stamp_file");
+        close($out);
 
-		open(my $out, ">$stamp_file");
-		close($out);
-
-		print "$file\n" if not $opt_verbose;
+        print "$file\n" if not $opt_verbose;
 
-		$changed++;
-	} continue {
-		print "\n" if $opt_verbose and defined $file;
-	}
+        $changed++;
+    }
+    continue {
+        print "\n" if $opt_verbose and defined $file;
+    }
+
+    if ($changed) {
+        my $pidfile;
 
-	if ($changed) {
-		my $pidfile;
-
-		print "** Changed $changed files, the nameserver needs to be reloaded!\n";
-		foreach (qw(/var/run/bind/run/named.pid /var/run/named.pid /etc/named.pid)) { 
-			-f $_ and $pidfile = $_ and last; }
+        print
+          "** Changed $changed files, the nameserver needs to be reloaded!\n";
+        foreach (
+            qw(/var/run/bind/run/named.pid /var/run/named.pid /etc/named.pid))
+        {
+            -f $_ and $pidfile = $_ and last;
+        }
 
-		if ($pidfile) {
-			if ($opt_reload) { $_ = "y"; print "** Nameserver will be reloaded\n"; } 
-			else { print "** Reload now? [Y/n]: "; $_ = ; }
-			/^y|^$/i and system "rndc reload";
-		} else {
-			print "** No PID of a running named found.  Please reload manually.\n";
-		}
+        if ($pidfile) {
+            if ($opt_reload) {
+                $_ = "y";
+                print "** Nameserver will be reloaded\n";
+            }
+            else { print "** Reload now? [Y/n]: "; $_ = ; }
+            /^y|^$/i and system "rndc reload";
+        }
+        else {
+            print
+              "** No PID of a running named found.  Please reload manually.\n";
+        }
 
-	}
+    }
 }
 
 {
-	my $date;
-sub next_serial($) {
-	if (not defined $date) {
-		my ($dd, $mm, $yy) = (localtime)[3..5];
-		$date = sprintf "%04d%02d%02d" => $yy < 1900 ? $yy + 1900 : $yy,  $mm + 1, $dd;
-	}
+    my $date;
 
-	$_[0] =~ /(?\d{8})(?\d\d)/;
-	return $date . sprintf("%02d", $+{cnt}+1) if $date eq $+{date};
-	return "${date}00";
-}
+    sub next_serial($) {
+        if (not defined $date) {
+            my ($dd, $mm, $yy) = (localtime)[3 .. 5];
+            $date = sprintf "%04d%02d%02d" => $yy < 1900 ? $yy + 1900 : $yy,
+              $mm + 1, $dd;
+        }
+
+        $_[0] =~ /(?\d{8})(?\d\d)/;
+        return $date . sprintf("%02d", $+{cnt} + 1) if $date eq $+{date};
+        return "${date}00";
+    }
 }
 
 __END__