-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathzonediff
executable file
·108 lines (83 loc) · 2.12 KB
/
zonediff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#!/usr/bin/env perl
#
# $Id$
#
use strict;
use Getopt::Std;
use vars qw ($opt_h $opt_Z $opt_D $opt_s);
getopts ('hZD:s');
if ($opt_h or ! defined ($ARGV[0])) {
die (<<EOM);
Syntax: $0 [options] zonefile ...
options:
-Z print zone name
-D dir chdir to dir
-s suppress message saying SOA serial not changed
EOM
}
my @files = @ARGV;
my $print_zonename = $opt_Z;
my $dir = $opt_D;
chdir ($dir) or die ("$0: Could not chdir to '$dir': $!\n") if ($dir);
foreach my $file (@files) {
my $header_printed = 0;
my $first = 1;
my $zonename;
# XXX fix this, it is SU.SE filename convention specific
$zonename = $file;
$zonename =~ s/\.\.ZONE$//o;
open (DIFF, "cvs -R diff -u $file |") or die ("$0: popen(cvs -R diff -u $file) failed: $!\n");
my @diff;
my $line;
while ($line = <DIFF>) {
next if ($line !~ /^[+-](.)/o);
next if ($1 eq "+" or $1 eq "-");
# line begins with a + or a -, but not more than one...
push (@diff, $line);
}
close (DIFF);
my @output;
my @saved_soa;
my $saved_soa_str;
foreach $line (@diff) {
if ($line =~ /^([+-])(\S+\s+\d+\s+IN\s+SOA\s+\S+\s\S+\s)(\d+)(\s+\d+\s+\d+\s+\d+\s+\d+)$/o) {
my $action = $1;
my $lhs = $2;
my $serial = $3;
my $rhs = $4;
if ($action eq "-") {
# save parameters
$saved_soa_str = $line;
@saved_soa = ($lhs, $serial, $rhs);
} elsif ($action eq "+") {
if ($serial ne $saved_soa[1]) {
print ("$zonename ") if ($print_zonename);
print ("SOA serial $serial :\n\n");
}
if ($lhs ne $saved_soa[0] or $rhs ne $saved_soa[2]) {
# something more than the serial number changed
print ("$zonename :\n\n") if ($print_zonename);
print ("$saved_soa_str$line\n\n");
}
$header_printed = 1;
} else {
die ("$0: unexpected SOA action, programming error\n");
}
} else {
if ($first) {
if ($print_zonename and ! $header_printed) {
if ($opt_s) {
print ("$zonename :\n\n");
} else {
print ("$zonename (SOA serial not changed) :\n\n");
}
$header_printed = 1;
}
$first = 0;
}
print ($line);
}
}
print ("\n") if ($#files != 0);
}
exit (0);