summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorAlex Harpin <development@landsofshadow.co.uk>2015-07-11 15:31:34 +0100
committerAlex Harpin <development@landsofshadow.co.uk>2015-07-11 15:31:34 +0100
commit33905c946dbe88d9e5c32ee7403c60daecc1e910 (patch)
tree31497794decbfff6d3aed8baa8f451129f965819 /scripts
parentcabc1522bca2e68981689dd147b41e5a28f3453e (diff)
downloadvyatta-cfg-33905c946dbe88d9e5c32ee7403c60daecc1e910.tar.gz
vyatta-cfg-33905c946dbe88d9e5c32ee7403c60daecc1e910.zip
vyatta-cfg: formatting changes for style consistency
Perltidy run on scripts/vyatta-config-loader.pl and scripts/vyatta-save-config.pl to have consistent identation levels and style throughout.
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/vyatta-config-loader.pl89
-rwxr-xr-xscripts/vyatta-save-config.pl140
2 files changed, 114 insertions, 115 deletions
diff --git a/scripts/vyatta-config-loader.pl b/scripts/vyatta-config-loader.pl
index c5a1164..9e296ad 100755
--- a/scripts/vyatta-config-loader.pl
+++ b/scripts/vyatta-config-loader.pl
@@ -8,12 +8,12 @@
# 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 Vyatta, Inc.
# All Rights Reserved.
@@ -40,11 +40,11 @@ umask 0002;
# Set up logging
openlog("config-loader", "nofail", LOG_LOCAL0);
-open (STDIN, '<', "/dev/null")
+open(STDIN, '<', "/dev/null")
or die "Can't open /dev/null : $!";
-open (STDOUT, '>>', $CONFIG_LOG)
+open(STDOUT, '>>', $CONFIG_LOG)
or die "Can't open $CONFIG_LOG : $!";
-open (STDERR, '>&STDOUT')
+open(STDERR, '>&STDOUT')
or die "Can't redirect stderr: $!";
sub trace {
@@ -55,7 +55,7 @@ sub trace {
# get a list of all config statement in the startup config file
my %cfg_hier = Vyatta::ConfigLoad::getStartupConfigStatements($ARGV[0],'true');
-my @all_nodes = @{ $cfg_hier{'set'} };
+my @all_nodes = @{$cfg_hier{'set'}};
# empty configuration?
die "Empty configuration!\n"
@@ -76,28 +76,28 @@ foreach (@all_nodes) {
my @pr = @$path_ref;
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";
-
- last if ($rp eq '"');
- last if ($rp eq '""');
-
- if ( !-e $node_path ) {
- #pop this element
- delete $pr[$ct];
- last;
- }
- $rel_path = $tmp_path;
- }
-
- my $comment_cmd = "$CWRAPPER " . join(" ",@pr) ;
- `$comment_cmd`;
- next;
+ 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";
+
+ last if ($rp eq '"');
+ last if ($rp eq '""');
+
+ if (!-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 = 'set ' . join(' ', @pr);
@@ -105,8 +105,8 @@ foreach (@all_nodes) {
# Show all commands in log
trace $cmd;
unless (system("$CWRAPPER $cmd") == 0) {
- warn "*** %s failed: %d\n", $cmd, $?;
- syslog(LOG_NOTICE, "[[%s]] failed", $cmd);
+ warn "*** %s failed: %d\n", $cmd, $?;
+ syslog(LOG_NOTICE, "[[%s]] failed", $cmd);
}
}
@@ -116,7 +116,7 @@ syslog(LOG_INFO, "Configuration took %d seconds.", $commit_start - $start);
unless (system($COMMIT_CMD) == 0) {
warn "*** Commit failed: %d\n", $?;
- syslog (LOG_WARNING, "Commit failed at boot");
+ syslog(LOG_WARNING, "Commit failed at boot");
system($CLEANUP_CMD);
system($END_CMD);
@@ -124,27 +124,26 @@ unless (system($COMMIT_CMD) == 0) {
}
my $commit_end = time;
-syslog(LOG_INFO, "Commit succeeded took %d seconds.",
- $commit_end - $commit_start);
+syslog(LOG_INFO, "Commit succeeded took %d seconds.",$commit_end - $commit_start);
# Now process any deactivate nodes
-my @deactivate_nodes = @{ $cfg_hier{'deactivate'} };
+my @deactivate_nodes = @{$cfg_hier{'deactivate'}};
if (@deactivate_nodes) {
foreach (@deactivate_nodes) {
- my $cmd = "deactivate " . $_;
- trace $cmd;
-
- unless (system("$CWRAPPER $cmd") == 0) {
- warn "*** %s failed: %d\n", $cmd, $?;
- syslog(LOG_WARNING, "[[%s]] failed", $cmd);
- last;
- }
+ my $cmd = "deactivate " . $_;
+ trace $cmd;
+
+ unless (system("$CWRAPPER $cmd") == 0) {
+ warn "*** %s failed: %d\n", $cmd, $?;
+ syslog(LOG_WARNING, "[[%s]] failed", $cmd);
+ last;
+ }
}
unless (system($COMMIT_CMD) == 0) {
- warn "deactivate commit failed: %d\n", $?;
- syslog(LOG_NOTICE, "Commit deactivate failed at boot");
- system($CLEANUP_CMD);
+ warn "deactivate commit failed: %d\n", $?;
+ syslog(LOG_NOTICE, "Commit deactivate failed at boot");
+ system($CLEANUP_CMD);
}
}
diff --git a/scripts/vyatta-save-config.pl b/scripts/vyatta-save-config.pl
index b397195..96dd4b1 100755
--- a/scripts/vyatta-save-config.pl
+++ b/scripts/vyatta-save-config.pl
@@ -8,12 +8,12 @@
# 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 Vyatta, Inc.
# All Rights Reserved.
@@ -34,84 +34,84 @@ my $url_tmp_file = $bootpath . "/config.boot.$$";
my $show_default = 1;
if ($#ARGV > 1) {
- print "Usage: save [config_file_name] --no-defaults\n";
- exit 1;
+ print "Usage: save [config_file_name] --no-defaults\n";
+ exit 1;
}
-
if (defined($ARGV[0])) {
if ($ARGV[0] ne '--no-defaults') {
- $save_file = $ARGV[0];
- }
- else {
- $show_default = 0;
+ $save_file = $ARGV[0];
+ }else {
+ $show_default = 0;
}
if (defined($ARGV[1]) && $ARGV[1] eq '--no-defaults') {
- $show_default = 0;
+ $show_default = 0;
}
}
-
my $mode = 'local';
my $proto;
if ($save_file =~ /^[^\/]\w+:\//) {
- if ($save_file =~ /^(\w+):\/\/\w/) {
- $mode = 'url';
- $proto = lc($1);
- if ($proto eq 'tftp') {
- } elsif ($proto eq 'ftp') {
- } elsif ($proto eq 'scp') {
+ if ($save_file =~ /^(\w+):\/\/\w/) {
+ $mode = 'url';
+ $proto = lc($1);
+ if ($proto eq 'tftp') {
+ } elsif ($proto eq 'ftp') {
+ } elsif ($proto eq 'scp') {
+ } else {
+ print "Invalid url protocol [$proto]\n";
+ exit 1;
+ }
} else {
- print "Invalid url protocol [$proto]\n";
- exit 1;
+ print "Invalid url [$save_file]\n";
+ exit 1;
}
- } else {
- print "Invalid url [$save_file]\n";
- exit 1;
- }
}
if ($mode eq 'local' and !($save_file =~ /^\//)) {
- # relative path
- $save_file = "$bootpath/$save_file";
+
+ # relative path
+ $save_file = "$bootpath/$save_file";
}
my $version_str = `/opt/vyatta/sbin/vyatta_current_conf_ver.pl`;
+
# when presenting to users, show shortened /config path
my $shortened_save_file = get_short_config_path($save_file);
print "Saving configuration to '$shortened_save_file'...\n";
my $save;
if ($mode eq 'local') {
+
# first check if this file exists, and if so ensure this is a config file.
if (-e $save_file) {
- my $result = `grep ' === vyatta-config-version:' $save_file`;
- if (!defined $result || length($result) == 0) {
- print "File exists and is not a Vyatta configuration file, aborting save!\n";
- exit 1;
- }
+ my $result = `grep ' === vyatta-config-version:' $save_file`;
+ if (!defined $result || length($result) == 0) {
+ print "File exists and is not a Vyatta configuration file, aborting save!\n";
+ exit 1;
+ }
}
# this overwrites the file if it exists. we could create a backup first.
open $save, '>', $save_file
- or die "Can not open file '$save_file': $!\n";
+ or die "Can not open file '$save_file': $!\n";
} elsif ($mode eq 'url') {
- die "Package [curl] not installed\n" unless ( -f '/usr/bin/curl');
+ die "Package [curl] not installed\n" unless (-f '/usr/bin/curl');
open $save, '>', $url_tmp_file
- or die "Cannot open file '$url_tmp_file': $!\n";
+ or die "Cannot open file '$url_tmp_file': $!\n";
}
select $save;
my $show_cmd = 'cli-shell-api showConfig --show-active-only --show-ignore-edit';
if ($show_default) {
- $show_cmd .= ' --show-show-defaults';
+ $show_cmd .= ' --show-show-defaults';
}
open(my $show_fd, '-|', $show_cmd) or die 'Cannot execute config output';
while (<$show_fd>) {
- print;
+ print;
}
close($show_fd);
print $version_str;
@@ -122,41 +122,41 @@ close $save;
if ($mode eq 'url') {
- my $rc = 0;
- if ($proto eq 'scp' ){
- $save_file =~ m/scp:\/\/(.*?)\//;
- my $host = $1;
- my $user = getpwuid($<);
- if ($host =~ m/(.*)@(.*)/) {
- $user = $1;
- $host = $2;
- }
-
- $rc = system("curl -u $user -# -T $url_tmp_file $save_file");
- if( $rc >> 8 == 51 ){
- my $rsa_key = `ssh-keyscan -t rsa $host 2>/dev/null`;
- print "The authenticity of host '$host' can't be established.\n";
- my $fingerprint = `ssh-keygen -lf /dev/stdin <<< \"$rsa_key\" | awk {' print \$2 '}`;
- chomp $fingerprint;
- print "RSA key fingerprint is $fingerprint.\n";
- if (prompt("Are you sure you want to continue connecting (yes/no) [Yes]? ", -tynd=>"y")) {
- mkdir "$ENV{HOME}/.ssh/",0700 unless -d "$ENV{HOME}/.ssh";
- open(my $known_hosts, ">>", "$ENV{HOME}/.ssh/known_hosts")
- or die "Cannot open known_hosts: $!";
- print $known_hosts "$rsa_key\n";
- close($known_hosts);
- $rc = system("curl -u $user -# -T $url_tmp_file $save_file");
- print "\n";
- }
- }
- } else {
- $rc = system("curl -# -T $url_tmp_file $save_file");
- }
- system("rm -f $url_tmp_file");
- if ($rc) {
- print "Error saving $save_file\n";
- exit 1;
- }
+ my $rc = 0;
+ if ($proto eq 'scp'){
+ $save_file =~ m/scp:\/\/(.*?)\//;
+ my $host = $1;
+ my $user = getpwuid($<);
+ if ($host =~ m/(.*)@(.*)/) {
+ $user = $1;
+ $host = $2;
+ }
+
+ $rc = system("curl -u $user -# -T $url_tmp_file $save_file");
+ if($rc >> 8 == 51){
+ my $rsa_key = `ssh-keyscan -t rsa $host 2>/dev/null`;
+ print "The authenticity of host '$host' can't be established.\n";
+ my $fingerprint = `ssh-keygen -lf /dev/stdin <<< \"$rsa_key\" | awk {' print \$2 '}`;
+ chomp $fingerprint;
+ print "RSA key fingerprint is $fingerprint.\n";
+ if (prompt("Are you sure you want to continue connecting (yes/no) [Yes]? ", -tynd=>"y")) {
+ mkdir "$ENV{HOME}/.ssh/",0700 unless -d "$ENV{HOME}/.ssh";
+ open(my $known_hosts, ">>", "$ENV{HOME}/.ssh/known_hosts")
+ or die "Cannot open known_hosts: $!";
+ print $known_hosts "$rsa_key\n";
+ close($known_hosts);
+ $rc = system("curl -u $user -# -T $url_tmp_file $save_file");
+ print "\n";
+ }
+ }
+ } else {
+ $rc = system("curl -# -T $url_tmp_file $save_file");
+ }
+ system("rm -f $url_tmp_file");
+ if ($rc) {
+ print "Error saving $save_file\n";
+ exit 1;
+ }
}
print "Done\n";