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.pl100
2 files changed, 48 insertions, 130 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..0496f7f 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", "ftps", "ssh")) {
$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);
+ friendly_download($from, $to);
}
exit 0;
}
@@ -215,90 +206,19 @@ 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 upload {
+ my ($from, $to) = @_;
+ system("python3 -c 'from vyos.remote import upload; upload(\"$from\", \"$to\")'")
}
-sub curl_to {
+sub download {
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 download; download(\"$to\", \"$from\")'");
}
-sub curl_from {
+sub friendly_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 friendly_download; friendly_download(\"$to\", \"$from\")'");
}
sub y_or_n {