summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorJohn Southworth <john.southworth@vyatta.com>2011-04-25 11:15:59 -0500
committerJohn Southworth <john.southworth@vyatta.com>2011-04-25 11:15:59 -0500
commit753e1a7c79df5e2766cd6fa807078c8e0f68c05e (patch)
tree195abc0ffa6ba2440ff7e4e34a1cf0c7b6dfb564 /scripts
parent9578473a2ba955a1b081dac28ea3aa2bbad88431 (diff)
parent7515f598b4283b65a76ea4175b3957c38bbd0eef (diff)
downloadvyatta-op-753e1a7c79df5e2766cd6fa807078c8e0f68c05e.tar.gz
vyatta-op-753e1a7c79df5e2766cd6fa807078c8e0f68c05e.zip
Merge branch 'napa' of http://git.vyatta.com/vyatta-op into napa
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/vyatta-image-tools.pl182
-rwxr-xr-xscripts/vyatta-op-cmd-wrapper5
2 files changed, 187 insertions, 0 deletions
diff --git a/scripts/vyatta-image-tools.pl b/scripts/vyatta-image-tools.pl
new file mode 100755
index 0000000..f19e18d
--- /dev/null
+++ b/scripts/vyatta-image-tools.pl
@@ -0,0 +1,182 @@
+#!/usr/bin/perl -w
+use Getopt::Long;
+use lib "/opt/vyatta/share/perl5/";
+
+use strict;
+
+my ($show, $delete, $updateone);
+my @copy;
+my @update;
+
+GetOptions("show=s" => \$show,
+ "delete=s" => \$delete,
+ "update=s{2}" => \@update,
+ "updateone=s" => \$updateone,
+ "copy=s{2}" => \@copy);
+
+if (defined $show){
+ show($show);
+}
+if (defined $delete){
+ delete_file($delete);
+}
+if (@update){
+ update(@update);
+}
+if (defined($updateone)){
+ update($updateone, "running://");
+}
+if (@copy){
+ copy(@copy);
+}
+
+sub conv_file {
+ my $file = " ";
+ $file = pop(@_);
+ $file =~ s/://;
+ $file =~ /(.+?)\/\/(.*)/;
+ my $topdir = $1;
+ $file = $2;
+ if ( $topdir eq "running" ) {
+ $file = "/$file";
+ } else {
+ $file = "/live/image/boot/$topdir/live-rw/$file";
+ }
+ return ($topdir, $file);
+}
+
+sub conv_file_to_rel {
+ my ($topdir, $filename) = @_;
+ if ($topdir eq "running"){
+ $filename =~ s?/?$topdir://?;
+ } else {
+ $filename =~ s?/live/image/boot/$topdir/live-rw/?$topdir://?;
+ }
+ return $filename;
+}
+
+sub delete_file {
+ my ($file) = @_;
+ (my $topdir, $file) = conv_file($file);
+ if (-d $file){
+ my $print_dir = conv_file_to_rel($topdir,$file);
+ if (y_or_n("Do you want to erase the entire $print_dir directory?")){
+ system("rm -rf $file");
+ print("Directory erased\n");
+ }
+ } elsif (-f $file) {
+ my $print_file = conv_file_to_rel($topdir,$file);
+ if (y_or_n("Do you want to erase the $print_file file?")){
+ system("rm -rf $file");
+ print("File erased\n");
+ }
+ }
+}
+
+sub copy {
+ my ($from, $to) = @_;
+ my ($f_topdir, $t_topdir);
+ ($f_topdir, $from) = conv_file($from);
+ ($t_topdir, $to) = conv_file($to);
+ $from =~ /.*\/(.*)/;
+ my $from_file = $1;
+ if ( -d $from && -e $to && !( -d $to ) ){
+ print "Cannot copy a directory to a file.\n";
+ return 1;
+ } elsif ( -f $to || (-d $to && -f "$to/$from_file") ) {
+ if (y_or_n("This file exists; overwrite if needed?")){
+ rsync($from, $to);
+ }
+ } elsif ( -d $to && -d $from ){
+ my $print_from = conv_file_to_rel($f_topdir, $from);
+ my $print_to = conv_file_to_rel($t_topdir, $to);
+ if (y_or_n("Merge directory $print_from with $print_to?")){
+ rsync($from, $to);
+ }
+ } else {
+ rsync($from, $to);
+ }
+}
+
+sub update {
+ my ($to, $from) = @_;
+ my ($t_topdir, $f_topdir);
+ ($f_topdir, $from) = conv_file($from);
+ ($t_topdir, $to) = conv_file($to);
+ my $print_from = conv_file_to_rel($f_topdir, $from);
+ my $print_to = conv_file_to_rel($t_topdir, $to);
+ my $msg = "WARNING: This is a destructive copy of the /config directories\n"
+ . "This will erase all data in the ".$print_to."config directory\n"
+ . "This data will be replaced with the data from $print_from\n"
+ . "Do you wish to continue?";
+ if (y_or_n("$msg")){
+ system("rm -rf $to/config");
+ rsync("$from/config", $to);
+ }
+}
+
+sub rsync {
+ my ($from,$to) = @_;
+ system("rsync -av --progress $from $to");
+}
+
+sub y_or_n {
+ my ($msg) = @_;
+ print "$msg (Y/N): ";
+ my $input = <>;
+ return 1 if ($input =~ /Y|y/);
+ return 0;
+}
+
+sub show {
+ my ($topdir, $file) = conv_file(pop(@_));
+ my $output = "";
+ if ( -d $file ) {
+ print "########### DIRECTORY LISTING ###########\n";
+ system("ls -lGph --group-directories-first $file");
+ } elsif ( -T $file ) {
+ print "########### FILE INFO ###########\n";
+ my $filename = conv_file_to_rel($topdir, $file);
+ print "File Name: $filename\n";
+ print "Text File: \n";
+ my $lsstr = `ls -lGh $file`;
+ parsels($lsstr);
+ print " Description:\t";
+ system("file -sb $file");
+ print "\n########### FILE DATA ###########\n";
+ system("cat $file");
+ } elsif ( $file =~ /.*\.pcap/ ){
+ print "########### FILE INFO ###########\n";
+ my $filename = conv_file_to_rel($topdir, $file);
+ print "File Name: $filename\n";
+ print "Binary File: \n";
+ my $lsstr = `ls -lGh $file`;
+ parsels($lsstr);
+ print " Description:\t";
+ system("file -sb $file");
+ print "\n########### FILE DATA ###########\n";
+ system("sudo tshark -r $file | less");
+ } elsif ( -B $file ) {
+ print "########### FILE INFO ###########\n";
+ my $filename = conv_file_to_rel($topdir, $file);
+ print "File Name: $filename\n";
+ print "Binary File: \n";
+ my $lsstr = `ls -lGh $file`;
+ parsels($lsstr);
+ print " Description:\t";
+ system("file -sb $file");
+ print "\n########### FILE DATA ###########\n";
+ system("hexdump -C $file| less");
+ } else {
+ print "File Not Found\n";
+ }
+}
+
+sub parsels {
+ my $lsout = pop(@_);
+ my @ls = split(' ', $lsout);
+ print " Permissions: $ls[0]\n";
+ print " Owner:\t$ls[2]\n";
+ print " Size:\t\t$ls[3]\n";
+ print " Modified:\t$ls[4] $ls[5] $ls[6]\n";
+}
diff --git a/scripts/vyatta-op-cmd-wrapper b/scripts/vyatta-op-cmd-wrapper
new file mode 100755
index 0000000..6610afd
--- /dev/null
+++ b/scripts/vyatta-op-cmd-wrapper
@@ -0,0 +1,5 @@
+#!/bin/vbash -l
+VYATTA_USER_LEVEL_DIR=/opt/vyatta/etc/shell/level/admin
+source /etc/default/vyatta
+source /etc/bash_completion.d/vyatta-op-run
+_vyatta_op_run $@