blob: 412498794a7b3a4e368c1393053eaadb8adf8a7d (
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
|
#!/usr/bin/perl
# Read all the configuration templates in the configuration
# template directory and produce an ordered list of the priority
# of configuration actions
use strict;
use warnings;
use File::Find;
my %priorities;
# Open node file and extract priority and comment if any
sub get_priority {
open( my $f, '<', $_ )
or return;
my $priority;
my $comment;
while (<$f>) {
chomp;
next unless m/^priority:\s(\d+)/;
$priority = $1;
$comment = $1 if (/#(.*)$/);
last;
}
close $f;
return ( $priority, $comment );
}
# Called by find and returns true iff
# file is named node.def
# file contains priority tag
# Side effect: tores resulting line in $priorities hash for display
sub wanted {
return unless ( $_ eq 'node.def' );
my ( $priority, $comment ) = get_priority($File::Find::name);
return unless $priority;
my $dir = $File::Find::dir;
$dir =~ s/^.*\/templates\///;
$dir .= " #" . $comment
if $comment;
# append line to list of entries with same priority
push @{ $priorities{$priority} }, $dir;
return 1;
}
# main program
my $cfgdir = '/opt/vyatta/share/vyatta-cfg/templates';
die "$cfgdir does not exist!" unless -d $cfgdir;
# walk config file tree
find( \&wanted, $cfgdir );
# display resulting priorities
foreach my $key ( sort { $a <=> $b } keys %priorities ) {
my @a = @{ $priorities{$key} };
foreach my $val ( sort @a ) {
print $key, " ", $val, "\n";
}
}
|