summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/priority.pl65
1 files changed, 38 insertions, 27 deletions
diff --git a/scripts/priority.pl b/scripts/priority.pl
index 39f6220..3f5804f 100644
--- a/scripts/priority.pl
+++ b/scripts/priority.pl
@@ -1,39 +1,50 @@
#!/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 %pri;
-# Look at all node.def files in the configuration template tree
-my @files = `find /opt/vyatta/share/vyatta-cfg -name 'node.def'`;
-foreach my $f (@files) {
- my $result = `grep 'priority:' $f`;
- if (defined $result && length($result) != 0) {
- my @r = split " ", $result;
- if (defined $r[1]) {
- # Strip off trailing "/node.def\n" from file pathname
- my $line = substr($f, 0, -10);
-
- # Strip off leading "/opt/vyatta/share/vyatta-cfg/templates/"
- $line = substr($line, 39);
-
- # See if there is a comment in entry
- my ($entry, $comment) = split /#/, $result;
- if (defined $comment) {
- $comment =~ s/\n//;
- $line = $line . " #" . $comment;
- }
-
- # stuff resulting line into hash
- push @{$pri{$r[1]}}, $line;
- }
+sub get_priority {
+ open( my $f, '<', $_ )
+ or return;
+ my $priority;
+
+ while (<$f>) {
+ chomp;
+ next unless m/^priority:\s(\d+)/;
+ $priority = $1;
+ last;
}
+ close $f;
+ return $priority;
}
+sub wanted {
+ return unless ( $_ eq 'node.def' );
+
+ my $p = get_priority($File::Find::name);
+ return unless $p;
-#now sort
+ my $dir = $File::Find::dir;
+ $dir =~ s/^.*\/templates\///;
+
+ push @{ $pri{$p} }, $dir;
+ return 1;
+}
+
+my $cfgdir = '/opt/vyatta/share/vyatta-cfg/templates';
+die "$cfgdir does not exist!" unless -d $cfgdir;
+find( \&wanted, $cfgdir );
foreach my $key ( sort { $a <=> $b } keys %pri ) {
- my @a = @{$pri{$key}};
+ my @a = @{ $pri{$key} };
foreach my $val (@a) {
- print $key," ",$val,"\n";
+ print $key, " ", $val, "\n";
}
-}
+}