diff options
author | Daniil Baturin <daniil@baturin.org> | 2014-07-02 05:21:57 +0200 |
---|---|---|
committer | Daniil Baturin <daniil@baturin.org> | 2014-07-02 05:21:57 +0200 |
commit | ffce196d7830ed61feb47b3fd5e9255d29648f63 (patch) | |
tree | 202aee27b4a1e7d147ff008b9b9eb5aa389dbd64 /scripts | |
parent | 84c14e0983b3c2b9659af2e701b606e43306ccb2 (diff) | |
download | vyatta-cfg-ffce196d7830ed61feb47b3fd5e9255d29648f63.tar.gz vyatta-cfg-ffce196d7830ed61feb47b3fd5e9255d29648f63.zip |
Bug #251: add dirty hack for taking config from stdin
to config-gen-sets script.
Diffstat (limited to 'scripts')
-rwxr-xr-x | scripts/vyatta-config-gen-sets.pl | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/scripts/vyatta-config-gen-sets.pl b/scripts/vyatta-config-gen-sets.pl index 1863edd..51a474a 100755 --- a/scripts/vyatta-config-gen-sets.pl +++ b/scripts/vyatta-config-gen-sets.pl @@ -27,11 +27,36 @@ use strict; use lib "/opt/vyatta/share/perl5/"; use Vyatta::ConfigLoad; +sub error +{ + my $error = shift; + print "$error\n"; + exit(1); +} + my $conf_file; my $conf_tmp = "/tmp/config.boot.$$"; if (defined $ARGV[0]) { - $conf_file = $ARGV[0]; + if ($ARGV[0] eq "-") { + # The case for using it in a pipe + + # The loader can't handle uncommited changes, + # it treats -/+/> as part of the config and produces garbage + system("cli-shell-api sessionChanged") + or error("Please commit or discard your changes before using \"commands\" filter!"); + + my $input = ""; + while (<>) { + $input .= $_; + } + open(my $fh, '>', $conf_tmp) or die "Could not open file '$conf_tmp' $!"; + print $fh $input; + close $fh; + $conf_file = $conf_tmp; + } else { + $conf_file = $ARGV[0]; + } } else { system("cli-shell-api showCfg --show-active-only > $conf_tmp"); $conf_file = $conf_tmp; |