From ffce196d7830ed61feb47b3fd5e9255d29648f63 Mon Sep 17 00:00:00 2001 From: Daniil Baturin Date: Wed, 2 Jul 2014 05:21:57 +0200 Subject: Bug #251: add dirty hack for taking config from stdin to config-gen-sets script. --- scripts/vyatta-config-gen-sets.pl | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) (limited to 'scripts') 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; -- cgit v1.2.3