blob: 54d9e5ef673c11bc1a52121637eb2df74e5c89d2 (
plain)
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
|
#! /usr/bin/env perl
#
use strict;
use File::Basename;
use File::Copy;
use File::Path qw(make_path);
use autodie;
# install-mib FILE DIR
die "bad number of arguments" unless $#ARGV == 1;
my ($file, $destdir) = @ARGV;
my $mibname;
open(my $fd, '<', $file);
while (<$fd>) {
s/^\s+//;
if (/([\S]+)\s+DEFINITIONS\s+::=\s+BEGIN\s*$/) {
$mibname = $1;
last;
}
}
close($fd);
die "no MIB definition in $file" unless defined $mibname;
make_path($destdir) unless -e $destdir;
copy($file, $destdir);
my $index = "$destdir/.index";
my $tmpname = $index . $$;
open(my $ofd, '>', $tmpname);
my $modified;
$file = basename($file);
if (-e $index) {
open($fd, '+<', $index);
while (<$fd>) {
if (defined($mibname) and /^${mibname}\s+/) {
chomp;
my @a = split /\s+/;
unless ($#a == 1 and $a[1] eq $file) {
print $ofd "$mibname $file\n";
$modified = 1;
}
$mibname = undef;
} else {
print $ofd $_;
}
}
close($fd);
}
if (defined($mibname)) {
print $ofd "$mibname $file\n";
$modified = 1;
}
close $ofd;
if ($modified) {
unlink $index if -e $index;
rename $tmpname, $index;
} else {
unlink $tmpname;
}
|