--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgignore Tue Jun 19 09:26:40 2012 +0200
@@ -0,0 +1,1 @@
+update-serial
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/.hgsigs Tue Jun 19 09:26:40 2012 +0200
@@ -0,0 +1,5 @@
+8ade8810add59847f42b5b50a995725d0d55ed99 0 iEYEABECAAYFAkzTL50ACgkQ7k6smEjQNZsM3wCfc4oCxoehAXGOwx4cKWU8YigZNpsAn2k2YyDGGm6yA2fXMs6O6LsY6a+p
+09298aaccb94499c47315871025d8e18d194f4d4 0 iEYEABECAAYFAkzTn8gACgkQ7k6smEjQNZtPWQCdFjYUTeyP4wHo6oplIjXyKZZ2YboAn3LHtjDsF2D+3ZtN3ZkmODIJS7Gm
+dada04e000556288ffd584804cfc7d339ec3b44a 0 iEYEABECAAYFAkzTyMMACgkQ7k6smEjQNZsoqwCgycPhnPuU2JPnmjYmU9CTrlk0fAcAni4xR+0pHhy6A/4NNBnlnQ+ok5gH
+7526e8355cc77cfef71955dd3f25fe8962bf79ad 0 iEYEABECAAYFAkzUIVQACgkQ7k6smEjQNZs7LwCff5O+zHtc5UF/6mTdqSGYUa+AljQAnAr6AyMO1LgulENyOLyldYZ/UKYw
+3145999d34e37c8e0bf9875f6a020bcc90920701 0 iEYEABECAAYFAkzVWmYACgkQ7k6smEjQNZtZeQCg7MGd8LL3/WKlKFsDyYsmazpW+HEAoOfATR8nNQKIWSZ5jBvPhgpsUz3v
--- a/Makefile Tue Jun 19 09:22:04 2012 +0200
+++ b/Makefile Tue Jun 19 09:26:40 2012 +0200
@@ -3,8 +3,29 @@
sbindir = ${prefix}/sbin
.PHONY: all install clean
-all:
+
+all: update-serial
+
install:
- install -m 0755 update-serial $(DESTDIR)/${sbindir}/
+ install -d -m 0755 $(DESTDIR)/${sbindir}
+ install -m 0755 update-serial $(DESTDIR)/${sbindir}/
clean:
+ rm -f update-serial
+
+%: %.pl
+ @rc=0; \
+ for p in `cat modules`; do \
+ if ! perl -M$$p -e "" 2>/dev/null; then \
+ echo "*** Need perl module $$p" >&2 ;\
+ rc=1 ;\
+ fi ;\
+ done ;\
+ test $$rc = 0
+ @perl -c $<
+ @test -f .hg_archival.txt \
+ && version=`grep ^node: .hg_archival.txt | cut -f2 -d ' '` \
+ || version=`hg id | cut -f1 -d' '` \
+ &&perl -pe 's/__VERSION__/'$$version'/' $< >$<.tmp
+ @mv -f $<.tmp $@
+ @chmod +x-w $@
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/modules Tue Jun 19 09:26:40 2012 +0200
@@ -0,0 +1,4 @@
+File::Copy
+File::Basename
+Getopt::Long
+Pod::Usage
--- a/update-serial Tue Jun 19 09:22:04 2012 +0200
+++ /dev/null Thu Jan 01 00:00:00 1970 +0000
@@ -1,190 +0,0 @@
-#! /usr/bin/perl
-# (c) 1998 Heiko Schlittermann <heiko@datom.de>
-# (c) 2010 Heiko Schlittermann <hs@schlittermann.de>
-#
-# … 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 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
-
-use strict;
-use warnings;
-
-use File::Copy;
-use File::Basename;
-use Getopt::Long;
-use Pod::Usage;
-
-#my $dnssec_sign = "../dnstools/dnssec-sign";
-my $ME = basename $0;
-
-my $master_dir = "/etc/bind/master";
-my $opt_verbose = 0;
-my $opt_reload = 0;
-my $opt_dnssec = 0;
-
-
-{
- my @cleanup;
- sub cleanup(@) {
- return push @cleanup, @_ if @_;
- unlink @cleanup;
- }
-}
-
-END { cleanup(); }
-
-sub next_serial($);
-
-MAIN: {
-
- GetOptions(
- "verbose!" => \$opt_verbose,
- "yes|reload!" => \$opt_reload,
- "dnssec!" => \$opt_dnssec,
- ) or pod2usage();
-
- 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;
-
- my $changed = 0;
- foreach my $file (@files) {
-
- $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;
-
- 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;
- }
-
- $_ = dirname($stamp_file);
- mkdir or die "mkdir $_: $!\n" if not -d;
-
- my $now = time;
-
- open(my $in, "+<", $file) or do {
- print "??: $!" if $opt_verbose;
- next;
- };
-
- $_ = join "", <$in>;
-
- # this pattern is too complicated
- s/^(?!;)(?<pre> # skip lines starting with comment
- (?:\S+)? # label
- (?:\s+\d+.)? # ttl
- (?:\s+in)? # class
- \s+soa # everything before the SOA
- \s+\S+ # ns
- \s+\S+ # hostmaster
- (?:\s*\()?
- \s+)
- (?<serial>\d{10}) # serial
- /$+{pre} . next_serial($+{serial})/exims or next;
-
- 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 $_;
-
- open(my $out, ">$stamp_file");
- close($out);
-
- print "$file\n" if not $opt_verbose;
-
- $changed++;
- } continue {
- print "\n" if $opt_verbose and defined $file;
- }
-
- 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; }
-
- if ($pidfile) {
- if ($opt_reload) { $_ = "y"; print "** Nameserver will be reloaded\n"; }
- else { print "** Reload now? [Y/n]: "; $_ = <STDIN>; }
- /^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;
- }
-
- $_[0] =~ /(?<date>\d{8})(?<cnt>\d\d)/;
- return $date . sprintf("%02d", $+{cnt}+1) if $date eq $+{date};
- return "${date}00";
-}
-}
-
-__END__
-
-=head1 NAME
-
- update-serial - update the serial numbers or dns zone files
-
-=head1 SYNOPSIS
-
- update-serial [-r] [-v] [file...]
-
-=head1 DESCRIPTION
-
-This script scans DNS (bind9 format) zone files and increments the
-serial number if the file is newer than some timestamp file.
-
-=head1 OPTIONS
-
-=over
-
-=item B<-r>|B<--reload>
-
-Automatically reload the bind (rndc reload) if some changes are applied.
-(default: off)
-
-=item B<-v>|B<--verbose>
-
-Be more verbose about the actions we're doing. (default: off)
-
-=back
-
-=head1 AUTHOR
-
- Heiko Schlittermann <hs@schlittermann.de>
- Andre Suess (dnssec specific parts)
-
-=cut
-
-# vim:ts=4:sw=4:ai:aw:
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/update-serial.pl Tue Jun 19 09:26:40 2012 +0200
@@ -0,0 +1,232 @@
+#! /usr/bin/perl
+# (c) 1998 Heiko Schlittermann <heiko@datom.de>
+# (c) 2010 Heiko Schlittermann <hs@schlittermann.de>
+#
+# … 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 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
+
+use strict;
+use warnings;
+use 5.010;
+
+use File::Copy;
+use File::Basename;
+use Getopt::Long;
+use Pod::Usage;
+
+#my $dnssec_sign = "../dnstools/dnssec-sign";
+my $ME = basename $0;
+my $VERSION = '__VERSION__';
+my $URL = "https://keller.schlittermann.de/hg/ius/update-serial";
+
+my $master_dir = "/etc/bind/master";
+my $opt_verbose = 0;
+my $opt_reload = 0;
+my $opt_dnssec = 0;
+
+{
+
+ # remove temporary files
+ my @cleanup;
+
+ sub cleanup(@) {
+ return push @cleanup, @_ if @_;
+ unlink @cleanup;
+ }
+}
+
+sub next_serial($);
+
+END { cleanup(); }
+$SIG{INT} = sub { exit 1 };
+
+MAIN: {
+
+ GetOptions(
+ "v|verbose!" => \$opt_verbose,
+ "y|r|yes|reload!" => \$opt_reload,
+ "dnssec!" => \$opt_dnssec,
+ "h|help" => sub { pod2usage(-exit => 0, -verbose => 1) },
+ "m|man" => sub {
+ pod2usage(
+ -noperldoc => system("perldoc -V &>/dev/null"),
+ -exit => 0,
+ -verbose => 2
+ );
+ },
+ "version" => sub { print "$0 version:$VERSION from $URL\n"; exit 0; },
+ ) or pod2usage();
+
+ 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;
+
+ my $changed = 0;
+ foreach my $file (@files) {
+
+ $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;
+
+ 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;
+ }
+
+ $_ = dirname($stamp_file);
+ mkdir or die "mkdir $_: $!\n" if not -d;
+
+ my $now = time;
+
+ open(my $in, "+<", $file) or do {
+ print "??: $!" if $opt_verbose;
+ next;
+ };
+
+ $_ = join "", <$in>;
+
+ # this pattern is too complicated
+ s/^(?!;)(?<pre> # skip lines starting with comment
+ (?:\S+)? # label
+ (?:\s+\d+.)? # ttl
+ (?:\s+in)? # class
+ \s+soa # everything before the SOA
+ \s+\S+ # ns
+ \s+\S+ # hostmaster
+ (?:\s*\()?
+ \s+)
+ (?<serial>\d{10}) # serial
+ /$+{pre} . next_serial($+{serial})/exims or next;
+
+ 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 $_;
+ close($in);
+
+ # touch the stamp
+ open(my $out, ">$stamp_file");
+ close($out);
+
+ print "$file\n" if not $opt_verbose;
+
+ $changed++;
+ }
+ continue {
+ print "\n" if $opt_verbose and defined $file;
+ }
+
+ 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;
+ }
+
+ if ($pidfile) {
+ if ($opt_reload) {
+ $_ = "y";
+ print "** Nameserver will be reloaded\n";
+ }
+ else { print "** Reload now? [Y/n]: "; $_ = <STDIN>; }
+ /^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;
+ }
+
+ $_[0] =~ /(?<date>\d{8})(?<cnt>\d\d)/;
+ return $date . sprintf("%02d", $+{cnt} + 1) if $date eq $+{date};
+ return "${date}00";
+ }
+}
+
+__END__
+
+=head1 NAME
+
+ update-serial - update the serial numbers or dns zone files
+
+=head1 SYNOPSIS
+
+ update-serial [-r] [-v] [file...]
+
+ update-serial -h|--help
+ update-serial -m|--man
+
+=head1 DESCRIPTION
+
+This script scans DNS (bind9 format) zone files and increments the
+serial number if the file is newer than some timestamp file.
+
+=head1 OPTIONS
+
+=over
+
+=item B<-h>|B<--help>
+
+=item B<-m>|B<--man>
+
+Show the reference help / man page. (default: off)
+
+=item B<-r>|B<--reload>
+
+Automatically reload the bind (rndc reload) if some changes are applied.
+(default: off)
+
+=item B<-v>|B<--verbose>
+
+Be more verbose about the actions we're doing. (default: off)
+
+=back
+
+=head1 AUTHOR
+
+The latest sources might be found on
+L<https://keller.schlittermann.de/hg/ius/update-serial>
+
+ Heiko Schlittermann <hs@schlittermann.de>
+ Andre Suess (dnssec specific parts)
+
+
+=cut
+
+# vim:ts=4:sw=4:ai:aw: