diff options
author | An-Cheng Huang <ancheng@vyatta.com> | 2007-09-25 15:55:26 -0700 |
---|---|---|
committer | An-Cheng Huang <ancheng@vyatta.com> | 2007-09-25 15:55:26 -0700 |
commit | e9a79a249cec69fc178098d2f75db9389068510a (patch) | |
tree | 0e366094b7fecd3988c243fbbb574015e0c900c8 /scripts/vyatta-save-config.pl | |
download | vyatta-cfg-e9a79a249cec69fc178098d2f75db9389068510a.tar.gz vyatta-cfg-e9a79a249cec69fc178098d2f75db9389068510a.zip |
initial import (from eureka /cli) plus new build system.upstream
Diffstat (limited to 'scripts/vyatta-save-config.pl')
-rwxr-xr-x | scripts/vyatta-save-config.pl | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/scripts/vyatta-save-config.pl b/scripts/vyatta-save-config.pl new file mode 100755 index 0000000..ad972b4 --- /dev/null +++ b/scripts/vyatta-save-config.pl @@ -0,0 +1,45 @@ +#!/usr/bin/perl + +use strict; +use lib "/opt/vyatta/share/perl5/"; +use VyattaConfigOutput; + +my $sbindir = $ENV{ofr_sbindir}; +my $etcdir = $ENV{ofr_sysconfdir}; +my $bootfile = ''; +if (-r "$etcdir/bootfile_path") { + $bootfile = `cat $etcdir/bootfile_path`; +} +my $bootpath = $bootfile; +$bootpath =~ s/\/[^\/]+$//; + +if ($#ARGV > 0) { + print "Usage: save [config_file_name]\n"; + exit 1; +} + +my $save_file = "$bootfile"; +if (defined($ARGV[0])) { + $save_file = $ARGV[0]; + if (!($save_file =~ /^\//)) { + # relative path + $save_file = "$bootpath/$save_file"; + } +} + +# this overwrites the file if it exists. we could create a backup first. +if (! open(SAVE, ">$save_file")) { + print "Cannot open file '$save_file': $!\n"; + exit 1; +} + +print "Saving configuration to '$save_file'..."; +select SAVE; +VyattaConfigOutput::outputActiveConfig(); +my $version_str = `/opt/vyatta/sbin/vyatta_current_conf_ver.pl`; +print SAVE $version_str; +select STDOUT; +print "\nDone\n"; +close SAVE; +exit 0; + |