diff options
author | rbalocca <rbalocca@vyatta.com> | 2008-06-29 18:05:08 -0700 |
---|---|---|
committer | rbalocca <rbalocca@vyatta.com> | 2008-06-29 18:05:08 -0700 |
commit | 7db066e99a5e9c3b41ce30d19b9781b1a8df8d44 (patch) | |
tree | 75da49d74a9da7cb6df98651ef511ddd12a42790 /scripts/vyatta-load-config.pl | |
parent | dd1921164c972be0333d8b90f7c12f31f67a136e (diff) | |
parent | 3b1043be67c60220c107e42998635c628eb84393 (diff) | |
download | vyatta-cfg-7db066e99a5e9c3b41ce30d19b9781b1a8df8d44.tar.gz vyatta-cfg-7db066e99a5e9c3b41ce30d19b9781b1a8df8d44.zip |
Merge branch 'hollywood'
Diffstat (limited to 'scripts/vyatta-load-config.pl')
-rwxr-xr-x | scripts/vyatta-load-config.pl | 75 |
1 files changed, 69 insertions, 6 deletions
diff --git a/scripts/vyatta-load-config.pl b/scripts/vyatta-load-config.pl index 05323e3..29d4dec 100755 --- a/scripts/vyatta-load-config.pl +++ b/scripts/vyatta-load-config.pl @@ -28,21 +28,84 @@ use VyattaConfigLoad; my $etcdir = $ENV{vyatta_sysconfdir}; my $sbindir = $ENV{vyatta_sbindir}; my $bootpath = $etcdir . "/config"; +my $load_file = $bootpath . "/config.boot"; +my $url_tmp_file = $bootpath . "/config.boot.$$"; -if ($#ARGV != 0) { +if ($#ARGV > 0) { print "Usage: load <config_file_name>\n"; exit 1; } -my $load_file = $ARGV[0]; -if (!($load_file =~ /^\//)) { +my $mode = 'local'; +my $proto; + +if (defined($ARGV[0])) { + $load_file = $ARGV[0]; +} + +if ($load_file =~ /^[^\/]\w+:\//) { + if ($load_file =~ /^(\w+):\/\/\w/) { + $mode = 'url'; + $proto = lc($1); + if ($proto eq 'tftp') { + } elsif ($proto eq 'ftp') { + } elsif ($proto eq 'http') { + } elsif ($proto eq 'scp') { + } else { + print "Invalid url protocol [$proto]\n"; + exit 1; + } + } else { + print "Invalid url [$load_file]\n"; + exit 1; + } +} + +if ($mode eq 'local' and !($load_file =~ /^\//)) { # relative path $load_file = "$bootpath/$load_file"; } -if (!open(CFG, "<$load_file")) { - print "Cannot open configuration file $load_file\n"; - exit 1; +if ($mode eq 'local') { + if (!open(CFG, "<$load_file")) { + print "Cannot open configuration file $load_file\n"; + exit 1; + } +} elsif ($mode eq 'url') { + if (! -f '/usr/bin/curl') { + print "Package [curl] not installed\n"; + exit 1; + } + if ($proto eq 'http') { + # + # error codes are send back in html, so 1st try a header + # and look for "HTTP/1.1 200 OK" + # + my $rc = `curl -q -I $load_file 2>&1`; + if ($rc =~ /HTTP\/\d+\.?\d\s+(\d+)\s+(.*)$/mi) { + my $rc_code = $1; + my $rc_string = $2; + if ($rc_code == 200) { + # good resonse + } else { + print "http error: [$rc_code] $rc_string\n"; + exit 1; + } + } else { + print "Error: $rc\n"; + exit 1; + } + } + my $rc = system("curl -# -o $url_tmp_file $load_file"); + if ($rc) { + print "Can not open remote configuration file $load_file\n"; + exit 1; + } + if (!open(CFG, "<$url_tmp_file")) { + print "Cannot open configuration file $load_file\n"; + exit 1; + } + $load_file = $url_tmp_file; } while (<CFG>) { if (/\/\*XORP Configuration File, v1.0\*\//) { |