summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/tech-support-archive78
-rwxr-xr-xscripts/vyatta-image-tools.pl99
-rwxr-xr-xscripts/vyatta-remote-copy.pl94
3 files changed, 45 insertions, 226 deletions
diff --git a/scripts/tech-support-archive b/scripts/tech-support-archive
index 9524557..2321d76 100755
--- a/scripts/tech-support-archive
+++ b/scripts/tech-support-archive
@@ -19,54 +19,52 @@ do_rotate ()
HOSTNAME=`hostname`
CURTIME=`date +%F-%H%M%S`
-
- if [ -n "$1" ]; then
- if [[ "$1" =~ scp:///* ]]; then
- OUT="$HOSTNAME.tech-support-archive.$CURTIME"
- REMOTE="1"
- elif [[ "$1" =~ ftp:///* ]]; then
- OUT="$HOSTNAME.tech-support-archive.$CURTIME"
- REMOTE="1"
- else
- #file to be save locally
- OUT="$1.$HOSTNAME.tech-support-archive.$CURTIME"
- fi
- else
+if [ -n "$1" ]; then
+ if [[ "$1" =~ scp:///* ]]; then
+ OUT="$HOSTNAME.tech-support-archive.$CURTIME"
+ REMOTE="1"
+ elif [[ "$1" =~ ftp:///* ]]; then
OUT="$HOSTNAME.tech-support-archive.$CURTIME"
+ REMOTE="1"
+ else
+ # File to be saved locally
+ OUT="$1.$HOSTNAME.tech-support-archive.$CURTIME"
fi
+else
+ OUT="$HOSTNAME.tech-support-archive.$CURTIME"
+fi
+
+if [[ $OUT != /* ]]; then
+ FILE_NAME=$OUT
+ do_rotate
+ # it's not absolute path. save in default path.
+ OUT="$DEFAULT_PATH/$OUT"
+ mkdir -p $OUT >& /dev/null
+ chgrp $DEFAULT_GROUP $OUT >& /dev/null
+ chmod 775 $OUT >& /dev/null
+else
+ mkdir -p $OUT >& /dev/null
+ chgrp $DEFAULT_GROUP $OUT >& /dev/null
+ chmod 775 $OUT >& /dev/null
+ FILE_NAME=`echo $OUT | sed -e 's/\//\n/g' | tail -1`
+fi
- if [[ $OUT != /* ]]; then
- FILE_NAME=$OUT
- do_rotate
- # it's not absolute path. save in default path.
- OUT="$DEFAULT_PATH/$OUT"
- mkdir -p $OUT >& /dev/null
- chgrp $DEFAULT_GROUP $OUT >& /dev/null
- chmod 775 $OUT >& /dev/null
- else
- mkdir -p $OUT >& /dev/null
- chgrp $DEFAULT_GROUP $OUT >& /dev/null
- chmod 775 $OUT >& /dev/null
- FILE_NAME=`echo $OUT | sed -e 's/\//\n/g' | tail -1`
- fi
builtin cd "$OUT"
-echo "Saving the archivals..."
-sudo tar -zcf config.tgz /opt/vyatta/etc/config --exclude "*tech-support-archive*" >& /dev/null
-sudo tar -zcf etc.tgz /etc >& /dev/null
-sudo tar -zcf home.tgz /home >& /dev/null
-sudo tar -zcf var-log.tgz /var/log >& /dev/null
-sudo tar -zcf root.tgz /root >& /dev/null
-sudo tar -zcf tmp.tgz /tmp >& /dev/null
-sudo tar -zcf core-dump.tgz /var/core >& /dev/null
+echo "Saving the archives..."
+sudo tar zcf config.tgz /opt/vyatta/etc/config --exclude "*tech-support-archive*" >& /dev/null
+sudo tar zcf etc.tgz /etc >& /dev/null
+sudo tar zcf home.tgz /home >& /dev/null
+sudo tar zcf var-log.tgz /var/log >& /dev/null
+sudo tar zcf root.tgz /root >& /dev/null
+sudo tar zcf tmp.tgz /tmp >& /dev/null
+sudo tar zcf core-dump.tgz /var/core >& /dev/null
builtin cd "../"
-sudo tar -zcvf $FILE_NAME.tgz $FILE_NAME >& /dev/null
+sudo tar zcvf $FILE_NAME.tgz $FILE_NAME >& /dev/null
sudo rm -r $FILE_NAME
-OUT=$OUT.tgz
+OUT=$OUT.tgz
echo "Saved tech-support archival at $OUT"
if [ $REMOTE == "1" ]; then
- perl /opt/vyatta/bin/vyatta-remote-copy.pl $1 $OUT $FLAG
+ python3 -c "from vyos.remote import upload; upload(\"$OUT\", \"$1\")"
fi
-
-exit
diff --git a/scripts/vyatta-image-tools.pl b/scripts/vyatta-image-tools.pl
index 092cbf7..bdee0c5 100755
--- a/scripts/vyatta-image-tools.pl
+++ b/scripts/vyatta-image-tools.pl
@@ -51,16 +51,7 @@ sub conv_file {
$file = "/$file";
} elsif (lc($topdir) eq 'disk-install') {
$file = "/lib/live/mount/persistence/$file";
- } elsif (lc($topdir) eq 'tftp') {
- $file = $filein;
- $topdir = 'url';
- } elsif (lc($topdir) eq 'http') {
- $file = $filein;
- $topdir = 'url';
- } elsif (lc($topdir) eq 'ftp') {
- $file = $filein;
- $topdir = 'url';
- } elsif (lc($topdir) eq 'scp') {
+ } elsif (grep { lc($topdir) eq $_ } ("ftp", "tftp", "http", "https", "scp", "sftp")) {
$file = $filein;
$topdir = 'url';
} else {
@@ -123,7 +114,7 @@ sub url_copy {
print "Cannot upload to http url\n";
exit 1;
}
- curl_to($from, $to);
+ upload($from, $to);
} elsif ($f_topdir eq 'url') {
if (-d $to){
$from =~ /.*\/(.*)/;
@@ -135,7 +126,7 @@ sub url_copy {
}
}
}
- curl_from($from, $to);
+ download($from, $to);
}
exit 0;
}
@@ -215,90 +206,14 @@ sub rsync {
return $?;
}
-sub conv_spec_char {
- my ($inpt_data) = @_;
- #replace #
- $inpt_data =~ s/\#/%23/g;
- #replace @
- $inpt_data =~ s/\@/%40/g;
- return $inpt_data;
-}
-
-sub prepare_login_data {
- my ($uri_data) = @_;
- # Parse protocol
- if ($uri_data =~ /ftp\:\/\//){
- $uri_data = reverse($');
- # Separate host and username login data
- $uri_data =~ m/@/;
- my $host_data = reverse($`);
- my $login_data = reverse($');
- $login_data =~ /\:/;
- my $username = $`;
- my $password = conv_spec_char($');
- return "ftp://".$username.":".$password."@".$host_data;
- }
- return $uri_data;
-}
-
-sub curl_to {
+sub upload {
my ($from, $to) = @_;
- $to = prepare_login_data($to);
- my $rc = system("curl -# -T $from $to");
- if ($to =~ /scp/ && ($rc >> 8) == 51){
- $to =~ m/scp:\/\/(.*?)\//;
- my $host = $1;
- if ($host =~ m/.*@(.*)/) {
- $host = $1;
- }
- 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")) {
- if (! -d "$ENV{HOME}/.ssh/") {
- mkdir "$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 -# -T $from $to");
- print "\n";
- }
- }
- print "\n";
+ system("python3 -c 'from vyos.remote import upload; upload(\"$from\", \"$to\")'")
}
-sub curl_from {
+sub download {
my ($from, $to) = @_;
- $from = prepare_login_data($from);
- my $rc = system("curl -# $from > $to");
- if ($from =~ /scp/ && ($rc >> 8) == 51){
- $from =~ m/scp:\/\/(.*?)\//;
- my $host = $1;
- if ($host =~ m/.*@(.*)/) {
- $host = $1;
- }
- 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")) {
- if (! -d "$ENV{HOME}/.ssh/") {
- mkdir "$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 -# $from > $to");
- print "\n";
- }
- }
- print "\n";
+ system("python3 -c 'from vyos.remote import download; download(\"$to\", \"$from\")'");
}
sub y_or_n {
diff --git a/scripts/vyatta-remote-copy.pl b/scripts/vyatta-remote-copy.pl
deleted file mode 100755
index 23dd135..0000000
--- a/scripts/vyatta-remote-copy.pl
+++ /dev/null
@@ -1,94 +0,0 @@
-#!/usr/bin/perl
-
-# Author: Deepti Kulkarni
-# Date: May 2010
-# Description: script to save file remotely.
-
-# **** License ****
-# 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.
-# **** End License ****
-
-use strict;
-use lib "/opt/vyatta/share/perl5";
-use IO::Prompt;
-
-my $save_file;
-
-if (defined($ARGV[0])) {
- $save_file = $ARGV[0];
-}
-my $tmp_file = $ARGV[1];
-my $flag = $ARGV[2];
-
-my $mode = 'local';
-my $proto;
-
-if ($save_file =~ /^[^\/]\w+:\//) {
-
-if ($save_file =~ /^(\w+):\/\/\w/) {
- $mode = 'url';
- $proto = lc($1);
- if ($proto eq 'ftp') {
- }
- elsif ($proto eq 'scp') {
- } else {
- print "Invalid url protocol [$proto]\n";
- exit 1;
- }
- } else {
- print "Invalid url [$save_file]\n";
- exit 1;
- }
-}
-if ($flag == 0)
-{
- $save_file=$save_file . ".gz"
-}
-if ($flag == 2)
-{
- $save_file=$save_file . ".tgz"
-}
-if ($mode eq 'url') {
- print "Saving output to $save_file\n";
- my $rc = system("curl -# -T $tmp_file $save_file");
- if ($proto eq 'scp' && ($rc >> 8) == 51){
- $save_file =~ m/scp:\/\/(.*?)\//;
- my $host = $1;
- if ($host =~ m/.*@(.*)/) {
- $host = $1;
- }
- 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 "~/.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 -# -T $tmp_file $save_file");
- print "\n";
- }
- }
- system("rm -f $tmp_file");
- if ($rc) {
- print "Error saving $save_file\n";
- exit 1;
- }
-}
-
-print "Done\n";
-exit 0;