diff options
Diffstat (limited to 'scripts')
| -rwxr-xr-x | scripts/enumeration/existing-interfaces | 4 | ||||
| -rw-r--r-- | scripts/update-priority.pl | 11 | ||||
| -rw-r--r-- | scripts/vyatta-activate-config.pl | 76 | ||||
| -rwxr-xr-x | scripts/vyatta-cfg-cmd-wrapper | 4 | ||||
| -rw-r--r-- | scripts/vyatta-comment-config.pl | 76 | ||||
| -rwxr-xr-x | scripts/vyatta-config-gen-sets.pl | 3 | ||||
| -rwxr-xr-x | scripts/vyatta-config-loader.pl | 40 | ||||
| -rwxr-xr-x | scripts/vyatta-load-config.pl | 44 |
8 files changed, 220 insertions, 38 deletions
diff --git a/scripts/enumeration/existing-interfaces b/scripts/enumeration/existing-interfaces new file mode 100755 index 0000000..1defc22 --- /dev/null +++ b/scripts/enumeration/existing-interfaces @@ -0,0 +1,4 @@ +#!/bin/bash + +ls /sys/class/net 2>/dev/null + diff --git a/scripts/update-priority.pl b/scripts/update-priority.pl index 84b4933..feb1e7f 100644 --- a/scripts/update-priority.pl +++ b/scripts/update-priority.pl @@ -38,7 +38,7 @@ my $prefix = $ARGV[1]; open my $pf, '<', $priority_file or die "$priority_file can't be opened"; while (<$pf>) { chomp; - next if /^#.*/; + next if /^#.*/ or /^$/; die "Syntax Error \"$_\"" unless /^(\d+)\s+(\S+)(|\s+|\s+#.*)$/; $priority = $1; $path = $2; @@ -55,11 +55,12 @@ while (<$pf>) { open my $nf, '<', $node_def or die "$node_def can't be opened"; open my $nfn, '>', "$node_def.new" or die "$node_def.new can't be opened"; while (<$nf>) { - print $nfn $_ if /^(tag|multi):/; - print $nfn $priority_line; - print $nfn $_ unless /^priority:\s(\d+)/ or /^(tag|multi):/; - last if $. == 1; + last unless /^#.*/ or /^$/; + print $nfn $_; } + print $nfn $_ if /^(tag|multi):/; + print $nfn $priority_line if $priority != 0; + print $nfn $_ unless /^priority:\s(\d+)/ or /^(tag|multi):/; while (<$nf>) { print $nfn $_ unless /^priority:\s(\d+)/; } diff --git a/scripts/vyatta-activate-config.pl b/scripts/vyatta-activate-config.pl index 20f704d..3eca90f 100644 --- a/scripts/vyatta-activate-config.pl +++ b/scripts/vyatta-activate-config.pl @@ -27,15 +27,40 @@ use lib "/opt/vyatta/share/perl5"; sub wanted { return unless ( $_ eq '.disable' ); - print("Cannot set nested deactivated nodes\n"); + print("Cannot deactivate nested elements\n"); exit 1; } +sub check_parents { + my @p = @_; + my $l_dir = "$ENV{VYATTA_TEMP_CONFIG_DIR}/"; + my $a_dir = "$ENV{VYATTA_ACTIVE_CONFIGURATION_DIR}/"; + foreach my $sw (@p) { + $l_dir .= "/$sw"; + $a_dir .= "/$sw"; + + if (-e "$l_dir/.disable") { + return 1; + } + if (-e "$a_dir/.disable") { + return 1; + } + } + return 0; +} + sub usage() { print "Usage: $0 <path>\n"; exit 0; } +my $action = $ARGV[0]; + +if (!defined $ARGV[1] || $ARGV[1] eq '') { + print("Cannot activate/deactivate configuration root\n"); + exit 1; +} + #adjust for leaf node my $i = 0; my @path = @ARGV[1..$#ARGV]; @@ -53,7 +78,6 @@ if (! -e $full_path) { my $leaf = "$ENV{VYATTA_TEMP_CONFIG_DIR}/$path/node.val"; if (-e $leaf) { #prevent setting on leaf or multi, check for node.val -# $full_path = "$ENV{VYATTA_TEMP_CONFIG_DIR}/$path"; printf("Cannot activate/deactivate end node\n"); exit 1; } @@ -63,45 +87,53 @@ if (! -e $full_path) { } } +####################################################### +#now check for nesting of the activate/deactivate nodes +####################################################### +if ($action eq 'deactivate') { + my $active_dir = "$ENV{VYATTA_ACTIVE_CONFIGURATION_DIR}/$path"; + my $local_dir = $full_path; + if (-e $active_dir) { #checks active children + find( \&wanted, $active_dir ); + } + if (-e $local_dir) { #checks locally commit children + find( \&wanted, $local_dir ); + } + #final check that walks up tree and checks + if (check_parents(@path)) { #checks active and locally committed parents + print("Cannot deactivate nested elements\n"); + exit 1; + } +} -if ($ARGV[0] eq 'activate') { +####################################################### +#now apply the magic +####################################################### +if ($action eq 'activate') { $full_path .= "/.disable"; if (-e $full_path) { `rm -f $full_path`; } else { - printf("This element is not deactivated.\n"); + printf("This element has not been deactivated\n"); exit 1; } } -elsif ($ARGV[0] eq 'deactivate') { +elsif ($action eq 'deactivate') { #first let's check and ensure that there is not another child .disable node... #also needs to be enforced when committing my $active_dir = "$ENV{VYATTA_ACTIVE_CONFIGURATION_DIR}/$path"; my $local_dir = $full_path; - if (-e $active_dir) { - find( \&wanted, $active_dir ); - } - if (-e $local_dir) { - find( \&wanted, $local_dir ); + if (-e "$active_dir/.disable" || -e "$local_dir/.disable") { + printf("This element has already been deactivated\n"); + exit 1; } `touch $full_path/.disable`; } -elsif ($ARGV[0] eq 'complete') { - #provide match... - printf("complete\n"); -} else { - printf("incoming arg: " . $ARGV[0] . "\n"); + printf("bad argument: " . $action . "\n"); usage(); } -#if this is activate -# make sure no activate subnodes -# create .disable file in node -#else -# ensure .disable file exists -# remove node - print "Done\n"; exit 0; diff --git a/scripts/vyatta-cfg-cmd-wrapper b/scripts/vyatta-cfg-cmd-wrapper index 3b2f040..4941e37 100755 --- a/scripts/vyatta-cfg-cmd-wrapper +++ b/scripts/vyatta-cfg-cmd-wrapper @@ -220,6 +220,10 @@ case "$1" in /opt/vyatta/sbin/vyatta-activate-config.pl activate "${@:2}" RET_STATUS=$? ;; + comment) + /opt/vyatta/sbin/vyatta-comment-config.pl "${@:2}" + RET_STATUS=$? + ;; commit) # debug file /tmp/bar should be deleted before release /opt/vyatta/sbin/my_commit -a >> /tmp/bar diff --git a/scripts/vyatta-comment-config.pl b/scripts/vyatta-comment-config.pl new file mode 100644 index 0000000..ab3191e --- /dev/null +++ b/scripts/vyatta-comment-config.pl @@ -0,0 +1,76 @@ +#!/usr/bin/perl + +# Author: Michael Larson <mike@vyatta.com> +# Date: 2010 +# Description: Perl script for adding comments to portions of the configuration + +# **** License **** +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# This code was originally developed by Vyatta, Inc. +# Portions created by Vyatta are Copyright (C) 2006, 2007, 2008, 2009, 2010 Vyatta, Inc. +# All Rights Reserved. +# **** End License **** + +use strict; +use warnings; +use File::Find; +use lib "/opt/vyatta/share/perl5"; + + +sub usage() { + print "Usage: $0 <path>\n"; + exit 0; +} + +if ($#ARGV == 0) { + exit 0; +} + +#adjust for leaf node +my $i = 0; +my @path = @ARGV[0..$#ARGV-1]; +foreach my $elem (@path) { + $elem =~ s/\//%2F/g; + $elem =~ s/\s+/\//g; + $path[$i++] = $elem; +} +my $path = join '/', @path; + +my $full_path = "$ENV{VYATTA_TEMP_CONFIG_DIR}/$path"; + +if (! -e $full_path) { + $path = join '/', @path[0..$#path-1]; + my $leaf = "$ENV{VYATTA_TEMP_CONFIG_DIR}/$path/node.val"; + if (-e $leaf) { + $full_path = "$ENV{VYATTA_TEMP_CONFIG_DIR}/$path"; + } + else { + `echo \"Path is not valid\n\"`; + exit 0; + } +} + +#scan for illegal characters here: '/*', '*/' +if ($ARGV[$#ARGV] =~ /\/\*|\*\//) { + print "illegal characters found in comment\n"; + exit 1; +} + + +if ($ARGV[$#ARGV] eq '') { + `rm -f $full_path/.comment`; +} +else { + `echo \"$ARGV[$#ARGV]\" > $full_path/.comment`; +} + +print "Done\n"; +exit 0; diff --git a/scripts/vyatta-config-gen-sets.pl b/scripts/vyatta-config-gen-sets.pl index e364dfa..7cf4feb 100755 --- a/scripts/vyatta-config-gen-sets.pl +++ b/scripts/vyatta-config-gen-sets.pl @@ -32,7 +32,8 @@ my $conf_file = '/opt/vyatta/etc/config/config.boot'; $conf_file = $ARGV[0] if defined $ARGV[0]; # get a list of all config statement in the startup config file -my @all_nodes = Vyatta::ConfigLoad::getStartupConfigStatements($conf_file); +my %cfg_hier = Vyatta::ConfigLoad::getStartupConfigStatements($conf_file); +my @all_nodes = @{ $cfg_hier{'set'} }; if (scalar(@all_nodes) == 0) { # no config statements exit 1; diff --git a/scripts/vyatta-config-loader.pl b/scripts/vyatta-config-loader.pl index 7a3df2b..0aae55b 100755 --- a/scripts/vyatta-config-loader.pl +++ b/scripts/vyatta-config-loader.pl @@ -46,7 +46,9 @@ sub restore_fds { } # get a list of all config statement in the startup config file -my @all_nodes = Vyatta::ConfigLoad::getStartupConfigStatements($ARGV[0]); +my %cfg_hier = Vyatta::ConfigLoad::getStartupConfigStatements($ARGV[0],'true'); +my @all_nodes = @{ $cfg_hier{'set'} }; +my @deactivate_nodes = @{ $cfg_hier{'deactivate'} }; if (scalar(@all_nodes) == 0) { # no config statements restore_fds(); @@ -72,11 +74,30 @@ foreach (@all_nodes) { my ($path_ref, $rank) = @$_; my @pr = @$path_ref; - if (@pr[0] eq '!') { - @pr = @pr[1..$#pr]; - my $deactivate_cmd = "$CWRAPPER deactivate " . (join ' ', @pr) . " 1>/dev/null"; - system("$deactivate_cmd"); - #ignore these errors due to nesting warnings. + if (@pr[0] =~ /^comment$/) { + my $ct = 0; + my $rel_path; + foreach my $rp (@pr[1..$#pr]) { + $ct++; + my $tmp_path = $rel_path . "/" . $rp; + my $node_path = "/opt/vyatta/share/vyatta-cfg/templates/" . $tmp_path . "/node.def"; + if ($rp eq '"') { + last; + } + elsif ($rp eq '""') { + last; + } + elsif (!-e $node_path) { + #pop this element + delete @pr[$ct]; + last; + } + $rel_path = $tmp_path; + } + + my $comment_cmd = "$CWRAPPER " . join(" ",@pr) ; + `$comment_cmd`; + next; } my $cmd = "$CWRAPPER set " . (join ' ', @pr); @@ -90,6 +111,13 @@ foreach (@all_nodes) { # continue after set failure (or should we abort?) } } + +# Now deactivate these nodes +for (@deactivate_nodes) { + my $cmd = "$CWRAPPER deactivate " . $_ . " 1>/dev/null"; + system("$cmd"); +} + $ret = system("$commit_cmd"); if ($ret >> 8) { print OLDOUT "Commit failed at boot\n"; diff --git a/scripts/vyatta-load-config.pl b/scripts/vyatta-load-config.pl index ab5a47e..296dc0d 100755 --- a/scripts/vyatta-load-config.pl +++ b/scripts/vyatta-load-config.pl @@ -191,6 +191,7 @@ if ( scalar( keys %cfg_hier ) == 0 ) { my %cfg_diff = Vyatta::ConfigLoad::getConfigDiff( \%cfg_hier ); my @set_list = @{ $cfg_diff{'set'} }; my @deactivate_list = @{ $cfg_diff{'deactivate'} }; +my @comment_list = @{ $cfg_diff{'comment'} }; if ($merge_mode eq 'false') { my @delete_list = @{ $cfg_diff{'delete'} }; @@ -219,10 +220,45 @@ foreach (@set_list) { } foreach (@deactivate_list) { - my ( $cmd_ref, $rank ) = @{$_}; - my @cmd = ( "$sbindir/vyatta-activate-config.pl deactivate", @{$cmd_ref} ); - my $cmd_str = join ' ', @cmd; - system("$cmd_str 1>/dev/null"); + #need to remove .disable nodes recursively in tree through activate command + my $cmd = "$sbindir/vyatta-activate-config.pl deactivate $_"; + system("$cmd 1>/dev/null"); + #ignore error on complaint re: nested nodes +} + +foreach (@comment_list) { + my ( $cmd_ref ) = $_; + #apply comment if it doesn't have an empty element at the array and a .comment file exists and this is not a merge + if ($merge_mode eq 'false' && $cmd_ref =~ /\"\"$/) { + my @cmd_array = split(" ",$cmd_ref); + pop(@cmd_array); + my $rel_path = join '/', @cmd_array; + my $path = "/opt/vyatta/config/active/" . $rel_path . "/.comment"; + if (-e $path) { + my @cmd = ( "$sbindir/vyatta-comment-config.pl ", $cmd_ref ); + my $cmd_str = join ' ', @cmd; + system("$cmd_str 1>/dev/null"); + } + else { + #not found, maybe a leaf? + pop(@cmd_array); + $rel_path = join '/', @cmd_array; + my $leaf = "/opt/vyatta/config/active/" . $rel_path . "/node.val"; + if (-e $leaf) { + $path = "/opt/vyatta/config/active/" . $rel_path . "/.comment"; + if (-e $path) { + my @cmd = ( "$sbindir/vyatta-comment-config.pl ", $cmd_ref ); + my $cmd_str = join ' ', @cmd; + system("$cmd_str 1>/dev/null"); + } + } + } + } + else { + my @cmd = ( "$sbindir/vyatta-comment-config.pl ", $cmd_ref ); + my $cmd_str = join ' ', @cmd; + system("$cmd_str 1>/dev/null"); + } #ignore error on complaint re: nested nodes } |
