bin/update-serial
changeset 124 3ba69372dec3
parent 123 942ef82c9673
child 125 9fc40547116d
equal deleted inserted replaced
123:942ef82c9673 124:3ba69372dec3
   330         my $z  = $2;
   330         my $z  = $2;
   331         my $cf = "$cd/$z";
   331         my $cf = "$cd/$z";
   332         my $de = dnssec_enabled $z, "$md/$config{indexzone}/$config{indexzone}";
   332         my $de = dnssec_enabled $z, "$md/$config{indexzone}/$config{indexzone}";
   333         my $suf = $de ? '.signed' : '';
   333         my $suf = $de ? '.signed' : '';
   334         # TODO: assuming that paths in $md and in zone config snippets match somehow
   334         # TODO: assuming that paths in $md and in zone config snippets match somehow
   335         my $zp = "$z/$z$suf";
   335         my $zr = qr{\Q$z/$z$suf\E$};
   336         my $zf = "$md/$z/$z$suf";
   336         my $zf = "$md/$z/$z$suf";
   337 
   337 
   338         my ($files, $changed) = (0, 0);
   338         my ($files, $changed) = (0, 0);
   339         my $czf;
   339         my $czf;
   340         open C, "+<$cf" or die "Cant't open '$cf': $!";
   340         open C, "+<$cf" or die "Cant't open '$cf': $!";
   341         my @lines = <C>; # TODO: deal with race condition?
   341         my @lines = <C>; # TODO: deal with race condition?
       
   342         my @oldlines;
   342         my ($mode, $uid, $gid, $atime, $mtime) = (stat C)[2, 4, 5, 8, 9] or die "Can't stat: $!";
   343         my ($mode, $uid, $gid, $atime, $mtime) = (stat C)[2, 4, 5, 8, 9] or die "Can't stat: $!";
   343         $mode &= 07777;
   344         $mode &= 07777;
   344         for (@lines) {
   345         for (@lines) {
   345             next unless /^\s*file\s+"([^"]*)"\s*;\s*$/;
   346             next unless /^\s*file\s+"([^"]*)"\s*;\s*$/;
   346             $czf = $1;
   347             $czf = $1;
   347             $files++;
   348             $files++;
   348             $_ = qq(\tfile "$zf";\n) and $changed++ unless $czf =~ m#\Q$z/$z$suf\E$#;
   349             unless ($czf =~ /$zr/) {
       
   350                 $changed++;
       
   351                 @oldlines or @oldlines = @lines;
       
   352                 $_ = qq(\tfile "$zf";\n);
       
   353             }
   349         }
   354         }
   350 
   355 
   351         die "Multiple file statements found in '$cf' (maybe inside multiline comments)" if $files > 1;
   356         die "Multiple file statements found in '$cf' (maybe inside multiline comments)" if $files > 1;
   352         next unless $changed;
   357         next unless $changed;
   353 
   358 
   354         # file statement in config snippet doesnt match, so we make a backup first and write a new config
   359         # file statement in config snippet doesnt match, so we make a backup first and write a new config
   355         my $cb = "$cf.bak";
   360         my $cb = "$cf.bak";
   356         open B, ">$cb" or die "Can't open '$cb': $!";
   361         open B, ">$cb" or die "Can't open '$cb': $!";
   357         print B @lines;
   362         print B @oldlines;
   358         close B;
   363         close B;
   359         chown $uid, $gid, $cb or die "Can't 'chown $uid, $gid, $cb': $!";
   364         chown $uid, $gid, $cb or die "Can't 'chown $uid, $gid, $cb': $!";
   360         chmod $mode, $cb or die "Can't 'chmod $mode, $cb': $!";
   365         chmod $mode, $cb or die "Can't 'chmod $mode, $cb': $!";
   361         utime $atime, $mtime, $cb or die "Can't 'utime $atime, $mtime, $cb': $!";
   366         utime $atime, $mtime, $cb or die "Can't 'utime $atime, $mtime, $cb': $!";
   362 
   367