summaryrefslogtreecommitdiff
path: root/scripts/vyatta-load-config.pl
diff options
context:
space:
mode:
authorAn-Cheng Huang <ancheng@vyatta.com>2007-09-25 15:55:26 -0700
committerAn-Cheng Huang <ancheng@vyatta.com>2007-09-25 15:55:26 -0700
commite9a79a249cec69fc178098d2f75db9389068510a (patch)
tree0e366094b7fecd3988c243fbbb574015e0c900c8 /scripts/vyatta-load-config.pl
downloadvyatta-cfg-e9a79a249cec69fc178098d2f75db9389068510a.tar.gz
vyatta-cfg-e9a79a249cec69fc178098d2f75db9389068510a.zip
initial import (from eureka /cli) plus new build system.upstream
Diffstat (limited to 'scripts/vyatta-load-config.pl')
-rwxr-xr-xscripts/vyatta-load-config.pl69
1 files changed, 69 insertions, 0 deletions
diff --git a/scripts/vyatta-load-config.pl b/scripts/vyatta-load-config.pl
new file mode 100755
index 0000000..7a1e01d
--- /dev/null
+++ b/scripts/vyatta-load-config.pl
@@ -0,0 +1,69 @@
+#!/usr/bin/perl
+# Perl script for loading config file at run time.
+# $0: config file.
+
+use strict;
+use lib "/opt/vyatta/share/perl5/";
+use VyattaConfigLoad;
+
+my $etcdir = $ENV{ofr_sysconfdir};
+my $bootpath = '';
+if (-r "$etcdir/bootfile_path") {
+ $bootpath = `cat $etcdir/bootfile_path`;
+}
+$bootpath =~ s/\/[^\/]+$//;
+
+if ($#ARGV != 0) {
+ print "Usage: load <config_file_name>\n";
+ exit 1;
+}
+
+my $load_file = $ARGV[0];
+if (!($load_file =~ /^\//)) {
+ # relative path
+ $load_file = "$bootpath/$load_file";
+}
+
+print "Loading config file $load_file...\n";
+my %cfg_hier = VyattaConfigLoad::loadConfigHierarchy($load_file);
+if (scalar(keys %cfg_hier) == 0) {
+ print "Load failed\n";
+ exit 1;
+}
+
+my %cfg_diff = VyattaConfigLoad::getConfigDiff(\%cfg_hier);
+
+my @delete_list = @{$cfg_diff{'delete'}};
+my @set_list = @{$cfg_diff{'set'}};
+
+foreach (@delete_list) {
+ my ($cmd_ref, $rank) = @{$_};
+ my @cmd = ( 'my_delete', @{$cmd_ref} );
+ my $cmd_str = join ' ', @cmd;
+ system("$cmd_str");
+ if ($? >> 8) {
+ $cmd_str =~ s/^my_//;
+ print "\"$cmd_str\" failed\n";
+ }
+}
+
+foreach (@set_list) {
+ my ($cmd_ref, $rank) = @{$_};
+ my @cmd = ( 'my_set', @{$cmd_ref} );
+ my $cmd_str = join ' ', @cmd;
+ system("$cmd_str");
+ if ($? >> 8) {
+ $cmd_str =~ s/^my_//;
+ print "\"$cmd_str\" failed\n";
+ }
+}
+
+system("my_commit");
+if ($? >> 8) {
+ print "Load failed (commit failed)\n";
+ exit 1;
+}
+
+print "Done\n";
+exit 0;
+